diff --git a/gg-pingpong-api/src/main/java/gg/party/api/user/category/service/CategoryService.java b/gg-pingpong-api/src/main/java/gg/party/api/user/category/service/CategoryService.java index db4c315ce..78170b3f6 100644 --- a/gg-pingpong-api/src/main/java/gg/party/api/user/category/service/CategoryService.java +++ b/gg-pingpong-api/src/main/java/gg/party/api/user/category/service/CategoryService.java @@ -32,7 +32,7 @@ public class CategoryService { @Transactional(readOnly = true) public CategoryListResDto findCategoryList(UserDto userDto) { User user = userRepository.findById(userDto.getId()).get(); - PartyPenalty partyPenalty = partyPenaltyRepository.findLatestByUserId(user.getId()); + PartyPenalty partyPenalty = partyPenaltyRepository.findTopByUserIdOrderByStartTimeDesc(user.getId()); if (PartyPenalty.isOnPenalty(partyPenalty)) { throw new OnPenaltyException(); } diff --git a/gg-pingpong-api/src/main/java/gg/party/api/user/comment/service/CommentService.java b/gg-pingpong-api/src/main/java/gg/party/api/user/comment/service/CommentService.java index 1e3f22331..bc9b92e55 100644 --- a/gg-pingpong-api/src/main/java/gg/party/api/user/comment/service/CommentService.java +++ b/gg-pingpong-api/src/main/java/gg/party/api/user/comment/service/CommentService.java @@ -48,7 +48,7 @@ public void addCreateComment(Long roomId, CommentCreateReqDto reqDto, Long userI throw new RoomNotOpenException(); } - PartyPenalty partyPenalty = partyPenaltyRepository.findLatestByUserId(userId); + PartyPenalty partyPenalty = partyPenaltyRepository.findTopByUserIdOrderByStartTimeDesc(userId); if (PartyPenalty.isOnPenalty(partyPenalty)) { throw new OnPenaltyException(); } diff --git a/gg-pingpong-api/src/main/java/gg/party/api/user/report/service/ReportService.java b/gg-pingpong-api/src/main/java/gg/party/api/user/report/service/ReportService.java index 3ae9ad926..60ecb6b3d 100644 --- a/gg-pingpong-api/src/main/java/gg/party/api/user/report/service/ReportService.java +++ b/gg-pingpong-api/src/main/java/gg/party/api/user/report/service/ReportService.java @@ -183,7 +183,7 @@ public void addReportUser(Long roomId, ReportReqDto reportReqDto, String userInt @Transactional public void partyGivePenalty(String intraId, Integer penaltyTime, String penaltyType) { User user = userRepository.findByIntraId(intraId).get(); - PartyPenalty pPenalty = partyPenaltyRepository.findLatestByUserId(user.getId()); + PartyPenalty pPenalty = partyPenaltyRepository.findTopByUserIdOrderByStartTimeDesc(user.getId()); if (pPenalty != null && LocalDateTime.now().isBefore(pPenalty.getStartTime() .plusMinutes(pPenalty.getPenaltyTime()))) { diff --git a/gg-pingpong-api/src/main/java/gg/party/api/user/room/service/RoomManagementService.java b/gg-pingpong-api/src/main/java/gg/party/api/user/room/service/RoomManagementService.java index 86b39972b..cf9c9ccf0 100644 --- a/gg-pingpong-api/src/main/java/gg/party/api/user/room/service/RoomManagementService.java +++ b/gg-pingpong-api/src/main/java/gg/party/api/user/room/service/RoomManagementService.java @@ -61,7 +61,7 @@ public class RoomManagementService { @Transactional public RoomCreateResDto addCreateRoom(RoomCreateReqDto roomCreateReqDto, UserDto userDto) { User user = userRepository.findById(userDto.getId()).get(); - PartyPenalty partyPenalty = partyPenaltyRepository.findLatestByUserId(user.getId()); + PartyPenalty partyPenalty = partyPenaltyRepository.findTopByUserIdOrderByStartTimeDesc(user.getId()); if (PartyPenalty.isOnPenalty(partyPenalty)) { throw new OnPenaltyException(); } @@ -176,7 +176,7 @@ public RoomStartResDto modifyStartRoom(Long roomId, UserDto user) { public RoomJoinResDto addJoinRoom(Long roomId, UserDto userDto) { User user = userRepository.findById(userDto.getId()).get(); Room room = roomRepository.findById(roomId).orElseThrow(RoomNotFoundException::new); - PartyPenalty partyPenalty = partyPenaltyRepository.findLatestByUserId(user.getId()); + PartyPenalty partyPenalty = partyPenaltyRepository.findTopByUserIdOrderByStartTimeDesc(user.getId()); if (PartyPenalty.isOnPenalty(partyPenalty)) { throw new OnPenaltyException(); } diff --git a/gg-pingpong-api/src/test/java/gg/party/api/user/category/CategoryControllerTest.java b/gg-pingpong-api/src/test/java/gg/party/api/user/category/CategoryControllerTest.java index 631e64aad..c9d4e4b23 100644 --- a/gg-pingpong-api/src/test/java/gg/party/api/user/category/CategoryControllerTest.java +++ b/gg-pingpong-api/src/test/java/gg/party/api/user/category/CategoryControllerTest.java @@ -45,8 +45,10 @@ public class CategoryControllerTest { private AuthTokenProvider tokenProvider; User userTester; User reportedTester; + User anotherTester; String userAccessToken; String reportedAccessToken; + String anotherAccessToken; @BeforeEach void beforeEach() { @@ -54,10 +56,17 @@ void beforeEach() { RacketType.DUAL, SnsType.SLACK, RoleType.USER); reportedTester = testDataUtils.createNewUser("reportedTester", "reportedTester", RacketType.DUAL, SnsType.SLACK, RoleType.USER); + anotherTester = testDataUtils.createNewUser("anotherUserTester", "anotherUserTester", + RacketType.DUAL, SnsType.SLACK, RoleType.USER); testDataUtils.createNewPenalty(reportedTester, "test", "test", LocalDateTime.now(), 60); + testDataUtils.createNewPenalty(anotherTester, "test1", "test1", + LocalDateTime.now(), 0); + testDataUtils.createNewPenalty(anotherTester, "test2", "test2", + LocalDateTime.now(), 0); userAccessToken = tokenProvider.createToken(userTester.getId()); reportedAccessToken = tokenProvider.createToken(reportedTester.getId()); + anotherAccessToken = tokenProvider.createToken(anotherTester.getId()); for (int i = 0; i < 10; i++) { testDataUtils.createNewCategory("테스트 카테고리" + i); } @@ -82,6 +91,22 @@ void success() throws Exception { assertThat(clrd.getCategoryList().size()).isEqualTo(10); } + @Test + @DisplayName("카테고리 목록 조회 성공 200") + void unLockPenaltySuccess() throws Exception { + //given + String uri = "/party/categories"; + //when + String contentAsString = mockMvc.perform(get(uri) + .header("Authorization", "Bearer " + anotherAccessToken) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + //then + CategoryListResDto clrd = objectMapper.readValue(contentAsString, CategoryListResDto.class); + assertThat(clrd.getCategoryList().size()).isEqualTo(10); + } + @Test @DisplayName("패널티 상태의 유저 카테고리 목록 조회 실패 403") void penaltyUserFail() throws Exception { diff --git a/gg-repo/src/main/java/gg/repo/party/PartyPenaltyRepository.java b/gg-repo/src/main/java/gg/repo/party/PartyPenaltyRepository.java index 621124342..b54932fb3 100644 --- a/gg-repo/src/main/java/gg/repo/party/PartyPenaltyRepository.java +++ b/gg-repo/src/main/java/gg/repo/party/PartyPenaltyRepository.java @@ -11,8 +11,7 @@ import gg.data.party.PartyPenalty; public interface PartyPenaltyRepository extends JpaRepository { - @Query("SELECT p FROM PartyPenalty p WHERE p.user.id = :userId ORDER BY p.startTime DESC") - PartyPenalty findLatestByUserId(@Param("userId") Long userId); + PartyPenalty findTopByUserIdOrderByStartTimeDesc(@Param("userId") Long userId); List findAllByUserId(Long userId);