Skip to content

Commit

Permalink
Merge pull request #87 from Team-KeepGoing/feature/damage
Browse files Browse the repository at this point in the history
Add :: 마지막 대여자 반환
  • Loading branch information
priverg authored Oct 10, 2024
2 parents dbecc74 + cec7c81 commit 9143e13
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@ public class Book {
private String imageUrl;

/*
기기 대여 시작일
대여 시작일
*/
@Column
private LocalDateTime rentDate;

/*
책 마지막 대여자 mail
*/
@Column
private String lastBorrowerMail;

/*
책 대여자
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public BookResponseDto entityToDto(Book entity) {
.writer(entity.getWriter())
.imageUrl(entity.getImageUrl())
.nfcCode(entity.getNfcCode())
.lastBorrowerMail(entity.getLastBorrowerMail())
.rentDate(entity.getRentDate())
.state(entity.getState())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public record BookResponseDto(
String writer,
String imageUrl,
String nfcCode,
String lastBorrowerMail,
LocalDateTime registrationDate,
LocalDateTime rentDate,
BookState state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public class Device {
@Column
private LocalDateTime rentDate;

/*
기기 마지막 대여자 mail
*/
@Column
private String lastBorrowerMail;

/*
대여자 id
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public DeviceResponseDto entityToDto(Device entity) {
.deviceName(entity.getDeviceName())
.imgUrl(entity.getImgUrl())
.borrower(entity.getBorrower() != null ? entity.getBorrower().getName() : "대여자 없음")
.lastBorrowerMail(entity.getLastBorrowerMail())
.regDate(entity.getRegDate())
.rentDate(entity.getRentDate())
.status(entity.getStatus())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public record DeviceResponseDto(
String deviceName,
String imgUrl,
String borrower,
String lastBorrowerMail,
LocalDateTime regDate,
LocalDateTime rentDate,
DeviceStatus status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public BaseResponse returnDevice(String deviceName, String email) {
User user = deviceService.findUserByEmail(email);
Device device = findDeviceByName(deviceName);
validateDeviceBorrower(device, user);
returnDeviceFromUser(device);
returnDeviceFromUser(device, user);
return new BaseResponse(HttpStatus.OK, "반납이 완료 되었습니다.", deviceMapper.entityToDto(device));
}

Expand All @@ -42,7 +42,7 @@ public BaseResponse returnBook(String nfcCode, String email) {
User user = deviceService.findUserByEmail(email);
Book book = findBookByNfcCodeContaining(nfcCode);
validateBookBorrower(book, user);
returnBookFromUser(book);
returnBookFromUser(book, user);
return new BaseResponse(HttpStatus.OK, "반납이 완료 되었습니다.", bookMapper.entityToDto(book));
}

Expand All @@ -57,7 +57,8 @@ private void validateDeviceBorrower(Device device, User user) {
}
}

private void returnDeviceFromUser(Device device) {
private void returnDeviceFromUser(Device device, User user) {
device.setLastBorrowerMail(user.getEmail());
device.setBorrower(null);
device.setStatus(DeviceStatus.AVAILABLE);
device.setRentDate(null);
Expand All @@ -75,7 +76,8 @@ private void validateBookBorrower(Book book, User user) {
}
}

private void returnBookFromUser(Book book) {
private void returnBookFromUser(Book book, User user) {
book.setLastBorrowerMail(user.getEmail());
book.setBorrower(null);
book.setState(BookState.AVAILABLE);
book.setRentDate(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public UserDto getProfileById(long id) {
device.deviceName,
device.imgUrl,
device.borrower.name,
device.lastBorrowerMail,
device.regDate,
device.rentDate,
device.status
Expand All @@ -59,6 +60,7 @@ public UserDto getProfileById(long id) {
book.writer,
book.imageUrl,
book.nfcCode,
book.lastBorrowerMail,
book.registrationDate,
book.rentDate,
book.state
Expand All @@ -80,6 +82,7 @@ public UserDto getProfileById(long id) {
.collect(Collectors.toSet()))
.borrowedBooks(dto.borrowedBooks().stream().filter(r -> r.id() != 0).collect(Collectors.toSet()))
.build();
// return null;
}

@Override
Expand Down

0 comments on commit 9143e13

Please sign in to comment.