diff --git a/src/main/kotlin/site/billilge/api/backend/domain/item/entity/Item.kt b/src/main/kotlin/site/billilge/api/backend/domain/item/entity/Item.kt index 4325f34..aff5eab 100644 --- a/src/main/kotlin/site/billilge/api/backend/domain/item/entity/Item.kt +++ b/src/main/kotlin/site/billilge/api/backend/domain/item/entity/Item.kt @@ -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 + } } \ No newline at end of file diff --git a/src/main/kotlin/site/billilge/api/backend/domain/rental/exception/RentalErrorCode.kt b/src/main/kotlin/site/billilge/api/backend/domain/rental/exception/RentalErrorCode.kt index 489d496..2b82242 100644 --- a/src/main/kotlin/site/billilge/api/backend/domain/rental/exception/RentalErrorCode.kt +++ b/src/main/kotlin/site/billilge/api/backend/domain/rental/exception/RentalErrorCode.kt @@ -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), } \ No newline at end of file diff --git a/src/main/kotlin/site/billilge/api/backend/domain/rental/service/RentalService.kt b/src/main/kotlin/site/billilge/api/backend/domain/rental/service/RentalService.kt index 8d33755..24cb5c1 100644 --- a/src/main/kotlin/site/billilge/api/backend/domain/rental/service/RentalService.kt +++ b/src/main/kotlin/site/billilge/api/backend/domain/rental/service/RentalService.kt @@ -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( @@ -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() @@ -80,6 +83,8 @@ class RentalService( rentAt = rentAt ) + item.subtractCount(rentalHistoryRequest.count) + rentalRepository.save(newRental) notificationService.sendNotification(