Skip to content

Commit

Permalink
Merge pull request #121 from Happy-HOBAK/fix/#120
Browse files Browse the repository at this point in the history
[#120] 행볡 νŠΈλ Œλ“œμ˜ 행볡 μž₯μ†Œ BEST 3λ₯Ό 였늘 κΈ°μ€€ λ°μ΄ν„°λ§Œ 보여주도둝 μˆ˜μ •
  • Loading branch information
yel-m authored Jun 9, 2024
2 parents 4d81b4a + d1f8ce7 commit 358ead4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@

public interface RecordRepository extends JpaRepository<Record, Long> {
Page<Record> findByUserOrderByRecordIdDesc(User user, Pageable pageRequest);

Page<Record> findByRecordIdLessThanAndUserOrderByRecordIdDesc(Long recordId, User user, Pageable pageRequest);

List<Record> findAllByCreatedAtBetweenAndUser(LocalDateTime startOfMonth, LocalDateTime endOfMonth, User user);

List<Record> findAllByCreatedAtBetween(LocalDateTime startOfMonth, LocalDateTime endOfMonth);

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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ public DataResponseDto<Object> getSummary(@RequestParam(required = false) AgeGro

@Operation(summary = "행볡도가 높은 μž₯μ†Œμ™€ ν™œλ™ Top3", description = "전체 μœ μ €κ°€ ν–‰λ³΅ν–ˆλ˜ μž₯μ†Œ Top 3의 이름, μœ„μΉ˜, κ·Έ μž₯μ†Œμ—μ„œ κ°€μž₯ 행볡도가 λ†’μ•˜λ˜ ν™œλ™μ„ μ‘°νšŒν•©λ‹ˆλ‹€.")
@GetMapping("/top-locations")
public DataResponseDto<List<LocationActivityRankingResponseDto>> getTop3HappiestLocations(@AuthenticationPrincipal UserDetails userDetails) {
User user = userFindService.findByUserDetails(userDetails);
List<LocationActivityRankingResponseDto> responseDto = trendLocationRankingService.getTop3HappyLocationsWithActivities(user);
public DataResponseDto<List<LocationActivityRankingResponseDto>> getTop3HappiestLocations() {
List<LocationActivityRankingResponseDto> responseDto = trendLocationRankingService.getTop3HappyLocationsWithActivities();
return DataResponseDto.of(responseDto, "행볡도가 높은 μž₯μ†Œμ™€ ν™œλ™ Top3λ₯Ό μ„±κ³΅μ μœΌλ‘œ μ‘°νšŒν–ˆμŠ΅λ‹ˆλ‹€.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import com.hobak.happinessql.domain.record.domain.Record;
import com.hobak.happinessql.domain.record.repository.RecordRepository;
import com.hobak.happinessql.domain.report.dto.LocationActivityRankingResponseDto;
import com.hobak.happinessql.domain.user.domain.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
Expand All @@ -15,9 +16,10 @@ public class TrendLocationRankingService {

private final RecordRepository recordRepository;

public List<LocationActivityRankingResponseDto> getTop3HappyLocationsWithActivities(User user) {
List<Record> records = recordRepository.findAllByUser(user);
public List<LocationActivityRankingResponseDto> getTop3HappyLocationsWithActivities() {
LocalDateTime startOfDay = LocalDate.now().atStartOfDay();
LocalDateTime endOfDay = LocalDate.now().atTime(23, 59, 59);
List<Record> records = recordRepository.findAllByCreatedAtBetween(startOfDay, endOfDay);
return LocationHappinessAnalyzer.getLocationActivityRankings(records, 3);

}
}

0 comments on commit 358ead4

Please sign in to comment.