From ed034dbb3c5c730bf14b31e531b89059764f3d76 Mon Sep 17 00:00:00 2001 From: kwonssshyeon Date: Sat, 31 Aug 2024 20:42:13 +0900 Subject: [PATCH] =?UTF-8?q?[Fix]:=20=EC=8A=A4=ED=8A=B8=EB=A6=AD=20Strick?= =?UTF-8?q?=20->=20Streak=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/user/UserController.java | 12 +++++------ .../zzansuni/controller/user/UserReq.java | 4 ++-- .../zzansuni/controller/user/UserRes.java | 8 ++++---- .../zzansuni/domain/user/UserModel.java | 8 ++++---- .../zzansuni/domain/user/UserService.java | 8 ++++---- .../domain/user/UserIntegratedTest.java | 20 +++++++++---------- .../zzansuni/domain/user/UserServiceTest.java | 7 ------- 7 files changed, 29 insertions(+), 38 deletions(-) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/user/UserController.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/user/UserController.java index f0b8d921..e3ffbd30 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/user/UserController.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/user/UserController.java @@ -13,8 +13,6 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; -import java.time.LocalDate; - @Tag(name = "user", description = "유저 API") @RequiredArgsConstructor @RestController @@ -42,20 +40,20 @@ public ApiResponse updateUser( } @Operation(summary = "스트릭 조회", description = "스트릭을 조회한다.") - @GetMapping("/api/user/strick") - public ApiResponse getStrick( + @GetMapping("/api/user/streak") + public ApiResponse getStreak( @AuthenticationPrincipal JwtUser jwtUser, - UserReq.GetStrick request + UserReq.GetStreak request ) { if(request.startDate().isAfter(request.endDate())){ throw new IllegalArgumentException("시작일은 종료일보다 이전이어야 합니다."); } - var userModelStrick = userService.getUserStrick( + var userModelStreak = userService.getUserStreak( jwtUser.getId(), request.startDate(), request.endDate() ); - return ApiResponse.success(UserRes.Strick.from(userModelStrick)); + return ApiResponse.success(UserRes.Streak.from(userModelStreak)); } @Operation(summary = "유저 랭킹 페이징", description = "전체 유저 랭킹을 조회 페이징") diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/user/UserReq.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/user/UserReq.java index ed004d2c..e8f1a7e2 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/user/UserReq.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/user/UserReq.java @@ -19,13 +19,13 @@ public UserCommand.Update toCommand() { } @ParameterObject - public record GetStrick( + public record GetStreak( @Schema(description = "시작일(null이면 종료일보다 365일 전)", example = "2023-08-12") LocalDate startDate, @Schema(description = "종료일(null이면 현재일)", example = "2024-08-12") LocalDate endDate ){ - public GetStrick{ + public GetStreak{ if(endDate == null){ endDate = LocalDate.now(); } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/user/UserRes.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/user/UserRes.java index 2f971d7a..1254a995 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/user/UserRes.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/controller/user/UserRes.java @@ -64,13 +64,13 @@ public static TierInfo from(Integer exp) { } @Builder - public record Strick( + public record Streak( /** 여기서 Model의 DayCount를 사용해도 되는지 */ List dayCounts ) { - public static Strick from(UserModel.Strick strick){ - return Strick.builder() - .dayCounts(strick.dayCounts()) + public static Streak from(UserModel.Streak streak){ + return UserRes.Streak.builder() + .dayCounts(streak.dayCounts()) .build(); } } diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/user/UserModel.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/user/UserModel.java index 3aa0b8b2..70c1e307 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/user/UserModel.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/user/UserModel.java @@ -29,16 +29,16 @@ public static Main from(User user) { } @Builder - public record Strick( + public record Streak( List dayCounts ) { /** 여기서 count 0인걸 포함하는 기능을 쓰는게 맞는지 */ - public static Strick from(Map strickCounts, LocalDate startDate, LocalDate endDate) { + public static Streak from(Map streakCounts, LocalDate startDate, LocalDate endDate) { List resultList = startDate.datesUntil(endDate.plusDays(1)) // 날짜가 존재하면 map(date)로 count를 가져오고, 없으면 0을 저장한다. - .map(date -> new DayCount(date, strickCounts.getOrDefault(date, 0))) + .map(date -> new DayCount(date, streakCounts.getOrDefault(date, 0))) .collect(Collectors.toList()); - return new Strick(resultList); + return new Streak(resultList); } @Override diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/user/UserService.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/user/UserService.java index 50ec6e23..74aec432 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/user/UserService.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/domain/user/UserService.java @@ -43,10 +43,10 @@ public Page getUserPagingByRanking(Pageable pageable) { } @Transactional(readOnly = true) - public UserModel.Strick getUserStrick(Long id, LocalDate startDate, LocalDate endDate){ - List userStricks = userChallengeReader.countAllByUserIdAndDate(id, startDate, endDate); - Map map = userStricks.stream() + public UserModel.Streak getUserStreak(Long id, LocalDate startDate, LocalDate endDate){ + List userStreaks = userChallengeReader.countAllByUserIdAndDate(id, startDate, endDate); + Map map = userStreaks.stream() .collect(Collectors.toMap(DayCountType::getDate, DayCountType::getCount)); - return UserModel.Strick.from(map, startDate, endDate); + return UserModel.Streak.from(map, startDate, endDate); } } diff --git a/zzansuni-api-server/app/src/test/java/org/haedal/zzansuni/domain/user/UserIntegratedTest.java b/zzansuni-api-server/app/src/test/java/org/haedal/zzansuni/domain/user/UserIntegratedTest.java index 041e73aa..6a701f77 100644 --- a/zzansuni-api-server/app/src/test/java/org/haedal/zzansuni/domain/user/UserIntegratedTest.java +++ b/zzansuni-api-server/app/src/test/java/org/haedal/zzansuni/domain/user/UserIntegratedTest.java @@ -74,7 +74,7 @@ public void getUserPagingByRankingOrder(){ @DisplayName("유저의 스트릭을 조회한다.") @Test @Transactional - public void getUserStrick(){ + public void getUserStreak(){ User user = createUser("테스트유저"); userRepository.save(user); @@ -106,17 +106,17 @@ public void getUserStrick(){ //when - List userStricks = userChallengeReader.countAllByUserIdAndDate(user.getId(), LocalDate.now().minusDays(7), LocalDate.now()); + List userStreaks = userChallengeReader.countAllByUserIdAndDate(user.getId(), LocalDate.now().minusDays(7), LocalDate.now()); //then - assertThat(userStricks.size()).isEqualTo(2); - assertThat(userStricks.get(0).getDate()).isEqualTo(LocalDate.now().minusDays(5)); - assertThat(userStricks.get(0).getCount()).isEqualTo(1); - assertThat(userStricks.get(1).getDate()).isEqualTo(LocalDate.now().minusDays(4)); - assertThat(userStricks.get(1).getCount()).isEqualTo(1); - - System.out.println("userStrick: "); - for (DayCountType dayCountType : userStricks) { + assertThat(userStreaks.size()).isEqualTo(2); + assertThat(userStreaks.get(0).getDate()).isEqualTo(LocalDate.now().minusDays(5)); + assertThat(userStreaks.get(0).getCount()).isEqualTo(1); + assertThat(userStreaks.get(1).getDate()).isEqualTo(LocalDate.now().minusDays(4)); + assertThat(userStreaks.get(1).getCount()).isEqualTo(1); + + System.out.println("userStreak: "); + for (DayCountType dayCountType : userStreaks) { System.out.println(dayCountType.getDate() + " : " + dayCountType.getCount()); } } diff --git a/zzansuni-api-server/app/src/test/java/org/haedal/zzansuni/domain/user/UserServiceTest.java b/zzansuni-api-server/app/src/test/java/org/haedal/zzansuni/domain/user/UserServiceTest.java index 4d1df995..d071563d 100644 --- a/zzansuni-api-server/app/src/test/java/org/haedal/zzansuni/domain/user/UserServiceTest.java +++ b/zzansuni-api-server/app/src/test/java/org/haedal/zzansuni/domain/user/UserServiceTest.java @@ -113,13 +113,6 @@ public void getUserPagingByRankingOrder(){ } - @DisplayName("유저의 스트릭을 조회한다.") - @Test - public void getUserStrick(){ - - } - - User createUser(Long id, String nickname){ return User.builder()