Skip to content

Commit

Permalink
Fix(#171-battery): 수면 내역 조회 today 조건 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hojeong2747 committed May 25, 2023
1 parent 4ded34c commit b5abfa9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public interface BatteryRepository extends JpaRepository<Battery, Long> {

@Modifying(clearAutomatically = true)
@Query(value = "update ss_battery set cur_battery = 100 where user_id=:userId", nativeQuery = true)
void updateCurBattery100(Long userId);
void updateCurBattery100(@Param("userId") Long userId);

// 배터리 증감 내역 레코드 추가
@Query(value = "select battery_id from ss_battery where user_id=:userId", nativeQuery = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ 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 = LocalDate.now().atStartOfDay(); // Current date and time
LocalDateTime startDate = endDate.minusDays(7); // 7 days ago

Expand Down Expand Up @@ -262,6 +259,19 @@ public List<SleepResponseDto> getUserSleep(Long userId, Integer year, Integer mo
int todayDay = date.getDayOfMonth(); // Extract the day of the month

for (SleepResponseDto sleepRes : res) {
Integer curSleep = batteryRepository.findUserCurSleep(userId);
if (todayDay == sleepRes.getDay() && curSleep != null) {
sleepRes.setSleep(curSleep);
// 오늘 수면량 입력했으면 따로 확인
if (curSleep < sleepGoal * 0.5) {
sleepRes.setColor(3);
} else if (curSleep < sleepGoal && curSleep >= sleepGoal * 0.5) {
sleepRes.setColor(2);
} else if (curSleep >= sleepGoal) {
sleepRes.setColor(1);
}
}

for (SleepDto result : resultList) {
if (result.getDay() == sleepRes.getDay()) {
sleepRes.setSleep(result.getSleep());
Expand Down

0 comments on commit b5abfa9

Please sign in to comment.