Skip to content

Commit

Permalink
Fix(#171-battery): 배터리 수준 조회 7일 LocalDate 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hojeong2747 committed May 25, 2023
1 parent fda0d61 commit bcacd14
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -66,9 +67,10 @@ public interface BatteryRepository extends JpaRepository<Battery, Long> {
// 배터리 수준 조회 (7일 퍼센트)
@Query(value = "select distinct new com._8attery.seesaw.dto.api.response.BatteryPercentResponseDto(b1.createdAt, b1.batteryPercentage) from BatteryHistory b1 join b1.battery b2 " +
"where b2.user.id=:userId " +
"and b1.createdAt between :startDate and :endDate " +
"and DATE(b1.createdAt) between :startDate and :endDate " +
"order by b1.createdAt desc")
List<BatteryPercentResponseDto> findUserBatteryHistory(@Param("userId") Long userId, @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate);
List<BatteryPercentResponseDto> findUserBatteryHistory(@Param("userId") Long userId, @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate);


// 배터리 증감 조회 (30일 증감 내역)
@Query(value = "select DISTINCT new com._8attery.seesaw.dto.api.response.BatteryDataVariationDto(b1.createdAt, b1.sleepTime, b1.sleepGoal, " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ public Integer setUserCurSleep(Long userId, Integer req) throws BaseException {
@Transactional
public List<BatteryPercentResponseDto> getUserBatteryHistory(Long userId) throws BaseException {
try {
LocalDateTime endDate = LocalDateTime.now(); // Current date and time
LocalDateTime startDate = endDate.minusDays(7); // 7 days ago
// LocalDateTime endDate = LocalDateTime.now(); // Current date and time
// LocalDateTime startDate = endDate.minusDays(7); // 7 days ago

LocalDate endDate = LocalDate.now(); // Current date and time
LocalDate startDate = endDate.minusDays(7); // 7 days ago

return batteryRepository.findUserBatteryHistory(userId, startDate, endDate);

Expand Down

0 comments on commit bcacd14

Please sign in to comment.