Skip to content

Commit

Permalink
[Fix]: 스트릭 strick -> streak 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonssshyeon committed Sep 4, 2024
1 parent b4e5fc6 commit ffc5667
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ public ApiResponse<Void> updateUser(
}

@Operation(summary = "스트릭 조회", description = "스트릭을 조회한다.")
@GetMapping("/api/user/strick")
public ApiResponse<UserRes.Strick> getStrick(
@GetMapping("/api/user/streak")
public ApiResponse<UserRes.Streak> 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 = "전체 유저 랭킹을 조회 페이징")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public static TierInfo from(Integer exp) {
}

@Builder
public record Strick(
public record Streak(
/** 여기서 Model의 DayCount를 사용해도 되는지 */
List<UserModel.DayCount> dayCounts
) {
public static Strick from(UserModel.Strick strick){
return Strick.builder()
.dayCounts(strick.dayCounts())
public static Streak from(UserModel.Streak streak){
return Streak.builder()
.dayCounts(streak.dayCounts())
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ public static Main from(User user) {
}

@Builder
public record Strick(
public record Streak(
List<DayCount> dayCounts
) {
/** 여기서 count 0인걸 포함하는 기능을 쓰는게 맞는지 */
public static Strick from(Map<LocalDate, Integer> strickCounts, LocalDate startDate, LocalDate endDate) {
public static Streak from(Map<LocalDate, Integer> streakCounts, LocalDate startDate, LocalDate endDate) {
List<DayCount> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public Page<UserModel.Main> getUserPagingByRanking(Pageable pageable) {
}

@Transactional(readOnly = true)
public UserModel.Strick getUserStrick(Long id, LocalDate startDate, LocalDate endDate){
List<DayCountType> userStricks = userChallengeReader.countAllByUserIdAndDate(id, startDate, endDate);
Map<LocalDate, Integer> map = userStricks.stream()
public UserModel.Streak getUserStreak(Long id, LocalDate startDate, LocalDate endDate){
List<DayCountType> userStreaks = userChallengeReader.countAllByUserIdAndDate(id, startDate, endDate);
Map<LocalDate, Integer> map = userStreaks.stream()
.collect(Collectors.toMap(DayCountType::getDate, DayCountType::getCount));
return UserModel.Strick.from(map, startDate, endDate);
return UserModel.Streak.from(map, startDate, endDate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void getUserPagingByRankingOrder(){
@DisplayName("유저의 스트릭을 조회한다.")
@Test
@Transactional
public void getUserStrick(){
public void getUserStreak(){
User user = createUser("테스트유저");
userRepository.save(user);

Expand Down Expand Up @@ -107,17 +107,17 @@ public void getUserStrick(){


//when
List<DayCountType> userStricks = userChallengeReader.countAllByUserIdAndDate(user.getId(), LocalDate.now().minusDays(7), LocalDate.now());
List<DayCountType> 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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@ public void getUserPagingByRankingOrder(){
}


@DisplayName("유저의 스트릭을 조회한다.")
@Test
public void getUserStrick(){

}



User createUser(Long id, String nickname){
Expand Down

0 comments on commit ffc5667

Please sign in to comment.