Skip to content

Commit

Permalink
fix : 충돌해결
Browse files Browse the repository at this point in the history
  • Loading branch information
KkomSang committed May 29, 2024
2 parents 27d40dc + cb8cc16 commit 7788efa
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDateTime;
import java.util.List;
Expand All @@ -16,4 +18,7 @@ public interface RecordRepository extends JpaRepository<Record, Long> {
List<Record> findAllByUser(User user);
Long countAllByUser(User user);
Long countAllByCreatedAtBetweenAndUser(LocalDateTime startDate, LocalDateTime endDate, User user);
@Query("SELECT r.activity, COUNT(r) as count FROM Record r WHERE r.createdAt >= :time GROUP BY r.activity ORDER BY count DESC limit 3")
List<Object[]> findPopularActivities(@Param("time")LocalDateTime time);

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class ReportController {
private final ReportSummaryService reportSummaryService;
private final ReportActivityRankingService reportActivityRankingService;
private final ReportLocationRankingService reportLocationRankingService;
private final ReportTimeOfPeriodRankingService reportTimeOfPeriodRankingService;
private final ReportGraphService reportGraphService;
private final AverageHappinessService averageHappinessService;
@Operation(summary = "[전체] 행복 종합 리포트", description = "전체 기간에서 언제, 어디에서, 무엇을 할 때 행복했는지에 대한 종합적인 리포트를 제공합니다.")
Expand Down Expand Up @@ -162,6 +163,30 @@ public DataResponseDto<List<LocationHappinessDto>> getMonthlyLocationRankings(@A
List<LocationHappinessDto> responseDto = reportLocationRankingService.getMonthlyLocationRankings(user);
return DataResponseDto.of(responseDto, "월간 위치 행복도 순위를 성공적으로 조회했습니다.");
}

@Operation(summary = "[전체] 시간대 행복도 순위", description = "전체 기록에서 시간대 행복도 순위를 제공합니다.")
@GetMapping("/all/ranking/time")
public DataResponseDto<List<TimeOfDayHappinessDto>> getAllTimeOfDayRankings(@AuthenticationPrincipal UserDetails userDetails) {
User user = userFindService.findByUserDetails(userDetails);
List<TimeOfDayHappinessDto> responseDto = reportTimeOfPeriodRankingService.getAllTimeOfDayRankings(user);
return DataResponseDto.of(responseDto, "전체 시간대 행복도 순위를 성공적으로 조회했습니다.");
}

@Operation(summary = "[연간] 시간대 행복도 순위", description = "이번 해 시간대 행복도 순위를 제공합니다.")
@GetMapping("/year/ranking/time")
public DataResponseDto<List<TimeOfDayHappinessDto>> getYearlyTimeOfDayRankings(@AuthenticationPrincipal UserDetails userDetails) {
User user = userFindService.findByUserDetails(userDetails);
List<TimeOfDayHappinessDto> responseDto = reportTimeOfPeriodRankingService.getYearlyTimeOfDayRankings(user);
return DataResponseDto.of(responseDto, "연간 시간대 행복도 순위를 성공적으로 조회했습니다.");
}

@Operation(summary = "[월간] 시간대 행복도 순위", description = "이번 달 시간대 행복도 순위를 제공합니다.")
@GetMapping("/month/ranking/time")
public DataResponseDto<List<TimeOfDayHappinessDto>> getMonthlyTimeOfDayRankings(@AuthenticationPrincipal UserDetails userDetails) {
User user = userFindService.findByUserDetails(userDetails);
List<TimeOfDayHappinessDto> responseDto = reportTimeOfPeriodRankingService.getMonthlyTimeOfDayRankings(user);
return DataResponseDto.of(responseDto, "월간 시간대 행복도 순위를 성공적으로 조회했습니다.");
}
@Operation(summary = "[전체] 평균 행복지수", description = "유저 개인의 전체기간 평균 행복지수와 그에 따른 수준을 판단합니다.")
@GetMapping("/all/happiness/")
public DataResponseDto<AverageHappinessResponseDto> getAllHappiness(@AuthenticationPrincipal UserDetails userDetails) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.hobak.happinessql.domain.report.converter;

import com.hobak.happinessql.domain.report.domain.HappinessLevel;
import com.hobak.happinessql.domain.report.domain.TimePeriod;
import com.hobak.happinessql.domain.report.domain.TimeOfDay;
import com.hobak.happinessql.domain.report.dto.*;

import java.util.ArrayList;

public class ReportConverter {
public static ReportSummaryResponseDto toReportSummaryResponseDto(TimePeriod timePeriod, String location, String activity) {
public static ReportSummaryResponseDto toReportSummaryResponseDto(TimeOfDay timeOfDay, String location, String activity) {
return ReportSummaryResponseDto.builder()
.activity(activity)
.location(location)
.timePeriod(timePeriod)
.timeOfDay(timeOfDay)
.build();
}

Expand All @@ -35,6 +35,12 @@ public static ReportGraphResponseDto toReportGraphResponseDto(ArrayList<String>
.happiness(happiness)
.build();
}
public static TimeOfDayHappinessDto toTimeOfDayHappinessDto(int ranking, TimeOfDay timeOfDay) {
return TimeOfDayHappinessDto.builder()
.ranking(ranking)
.timeOfDay(timeOfDay)
.build();
}
public static AverageHappinessResponseDto toAverageHappinessResponseDto(double happiness, HappinessLevel level, String emoji) {
return AverageHappinessResponseDto
.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.hobak.happinessql.domain.report.converter;
import com.hobak.happinessql.domain.report.dto.TrendPopularActivitiesResponseDto;

public class TrendConverter {
public static TrendPopularActivitiesResponseDto toTrendPopularActivitiesResponseDto(int ranking, String name, String emoji, Long times) {
return TrendPopularActivitiesResponseDto
.builder()
.ranking(ranking)
.times(times)
.name(name)
.emoji(emoji)
.build();
}
}

0 comments on commit 7788efa

Please sign in to comment.