Skip to content

Commit

Permalink
Merge pull request #80 from shim-pyoo/fix/#79-CalculateError
Browse files Browse the repository at this point in the history
πŸ› FIX. 호흑 μΈ‘μ • 및 쑰회 μ‹œ, db에 4~5λ²ˆμ”© λ“€μ–΄κ°€λŠ” 였λ₯˜ μˆ˜μ •
  • Loading branch information
frombunny authored Sep 13, 2024
2 parents 396784e + 3b4f478 commit 113cd22
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
import com.hsu.shimpyoo.domain.user.entity.User;
import com.hsu.shimpyoo.domain.user.repository.UserRepository;
import com.hsu.shimpyoo.global.aws.s3.service.S3Service;
import com.hsu.shimpyoo.global.response.CustomAPIResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.ErrorResponseException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ResponseStatusException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,22 @@ public CustomAPIResponse<Map<String, Object>> calculateBreathingResult(Breathing
// ν˜„μž¬ μš”μΌμ— ν•΄λ‹Ήν•˜λŠ” WeekDay Enum을 κ°€μ Έμ˜΅λ‹ˆλ‹€.
WeekDay currentWeekDay = WeekDay.valueOf(LocalDateTime.now().getDayOfWeek().name());

// DailyPef λ°μ΄ν„°λ² μ΄μŠ€μ— μƒνƒœμ™€ μ΅œλŒ€ν˜ΈκΈ°λŸ‰μ„ μ €μž₯
DailyPef dailyPef = DailyPef.builder()
.userId(user)
.pef(maxBreathingRate)
.state(state) // Enum νƒ€μž…μœΌλ‘œ μƒνƒœ μ €μž₯
.weekDay(currentWeekDay) // Enum νƒ€μž…μœΌλ‘œ μš”μΌ μ €μž₯
.build();
dailyPefRepository.save(dailyPef);
LocalDateTime startOfToday = LocalDate.now().atStartOfDay(); // 였늘의 μ‹œμž‘ μ‹œκ°„
LocalDateTime endOfToday = LocalDate.now().atTime(LocalTime.MAX); // 였늘의 끝 μ‹œκ°„

// 이미 였늘의 DailyPef 데이터가 μ €μž₯λ˜μ–΄ μžˆλŠ”μ§€ 확인
Optional<DailyPef> existingDailyPef = dailyPefRepository.findTopByUserIdAndCreatedAtBetweenOrderByCreatedAtDesc(user, startOfToday, endOfToday);

// 였늘의 데이터가 없을 λ•Œλ§Œ μ €μž₯
if (!existingDailyPef.isPresent()) { // DailyPef λ°μ΄ν„°λ² μ΄μŠ€μ— μƒνƒœμ™€ μ΅œλŒ€ν˜ΈκΈ°λŸ‰μ„ μ €μž₯
DailyPef dailyPef = DailyPef.builder()
.userId(user)
.pef(maxBreathingRate)
.state(state) // Enum νƒ€μž…μœΌλ‘œ μƒνƒœ μ €μž₯
.weekDay(currentWeekDay) // Enum νƒ€μž…μœΌλ‘œ μš”μΌ μ €μž₯
.build();
dailyPefRepository.save(dailyPef);
}

// λ°˜ν™˜ 데이터
Map<String, Object> responseData = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ public class BreathingController {
private final UserRepository userRepository;
private final BreathingRepository breathingRepository;

// // 였늘의 μ‰Ό κ²°κ³Ό
// @PostMapping("/today/result")
// public CustomAPIResponse<Map<String, Object>> getTodayBreathingResult(
// @RequestBody BreathingPefDto dto) {
// // ν˜„μž¬ 둜그인된 μ‚¬μš©μž 정보 κ°€μ Έμ˜€κΈ°
// String loginId = authenticationUserUtils.getCurrentUserId();
// User user = userRepository.findByLoginId(loginId)
// .orElseThrow(() -> new UsernameNotFoundException("ν•΄λ‹Ή μ‚¬μš©μžκ°€ μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€."));
//
// return breathingService.calculateBreathingResult(dto, user);
// }

// 였늘 μΈ‘μ •ν•œ 호흑 기둝을 μ°Ύμ•„μ„œ, κ²°κ³Όλ₯Ό 쑰회
@GetMapping("/today/result")
public CustomAPIResponse<Map<String, Object>> getTodayBreathingResult() {
Expand Down

0 comments on commit 113cd22

Please sign in to comment.