Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ class Item(
this.count = count
imageUrl?.let { this.imageUrl = it }
}

fun addCount(count: Int) {
this.count += count
}

fun subtractCount(count: Int) {
if (count > this.count) {
this.count = 0
return
}
this.count -= count
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ enum class RentalErrorCode(
RENTAL_ITEM_DUPLICATED("이미 대여 중인 물품입니다.\n중복 대여하시겠습니까?", HttpStatus.CONFLICT),
INVALID_RENTAL_TIME_OUT_OF_RANGE("대여 가능시간은 10:00 ~ 17:00입니다. 다시 입력해주세요", HttpStatus.BAD_REQUEST),
INVALID_RENTAL_TIME_PAST("현재 시간보다 이후의 시간으로 설정해주세요", HttpStatus.BAD_REQUEST),
RENTAL_NOT_FOUND("대여 기록을 찾을 수 없습니다", HttpStatus.NOT_FOUND)
RENTAL_NOT_FOUND("대여 기록을 찾을 수 없습니다", HttpStatus.NOT_FOUND),
MEMBER_IS_NOT_PAYER("복지물품을 대여하려면 먼저 학생회비를 납부해주세요.", HttpStatus.FORBIDDEN),
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class RentalService(
val rentUser = memberRepository.findById(memberId!!)
.orElseThrow { ApiException(RentalErrorCode.MEMBER_NOT_FOUND) }

if (!rentUser.isFeePaid)
throw ApiException(RentalErrorCode.MEMBER_IS_NOT_PAYER)

val koreanZone = ZoneId.of("Asia/Seoul")
val today = LocalDate.now(koreanZone)
val requestedRentalDateTime = LocalDateTime.of(
Expand All @@ -61,15 +64,15 @@ class RentalService(
)

val currentKoreanTime = LocalDateTime.now(koreanZone)
// if (requestedRentalDateTime.isBefore(currentKoreanTime)) {
// throw ApiException(RentalErrorCode.INVALID_RENTAL_TIME_PAST)
// }
if (requestedRentalDateTime.isBefore(currentKoreanTime)) {
throw ApiException(RentalErrorCode.INVALID_RENTAL_TIME_PAST)
}

val rentalHour = requestedRentalDateTime.hour
val rentalMinute = requestedRentalDateTime.minute
// if (rentalHour < 10 || rentalHour > 17) {
// throw ApiException(RentalErrorCode.INVALID_RENTAL_TIME_PAST)
// }
if (rentalHour < 10 || rentalHour > 17) {
throw ApiException(RentalErrorCode.INVALID_RENTAL_TIME_OUT_OF_RANGE)
}

val rentAt = requestedRentalDateTime.atZone(koreanZone).toLocalDateTime()

Expand All @@ -80,6 +83,8 @@ class RentalService(
rentAt = rentAt
)

item.subtractCount(rentalHistoryRequest.count)

rentalRepository.save(newRental)

notificationService.sendNotification(
Expand Down