Skip to content

Commit

Permalink
hotfix: 상태코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
korno1 committed Oct 1, 2024
1 parent 1239e40 commit 3d3e9c9
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class OfficialCourseController {
})
public ResponseEntity<?> findAllOfficialCourses(@RequestParam double lat, @RequestParam double lng) {
List<RecommendationDto> courses = officialCourseService.findAllOfiicialCourse(lat, lng);
if(courses == null) return ResponseEntity.status(204).build();
return ResponseEntity.ok(courses);
}

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class UserCourseController {
})
public ResponseEntity<?> selectUserCourseList(@RequestParam Double lat, @RequestParam Double lng) {
List<UserListResponseDto> userCourseList = userCourseService.findAllUserCourse(lat, lng);
if(userCourseList.isEmpty()) return ResponseEntity.status(204).build();
return ResponseEntity.status(HttpStatus.OK).body(userCourseList);
}

Expand All @@ -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);
}

Expand All @@ -62,6 +64,7 @@ public ResponseEntity<?> getUserCourse(@PathVariable("courseId") Long courseId)
})
public ResponseEntity<?> selectPopularAllList(@RequestParam Double lat, @RequestParam Double lng) {
List<UserListResponseDto> userCourseList = userCourseService.findPopularAllUserCourse(lat, lng);
if(userCourseList.isEmpty()) return ResponseEntity.status(204).build();
return ResponseEntity.ok(userCourseList);
}

Expand All @@ -76,6 +79,7 @@ public ResponseEntity<?> selectPopularAllList(@RequestParam Double lat, @Request
})
public ResponseEntity<?> selectPopularLatelyList(@RequestParam Double lat, @RequestParam Double lng) {
List<UserListResponseDto> userCourseList = userCourseService.findPopularLatelyUserCourse(lat, lng);
if(userCourseList.isEmpty()) return ResponseEntity.status(204).build();
return ResponseEntity.ok(userCourseList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class OfficialCourseServiceImpl implements OfficialCourseService{
@Override
public List<RecommendationDto> findAllOfiicialCourse(double lat, double lng) {
List<RecommendationDto> courses = getRecommendation(lat, lng);
if(courses.isEmpty()) throw new NoSuchElementException();
if(courses.isEmpty()) return null;
for(RecommendationDto course : courses) {
Optional<CourseImage> courseImage = courseImageRepositoryPrimaryKey.findById(course.getCourseId());
courseImage.ifPresent(image -> course.setCourseImage(courseMapper.toCourseImageDto(image)));
Expand All @@ -57,10 +57,10 @@ public List<RecommendationDto> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class UserCourseServiceImpl implements UserCourseService {
public List<UserListResponseDto> findAllUserCourse(double lat, double lng) {
String h3Index = h3.geoToH3Address(lat, lng, resolution);
List<Course> courses = userCourseRepository.findAll(h3Index);
// if(courses.isEmpty()) return null;
return courses.stream()
.map(course -> {
// Course -> UserListResponseDto 변환
Expand All @@ -69,8 +70,9 @@ public List<UserListResponseDto> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class RankingController {
})
public ResponseEntity<String> getLankerLog(@PathVariable("rankId") Long rankId){
String path = rankingService.getRankerLog(rankId);

if(path == null) return ResponseEntity.status(404).build();
return ResponseEntity.status(200).body(path);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public ResponseEntity<?> getRunningRecords(
@Valid @ModelAttribute RecordDateRequestDto requestDto) {

List<RecordResponseDto> records = runningRecordService.getRecords(requestDto.getYear(), requestDto.getMonth(), requestDto.getDay());
if(records == null) return ResponseEntity.status(204).build();
return ResponseEntity.status(200).body(records);
}

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ List<RunningRecord> findByDate(
// Optional<RecordMonthData> 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 " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -45,7 +46,7 @@ public class RunningRecordServiceImpl implements RunningRecordService{
public List<RecordResponseDto> getRecords(int year, int month, Integer day) {
List<RunningRecord> runningRecords = runningRecordRepository.findByDate(year, month, day);
if(runningRecords.isEmpty()) {
throw new NoSuchElementException();
return null;
}

return runningRecordMapper.toRecordResponseDtoList(runningRecords);
Expand All @@ -55,7 +56,8 @@ public List<RecordResponseDto> 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);
Expand All @@ -65,10 +67,24 @@ public RecordDetailResponseDto getRecord(Long recordId) {
public RecordMonthData getAnalysisRecord(int year, int month) {
Map<String, Object> 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()
);
}
Expand Down

0 comments on commit 3d3e9c9

Please sign in to comment.