diff --git a/BackEnd/src/main/java/chuchu/runnerway/course/controller/OfficialCourseController.java b/BackEnd/src/main/java/chuchu/runnerway/course/controller/OfficialCourseController.java index c025531c..c03ef535 100644 --- a/BackEnd/src/main/java/chuchu/runnerway/course/controller/OfficialCourseController.java +++ b/BackEnd/src/main/java/chuchu/runnerway/course/controller/OfficialCourseController.java @@ -37,6 +37,7 @@ public class OfficialCourseController { }) public ResponseEntity findAllOfficialCourses(@RequestParam double lat, @RequestParam double lng) { List courses = officialCourseService.findAllOfiicialCourse(lat, lng); + if(courses == null) return ResponseEntity.status(204).build(); return ResponseEntity.ok(courses); } @@ -51,7 +52,7 @@ public ResponseEntity findAllOfficialCourses(@RequestParam double lat, @Reque }) public ResponseEntity getOfficialCourse(@PathVariable("courseId") Long courseId) { OfficialDetailResponseDto course = officialCourseService.getOfficialCourse(courseId); - + if(course == null) return ResponseEntity.status(404).body("데이터가 존재하지 않습니다."); return ResponseEntity.ok(course); } diff --git a/BackEnd/src/main/java/chuchu/runnerway/course/controller/SearchCourseController.java b/BackEnd/src/main/java/chuchu/runnerway/course/controller/SearchCourseController.java index d4dbb75f..ea23437c 100644 --- a/BackEnd/src/main/java/chuchu/runnerway/course/controller/SearchCourseController.java +++ b/BackEnd/src/main/java/chuchu/runnerway/course/controller/SearchCourseController.java @@ -34,7 +34,7 @@ public ResponseEntity search(@RequestParam("searchWord") String searchWord, @RequestParam(value = "size", defaultValue = "10") int size) { SelectAllResponseDto selectAllResponseDtoList = searchCourseService.search(searchWord, page, size); - if(selectAllResponseDtoList.getSearchCourseList().isEmpty()) return ResponseEntity.status(200).body("검색 조건에 일치하는 결과가 없습니다."); + if(selectAllResponseDtoList.getSearchCourseList().isEmpty()) return ResponseEntity.status(204).body("검색 조건에 일치하는 결과가 없습니다."); return ResponseEntity.ok(selectAllResponseDtoList); } diff --git a/BackEnd/src/main/java/chuchu/runnerway/course/controller/UserCourseController.java b/BackEnd/src/main/java/chuchu/runnerway/course/controller/UserCourseController.java index c25943df..77634253 100644 --- a/BackEnd/src/main/java/chuchu/runnerway/course/controller/UserCourseController.java +++ b/BackEnd/src/main/java/chuchu/runnerway/course/controller/UserCourseController.java @@ -34,6 +34,7 @@ public class UserCourseController { }) public ResponseEntity selectUserCourseList(@RequestParam Double lat, @RequestParam Double lng) { List userCourseList = userCourseService.findAllUserCourse(lat, lng); + if(userCourseList.isEmpty()) return ResponseEntity.status(204).build(); return ResponseEntity.status(HttpStatus.OK).body(userCourseList); } @@ -48,6 +49,7 @@ public ResponseEntity selectUserCourseList(@RequestParam Double lat, @Request }) public ResponseEntity getUserCourse(@PathVariable("courseId") Long courseId) { UserDetailResponseDto course = userCourseService.getUserCourse(courseId); + if(course == null) return ResponseEntity.status(404).body("데이터가 존재하지 않습니다."); return ResponseEntity.ok(course); } @@ -62,6 +64,7 @@ public ResponseEntity getUserCourse(@PathVariable("courseId") Long courseId) }) public ResponseEntity selectPopularAllList(@RequestParam Double lat, @RequestParam Double lng) { List userCourseList = userCourseService.findPopularAllUserCourse(lat, lng); + if(userCourseList.isEmpty()) return ResponseEntity.status(204).build(); return ResponseEntity.ok(userCourseList); } @@ -76,6 +79,7 @@ public ResponseEntity selectPopularAllList(@RequestParam Double lat, @Request }) public ResponseEntity selectPopularLatelyList(@RequestParam Double lat, @RequestParam Double lng) { List userCourseList = userCourseService.findPopularLatelyUserCourse(lat, lng); + if(userCourseList.isEmpty()) return ResponseEntity.status(204).build(); return ResponseEntity.ok(userCourseList); } diff --git a/BackEnd/src/main/java/chuchu/runnerway/course/model/service/OfficialCourseServiceImpl.java b/BackEnd/src/main/java/chuchu/runnerway/course/model/service/OfficialCourseServiceImpl.java index 0ff2b891..93eba843 100644 --- a/BackEnd/src/main/java/chuchu/runnerway/course/model/service/OfficialCourseServiceImpl.java +++ b/BackEnd/src/main/java/chuchu/runnerway/course/model/service/OfficialCourseServiceImpl.java @@ -46,7 +46,7 @@ public class OfficialCourseServiceImpl implements OfficialCourseService{ @Override public List findAllOfiicialCourse(double lat, double lng) { List courses = getRecommendation(lat, lng); - if(courses.isEmpty()) throw new NoSuchElementException(); + if(courses.isEmpty()) return null; for(RecommendationDto course : courses) { Optional courseImage = courseImageRepositoryPrimaryKey.findById(course.getCourseId()); courseImage.ifPresent(image -> course.setCourseImage(courseMapper.toCourseImageDto(image))); @@ -57,10 +57,10 @@ public List findAllOfiicialCourse(double lat, double lng) { @Override @Cacheable(value = "officialCourseCache", key = "#courseId", unless = "#result == null") public OfficialDetailResponseDto getOfficialCourse(Long courseId) { - Course course = officialCourseRepository.findById(courseId) - .orElseThrow(NoSuchElementException::new); - + Course course = officialCourseRepository.findById(courseId).orElse(null); + if(course == null) return null; OfficialDetailResponseDto dto = courseMapper.toOfficialDetailResponseDto(course); + dto.setMemberId(course.getMember().getMemberId()); return dto; diff --git a/BackEnd/src/main/java/chuchu/runnerway/course/model/service/UserCourseServiceImpl.java b/BackEnd/src/main/java/chuchu/runnerway/course/model/service/UserCourseServiceImpl.java index bd4ba1cb..cb30062d 100644 --- a/BackEnd/src/main/java/chuchu/runnerway/course/model/service/UserCourseServiceImpl.java +++ b/BackEnd/src/main/java/chuchu/runnerway/course/model/service/UserCourseServiceImpl.java @@ -47,6 +47,7 @@ public class UserCourseServiceImpl implements UserCourseService { public List findAllUserCourse(double lat, double lng) { String h3Index = h3.geoToH3Address(lat, lng, resolution); List courses = userCourseRepository.findAll(h3Index); +// if(courses.isEmpty()) return null; return courses.stream() .map(course -> { // Course -> UserListResponseDto 변환 @@ -69,8 +70,9 @@ public List findAllUserCourse(double lat, double lng) { @Override @Cacheable(value = "userCourseCache", key = "#courseId", unless = "#result == null") public UserDetailResponseDto getUserCourse(Long courseId) { - Course course = userCourseRepository.findById(courseId) - .orElseThrow(NoSuchElementException::new); + Course course = userCourseRepository.findById(courseId).orElse(null); + if(course == null) return null; + UserDetailResponseDto dto = mapper.map(course, UserDetailResponseDto.class); dto.setNickname(course.getMember().getNickname()); dto.setMemberId(course.getMember().getMemberId()); diff --git a/BackEnd/src/main/java/chuchu/runnerway/ranking/controller/RankingController.java b/BackEnd/src/main/java/chuchu/runnerway/ranking/controller/RankingController.java index ee5e0558..7cdbc6eb 100644 --- a/BackEnd/src/main/java/chuchu/runnerway/ranking/controller/RankingController.java +++ b/BackEnd/src/main/java/chuchu/runnerway/ranking/controller/RankingController.java @@ -36,7 +36,7 @@ public class RankingController { }) public ResponseEntity getLankerLog(@PathVariable("rankId") Long rankId){ String path = rankingService.getRankerLog(rankId); - + if(path == null) return ResponseEntity.status(404).build(); return ResponseEntity.status(200).body(path); } diff --git a/BackEnd/src/main/java/chuchu/runnerway/ranking/model/service/RankingServiceImpl.java b/BackEnd/src/main/java/chuchu/runnerway/ranking/model/service/RankingServiceImpl.java index 71c53685..27579edf 100644 --- a/BackEnd/src/main/java/chuchu/runnerway/ranking/model/service/RankingServiceImpl.java +++ b/BackEnd/src/main/java/chuchu/runnerway/ranking/model/service/RankingServiceImpl.java @@ -31,8 +31,8 @@ public class RankingServiceImpl implements RankingService{ @Override public String getRankerLog(Long rankId) { - Ranking ranking = rankingRepository.findByRankId(rankId) - .orElseThrow(NoSuchElementException::new); + Ranking ranking = rankingRepository.findByRankId(rankId).orElse(null); + if(ranking == null) return null; return ranking.getPath(); diff --git a/BackEnd/src/main/java/chuchu/runnerway/runningRecord/controller/RunningController.java b/BackEnd/src/main/java/chuchu/runnerway/runningRecord/controller/RunningController.java index 6407b3a1..2328c5af 100644 --- a/BackEnd/src/main/java/chuchu/runnerway/runningRecord/controller/RunningController.java +++ b/BackEnd/src/main/java/chuchu/runnerway/runningRecord/controller/RunningController.java @@ -42,6 +42,7 @@ public ResponseEntity getRunningRecords( @Valid @ModelAttribute RecordDateRequestDto requestDto) { List records = runningRecordService.getRecords(requestDto.getYear(), requestDto.getMonth(), requestDto.getDay()); + if(records == null) return ResponseEntity.status(204).build(); return ResponseEntity.status(200).body(records); } @@ -56,7 +57,7 @@ public ResponseEntity getRunningRecords( @GetMapping("/detail/{recordId}") public ResponseEntity getRunningRecord(@PathVariable("recordId") Long recordId){ RecordDetailResponseDto record = runningRecordService.getRecord(recordId); - + if(record == null) return ResponseEntity.status(404).body("데이터가 존재하지 않습니다."); return ResponseEntity.status(200).body(record); } diff --git a/BackEnd/src/main/java/chuchu/runnerway/runningRecord/dto/response/RecordMonthData.java b/BackEnd/src/main/java/chuchu/runnerway/runningRecord/dto/response/RecordMonthData.java index d7791bde..963b5230 100644 --- a/BackEnd/src/main/java/chuchu/runnerway/runningRecord/dto/response/RecordMonthData.java +++ b/BackEnd/src/main/java/chuchu/runnerway/runningRecord/dto/response/RecordMonthData.java @@ -3,10 +3,11 @@ import lombok.Data; import java.sql.Time; +import java.time.LocalDateTime; @Data public class RecordMonthData { - public RecordMonthData(double totalDistance, double averageFace, Time totalScore, double totalCalorie) { + public RecordMonthData(double totalDistance, double averageFace, String totalScore, double totalCalorie) { this.totalDistance = totalDistance; this.averageFace = averageFace; this.totalScore = totalScore; @@ -15,6 +16,6 @@ public RecordMonthData(double totalDistance, double averageFace, Time totalScore private double totalDistance; private double averageFace; - private Time totalScore; + private String totalScore; private double totalCalorie; } diff --git a/BackEnd/src/main/java/chuchu/runnerway/runningRecord/model/repository/RunningRecordRepository.java b/BackEnd/src/main/java/chuchu/runnerway/runningRecord/model/repository/RunningRecordRepository.java index 557c115a..608c1b48 100644 --- a/BackEnd/src/main/java/chuchu/runnerway/runningRecord/model/repository/RunningRecordRepository.java +++ b/BackEnd/src/main/java/chuchu/runnerway/runningRecord/model/repository/RunningRecordRepository.java @@ -31,7 +31,7 @@ List findByDate( // Optional getRecordMonthData(@Param("year") int year, @Param("month") int month); @Query(value = "SELECT SUM(rr.running_distance) AS totalDistance, " + "AVG(rr.average_face) AS averageFace, " + - "SEC_TO_TIME(SUM(TIME_TO_SEC(rr.score))) AS totalScore, " + + "SUM(TIME_TO_SEC(rr.score)) AS totalScore, " + "SUM(rr.calorie) AS totalCalorie " + "FROM running_record rr " + "WHERE YEAR(rr.start_date) = :year " + diff --git a/BackEnd/src/main/java/chuchu/runnerway/runningRecord/model/service/RunningRecordServiceImpl.java b/BackEnd/src/main/java/chuchu/runnerway/runningRecord/model/service/RunningRecordServiceImpl.java index 676df9a1..e03a92e2 100644 --- a/BackEnd/src/main/java/chuchu/runnerway/runningRecord/model/service/RunningRecordServiceImpl.java +++ b/BackEnd/src/main/java/chuchu/runnerway/runningRecord/model/service/RunningRecordServiceImpl.java @@ -24,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional; import java.sql.Time; +import java.time.LocalDateTime; import java.time.LocalTime; import java.util.*; @@ -45,7 +46,7 @@ public class RunningRecordServiceImpl implements RunningRecordService{ public List getRecords(int year, int month, Integer day) { List runningRecords = runningRecordRepository.findByDate(year, month, day); if(runningRecords.isEmpty()) { - throw new NoSuchElementException(); + return null; } return runningRecordMapper.toRecordResponseDtoList(runningRecords); @@ -55,7 +56,8 @@ public List getRecords(int year, int month, Integer day) { @Override public RecordDetailResponseDto getRecord(Long recordId) { RunningRecord runningRecord = runningRecordRepository.findById(recordId) - .orElseThrow(NoSuchElementException::new); + .orElse(null); + if(runningRecord == null) return null; return runningRecordMapper.toRecordDetailResponseDto(runningRecord); @@ -65,10 +67,24 @@ public RecordDetailResponseDto getRecord(Long recordId) { public RecordMonthData getAnalysisRecord(int year, int month) { Map result = runningRecordRepository.getRecordMonthData(year, month) .orElseThrow(NoSuchElementException::new); + if(result.get("totalScore") == null){ + return new RecordMonthData( + 0, + 0, + "00:00:00", + 0 + ); + } + + long time = ((Number) result.get("totalScore")).longValue(); + long hours = time / 3600; + long minutes = (time % 3600) / 60; + long seconds = time % 60; + String formattedTotalScore = String.format("%02d:%02d:%02d", hours, minutes, seconds); return new RecordMonthData( ((Number) result.get("totalDistance")).doubleValue(), ((Number) result.get("averageFace")).doubleValue(), - (Time) result.get("totalScore"), + formattedTotalScore, ((Number) result.get("totalCalorie")).doubleValue() ); }