Skip to content

Commit

Permalink
fix : 행복 트렌드의 행복 장소 BEST 3를 오늘 기준 데이터만 보여주도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
yel-m committed Jun 9, 2024
1 parent 4d81b4a commit cf2175e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 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 @@ -7,6 +7,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

@Service
Expand All @@ -16,8 +18,9 @@ public class TrendLocationRankingService {
private final RecordRepository recordRepository;

public List<LocationActivityRankingResponseDto> getTop3HappyLocationsWithActivities(User user) {
List<Record> records = recordRepository.findAllByUser(user);
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 cf2175e

Please sign in to comment.