diff --git a/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/WithDankookRepository.java b/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/WithDankookRepository.java index 49d7faa7..350f2490 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/WithDankookRepository.java +++ b/src/main/java/com/dku/council/domain/with_dankook/repository/with_dankook/WithDankookRepository.java @@ -61,5 +61,10 @@ public interface WithDankookRepository extends JpaReposit @Query(value = "select COUNT(*) from with_dankook w " + "where w.with_dankook_id = :withDankookId and " + "((w.with_dankook_status in ('FULL', 'CLOSED')) or (w.with_dankook_status = 'ACTIVE' and w.end_time <= CURRENT_TIMESTAMP())) ", nativeQuery = true) - int findWithClosedOrFullOrActiveByIdToCreateReview(@Param("withDankookId") Long withDankookId); + int findWithClosedOrFullOrActiveEndTimeByIdToCreateReview(@Param("withDankookId") Long withDankookId); + + @Query(value = "select COUNT(*) from with_dankook w " + + "where w.with_dankook_id = :withDankookId and " + + "((w.with_dankook_status in ('FULL', 'CLOSED')) or (w.with_dankook_status = 'ACTIVE' and w.delivery_time <= CURRENT_TIMESTAMP())) ", nativeQuery = true) + int findWithClosedOrFullOrActiveDeliveryTimeByIdToCreateReview(@Param("withDankookId") Long withDankookId); } diff --git a/src/main/java/com/dku/council/domain/with_dankook/service/WithDankookService.java b/src/main/java/com/dku/council/domain/with_dankook/service/WithDankookService.java index 2d3e00ed..d7b64004 100644 --- a/src/main/java/com/dku/council/domain/with_dankook/service/WithDankookService.java +++ b/src/main/java/com/dku/council/domain/with_dankook/service/WithDankookService.java @@ -213,18 +213,28 @@ public interface PostResultMapper { public void isPossibleCreateReview(Long withDankookId) { String withDankookType = withDankookRepository.findWithDankookType(withDankookId); - if (withDankookType.equals("Trade")) { - if (withDankookRepository.findWithClosedByIdToCreateReview(withDankookId) != 1) { - throw new InvalidStatusException(); - } -// } else if (withDankookType.equals("Study") || withDankookType.equals("Dormitory")) { -// if (withDankookRepository.findWithClosedOrFullOrActiveByIdToCreateReview(withDankookId) != 1) { -// throw new InvalidStatusException(); -// } - } else if (withDankookType.equals("BearEats") || withDankookType.equals("EatingAlong")) { - if (withDankookRepository.findWithClosedOrFullByIdToCreateReview(withDankookId) != 1) { - throw new InvalidStatusException(); - } + switch (withDankookType) { + case "Trade": + case "Roommate": + if (withDankookRepository.findWithClosedByIdToCreateReview(withDankookId) != 1) { + throw new InvalidStatusException(); + } + break; + case "Study": + if (withDankookRepository.findWithClosedOrFullOrActiveEndTimeByIdToCreateReview(withDankookId) != 1) { + throw new InvalidStatusException(); + } + break; + case "EatingAlong": + if (withDankookRepository.findWithClosedOrFullByIdToCreateReview(withDankookId) != 1) { + throw new InvalidStatusException(); + } + break; + case "BearEats": + if (withDankookRepository.findWithClosedOrFullOrActiveDeliveryTimeByIdToCreateReview(withDankookId) != 1) { + throw new InvalidStatusException(); + } + break; } } }