Skip to content

Commit

Permalink
fix: record 기록 순위 예외 처리 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
82everywin committed Mar 2, 2025
1 parent c9631bc commit e487d92
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public ResponseEntity<CommonResponse<List<RecentRecordResDto>>> viewRandomRecord

@Operation(summary = "기록 작성 진행률 조회 (순위 조회)", description = "해당 그룹의 독서 진행률을 조회합니다.")
@GetMapping("/progress")
public List<RecordProgressChartDto> getGroupReadingProgress(@RequestParam(name = "groupId")Long groupId) {
return recordService.getProgressChart(groupId);
public ResponseEntity<CommonResponse<List<RecordProgressChartDto>>> getGroupReadingProgress(@RequestParam(name = "groupId")Long groupId) {
return ResponseEntity.status(VIEW_RECORD.getStatus())
.body(CommonResponse.from(VIEW_RECORD.getMessage(), recordService.getProgressChart(groupId)));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.bookmile.backend.domain.record.entity.Record;
import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand All @@ -24,5 +26,5 @@ public interface RecordRepository extends JpaRepository<Record, Long> {
" WHERE r2.usergroup_id = r.usergroup_id " +
")",
nativeQuery = true)
Record findLatestRecordByUserAndGroup(@Param("userGroupId") Long userGroupId);
Optional<Record> findLatestRecordByUserAndGroup(@Param("userGroupId") Long userGroupId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ public List<RecentRecordResDto> viewRandomRecord(Long groupId) {
public List<RecordProgressChartDto> getProgressChart(Long groupId) {
// groupId로 해당 그룹 존재
List<UserGroup> userGroups = userGroupRepository.findByGroupId(groupId);
if( userGroups.isEmpty()){
throw new CustomException(GROUP_NOT_FOUND);
}
for(UserGroup userGroup : userGroups) {
log.info("userGroup 리스트 {}- ID : {}", userGroup.getId(), userGroup.getUser().getId());
}
Expand All @@ -146,7 +149,10 @@ public List<RecordProgressChartDto> getProgressChart(Long groupId) {

// 개인 진행률 계산
private double calculateReadingProgress(Long userGroupId) {
Record record = recordRepository.findLatestRecordByUserAndGroup(userGroupId);
Record record = recordRepository.findLatestRecordByUserAndGroup(userGroupId).orElseThrow(
() -> new CustomException(RECORD_NOT_FOUND)
);

log.info("개인 진행률 계산 : record - {}, 현재 페이지 {}", record.getId(), record.getCurrentPage());


Expand Down

0 comments on commit e487d92

Please sign in to comment.