Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#109] 활동 추천 API 구축 #113

Merged
merged 9 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ public interface RecordRepository extends JpaRepository<Record, Long> {
@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);

@Query("SELECT r FROM Record r WHERE r.user.userId != :userId")
List<Record> findAllExceptUser(@Param("userId") Long userId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,49 +56,49 @@ public DataResponseDto<ReportSummaryResponseDto> getMonthlySummary(@Authenticati

@Operation(summary = "[전체] 행복도가 높은 Top 3 활동", description = "전체 기록에서 가장 행복도가 높은 Top 3 활동을 제공합니다.")
@GetMapping("/all/top-activities")
public DataResponseDto<List<ActivityHappinessDto>> getTop3AllHappiestActivities(@AuthenticationPrincipal UserDetails userDetails) {
public DataResponseDto<List<ActivityHappinessResponseDto>> getTop3AllHappiestActivities(@AuthenticationPrincipal UserDetails userDetails) {
User user = userFindService.findByUserDetails(userDetails);
List<ActivityHappinessDto> responseDto = reportActivityRankingService.getTop3AllHappiestActivities(user);
List<ActivityHappinessResponseDto> responseDto = reportActivityRankingService.getTop3AllHappiestActivities(user);
return DataResponseDto.of(responseDto, "행복도가 높은 Top 3 활동(전체)을 성공적으로 조회했습니다.");
}

@Operation(summary = "[연간] 행복도가 높은 Top 3 활동", description = "이번 해 가장 행복도가 높은 Top 3 활동을 제공합니다.")
@GetMapping("/year/top-activities")
public DataResponseDto<List<ActivityHappinessDto>> getTop3AnnualHappiestActivities(@AuthenticationPrincipal UserDetails userDetails) {
public DataResponseDto<List<ActivityHappinessResponseDto>> getTop3AnnualHappiestActivities(@AuthenticationPrincipal UserDetails userDetails) {
User user = userFindService.findByUserDetails(userDetails);
List<ActivityHappinessDto> responseDto = reportActivityRankingService.getTop3AnnualHappiestActivities(user);
List<ActivityHappinessResponseDto> responseDto = reportActivityRankingService.getTop3AnnualHappiestActivities(user);
return DataResponseDto.of(responseDto, "행복도가 높은 Top 3 활동(연간)을 성공적으로 조회했습니다.");
}

@Operation(summary = "[월간] 행복도가 높은 Top 3 활동", description = "이번 해 가장 행복도가 높은 Top 3 활동을 제공합니다.")
@GetMapping("/month/top-activities")
public DataResponseDto<List<ActivityHappinessDto>> getTop3MonthlyHappiestActivities(@AuthenticationPrincipal UserDetails userDetails) {
public DataResponseDto<List<ActivityHappinessResponseDto>> getTop3MonthlyHappiestActivities(@AuthenticationPrincipal UserDetails userDetails) {
User user = userFindService.findByUserDetails(userDetails);
List<ActivityHappinessDto> responseDto = reportActivityRankingService.getTop3MonthlyHappiestActivities(user);
List<ActivityHappinessResponseDto> responseDto = reportActivityRankingService.getTop3MonthlyHappiestActivities(user);
return DataResponseDto.of(responseDto, "행복도가 높은 Top 3 활동(월간)을 성공적으로 조회했습니다.");
}

@Operation(summary = "[전체] 행복도가 높은 Top 3 위치", description = "전체 기록에서 가장 행복도가 높은 Top 3 위치을 제공합니다.")
@GetMapping("/all/top-locations")
public DataResponseDto<List<LocationHappinessDto>> getTop3AllHappiestLocations(@AuthenticationPrincipal UserDetails userDetails) {
public DataResponseDto<List<LocationHappinessResponseDto>> getTop3AllHappiestLocations(@AuthenticationPrincipal UserDetails userDetails) {
User user = userFindService.findByUserDetails(userDetails);
List<LocationHappinessDto> responseDto = reportLocationRankingService.getTop3AllHappiestLocations(user);
List<LocationHappinessResponseDto> responseDto = reportLocationRankingService.getTop3AllHappiestLocations(user);
return DataResponseDto.of(responseDto, "행복도가 높은 Top 3 위치(전체)를 성공적으로 조회했습니다.");
}

@Operation(summary = "[연간] 행복도가 높은 Top 3 위치", description = "이번 해 가장 행복도가 높은 Top 3 위치를 제공합니다.")
@GetMapping("/year/top-locations")
public DataResponseDto<List<LocationHappinessDto>> getTop3AnnualHappiestLocations(@AuthenticationPrincipal UserDetails userDetails) {
public DataResponseDto<List<LocationHappinessResponseDto>> getTop3AnnualHappiestLocations(@AuthenticationPrincipal UserDetails userDetails) {
User user = userFindService.findByUserDetails(userDetails);
List<LocationHappinessDto> responseDto = reportLocationRankingService.getTop3AnnualHappiestLocations(user);
List<LocationHappinessResponseDto> responseDto = reportLocationRankingService.getTop3AnnualHappiestLocations(user);
return DataResponseDto.of(responseDto, "행복도가 높은 Top 3 위치(연간)를 성공적으로 조회했습니다.");
}

@Operation(summary = "[월간] 행복도가 높은 Top 3 위치", description = "이번 해 가장 행복도가 높은 Top 3 위치를 제공합니다.")
@GetMapping("/month/top-locations")
public DataResponseDto<List<LocationHappinessDto>> getTop3MonthlyHappiestLocations(@AuthenticationPrincipal UserDetails userDetails) {
public DataResponseDto<List<LocationHappinessResponseDto>> getTop3MonthlyHappiestLocations(@AuthenticationPrincipal UserDetails userDetails) {
User user = userFindService.findByUserDetails(userDetails);
List<LocationHappinessDto> responseDto = reportLocationRankingService.getTop3MonthlyHappiestLocations(user);
List<LocationHappinessResponseDto> responseDto = reportLocationRankingService.getTop3MonthlyHappiestLocations(user);
return DataResponseDto.of(responseDto, "행복도가 높은 Top 3 위치(월간)를 성공적으로 조회했습니다.");
}
@Operation(summary = "[연간] 행복 그래프", description = "연간 행복지수 그래프를 제공합니다.")
Expand All @@ -118,73 +118,73 @@ public DataResponseDto<ReportGraphResponseDto> getMonthlyGraph(@AuthenticationPr

@Operation(summary = "[전체] 모든 활동의 행복도 순위", description = "전체 기록에서 모든 활동의 행복도 순위를 제공합니다.")
@GetMapping("/all/ranking/activities")
public DataResponseDto<List<ActivityHappinessDto>> getAllActivityRankings(@AuthenticationPrincipal UserDetails userDetails) {
public DataResponseDto<List<ActivityHappinessResponseDto>> getAllActivityRankings(@AuthenticationPrincipal UserDetails userDetails) {
User user = userFindService.findByUserDetails(userDetails);
List<ActivityHappinessDto> responseDto = reportActivityRankingService.getAllActivityRankings(user);
List<ActivityHappinessResponseDto> responseDto = reportActivityRankingService.getAllActivityRankings(user);
return DataResponseDto.of(responseDto, "전체 활동 행복도 순위를 성공적으로 조회했습니다.");
}

@Operation(summary = "[연간] 모든 활동의 행복도 순위", description = "이번 해 모든 활동의 행복도 순위를 제공합니다.")
@GetMapping("/year/ranking/activities")
public DataResponseDto<List<ActivityHappinessDto>> getYearlyActivityRankings(@AuthenticationPrincipal UserDetails userDetails) {
public DataResponseDto<List<ActivityHappinessResponseDto>> getYearlyActivityRankings(@AuthenticationPrincipal UserDetails userDetails) {
User user = userFindService.findByUserDetails(userDetails);
List<ActivityHappinessDto> responseDto = reportActivityRankingService.getYearlyActivityRankings(user);
List<ActivityHappinessResponseDto> responseDto = reportActivityRankingService.getYearlyActivityRankings(user);
return DataResponseDto.of(responseDto, "연간 활동 행복도 순위를 성공적으로 조회했습니다.");
}

@Operation(summary = "[월간] 모든 활동의 행복도 순위", description = "이번 달 모든 활동의 행복도 순위를 제공합니다.")
@GetMapping("/month/ranking/activities")
public DataResponseDto<List<ActivityHappinessDto>> getMonthlyActivityRankings(@AuthenticationPrincipal UserDetails userDetails) {
public DataResponseDto<List<ActivityHappinessResponseDto>> getMonthlyActivityRankings(@AuthenticationPrincipal UserDetails userDetails) {
User user = userFindService.findByUserDetails(userDetails);
List<ActivityHappinessDto> responseDto = reportActivityRankingService.getMonthlyActivityRankings(user);
List<ActivityHappinessResponseDto> responseDto = reportActivityRankingService.getMonthlyActivityRankings(user);
return DataResponseDto.of(responseDto, "월간 활동 행복도 순위를 성공적으로 조회했습니다.");
}

@Operation(summary = "[전체] 모든 위치의 행복도 순위", description = "전체 기록에서 모든 위치의 행복도 순위를 제공합니다.")
@GetMapping("/all/ranking/locations")
public DataResponseDto<List<LocationHappinessDto>> getAllLocationRankings(@AuthenticationPrincipal UserDetails userDetails) {
public DataResponseDto<List<LocationHappinessResponseDto>> getAllLocationRankings(@AuthenticationPrincipal UserDetails userDetails) {
User user = userFindService.findByUserDetails(userDetails);
List<LocationHappinessDto> responseDto = reportLocationRankingService.getAllLocationRankings(user);
List<LocationHappinessResponseDto> responseDto = reportLocationRankingService.getAllLocationRankings(user);
return DataResponseDto.of(responseDto, "전체 위치 행복도 순위를 성공적으로 조회했습니다.");
}

@Operation(summary = "[연간] 모든 위치의 행복도 순위", description = "이번 해 모든 위치의 행복도 순위를 제공합니다.")
@GetMapping("/year/ranking/locations")
public DataResponseDto<List<LocationHappinessDto>> getYearlyLocationRankings(@AuthenticationPrincipal UserDetails userDetails) {
public DataResponseDto<List<LocationHappinessResponseDto>> getYearlyLocationRankings(@AuthenticationPrincipal UserDetails userDetails) {
User user = userFindService.findByUserDetails(userDetails);
List<LocationHappinessDto> responseDto = reportLocationRankingService.getYearlyLocationRankings(user);
List<LocationHappinessResponseDto> responseDto = reportLocationRankingService.getYearlyLocationRankings(user);
return DataResponseDto.of(responseDto, "연간 위치 행복도 순위를 성공적으로 조회했습니다.");
}

@Operation(summary = "[월간] 모든 위치의 행복도 순위", description = "이번 달 모든 위치의 행복도 순위를 제공합니다.")
@GetMapping("/month/ranking/locations")
public DataResponseDto<List<LocationHappinessDto>> getMonthlyLocationRankings(@AuthenticationPrincipal UserDetails userDetails) {
public DataResponseDto<List<LocationHappinessResponseDto>> getMonthlyLocationRankings(@AuthenticationPrincipal UserDetails userDetails) {
User user = userFindService.findByUserDetails(userDetails);
List<LocationHappinessDto> responseDto = reportLocationRankingService.getMonthlyLocationRankings(user);
List<LocationHappinessResponseDto> responseDto = reportLocationRankingService.getMonthlyLocationRankings(user);
return DataResponseDto.of(responseDto, "월간 위치 행복도 순위를 성공적으로 조회했습니다.");
}

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

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

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

import com.hobak.happinessql.domain.report.application.AverageHappinessService;
import com.hobak.happinessql.domain.report.application.TrendPopularActivitiesService;
import com.hobak.happinessql.domain.report.application.TrendPopularActivityService;
import com.hobak.happinessql.domain.report.application.TrendRecommendService;
import com.hobak.happinessql.domain.report.dto.AverageHappinessResponseDto;
import com.hobak.happinessql.domain.report.dto.TrendPopularActivitiesResponseDto;
import com.hobak.happinessql.domain.report.dto.TrendPopularActivitiyResponseDto;
import com.hobak.happinessql.domain.report.dto.TrendRecommendActivityResponseDto;
import com.hobak.happinessql.domain.user.application.UserFindService;
import com.hobak.happinessql.domain.user.domain.User;
import com.hobak.happinessql.global.response.DataResponseDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -19,18 +25,30 @@
@RequiredArgsConstructor
@RequestMapping("api/trend")
public class TrendController {
private final UserFindService userFindService;
private final AverageHappinessService averageHappinessService;
private final TrendPopularActivitiesService trendPopularActivitiesService;
private final TrendPopularActivityService trendPopularActivityService;
private final TrendRecommendService trendRecommendService;

@Operation(summary = "대한민국 평균 행복지수", description = "전체 유저의 평균 행복지수와 그에 따른 수준을 판단합니다.")
@GetMapping("/happiness")
public DataResponseDto<AverageHappinessResponseDto> getHappiness() {
public DataResponseDto<AverageHappinessResponseDto> getAverageHappiness() {
AverageHappinessResponseDto responseDto = averageHappinessService.getTrendHappiness();
return DataResponseDto.of(responseDto, "대한민국 평균 행복지수를 성공적으로 조회했습니다.");
}
@Operation(summary = "오늘의 인기 활동 top3", description = "오늘 많이 기록된 활동의 이름과 기록 횟수를 조회합니다.")
@GetMapping("/popular")
public DataResponseDto<List<TrendPopularActivitiesResponseDto>> getPopular() {
List<TrendPopularActivitiesResponseDto> responseDto = trendPopularActivitiesService.getPopularActivities();
public DataResponseDto<List<TrendPopularActivitiyResponseDto>> getPopularActivities() {
List<TrendPopularActivitiyResponseDto> responseDto = trendPopularActivityService.getPopularActivities();
return DataResponseDto.of(responseDto, "오늘의 인기 활동을 성공적으로 조회했습니다.");
}

@Operation(summary = "추천 활동", description = "추천 활동을 조회합니다. 행복도가 5 이상인 활동 중에서 랜덤으로 하나를 추천받을 수 있습니다.")
@GetMapping("/recommend")
public DataResponseDto<List<TrendRecommendActivityResponseDto>> getRecommendedActivities(@AuthenticationPrincipal UserDetails userDetails) {
User user = userFindService.findByUserDetails(userDetails);
List<TrendRecommendActivityResponseDto> responseDto = trendRecommendService.getRecommendActivities(user);
return DataResponseDto.of(responseDto, "추천 활동을 성공적으로 조회했습니다.");
return DataResponseDto.of(responseDto, "오늘의 인기 활동을 성공적으로 조회했습니다.");
yel-m marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading