Skip to content

Commit

Permalink
refactor: HistoryRepository 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
200516bb committed Oct 24, 2024
1 parent a400a52 commit c648f89
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,7 @@ public interface HistoryRepository extends JpaRepository<History, Long>, History

Page<History> findByMemberAndOriginPrayIdIsNotNull(Member member, Pageable pageable);


Optional<History> findByIdAndMember(Long historyId, Member member);

default History getHistoryByIdAndMember(Long historyId, Member member) {
return findByIdAndMember(historyId, member)
.orElseThrow(() -> new NotFoundException(ErrorStatus.HISTORY_NOT_FOUND_EXCEPTION));
}

default History getHistoryById(Long historyId) {
return findById(historyId)
.orElseThrow(() -> new NotFoundException(
ErrorStatus.HISTORY_NOT_FOUND_EXCEPTION
));
}
Optional<History> findById(Long historyId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public HistoryListResponseDto searchHistoryList(String username,
@Transactional(readOnly = true)
public HistoryDetailResponseDto getHistoryDetail(String username, Long historyId) {
Member member = memberRepository.getMemberByUserId(username);
History history = historyRepository.getHistoryById(historyId);
History history = getHistoryById(historyId);
if (history.getPrayType().equals(PrayType.SHARED)) {
Pray originPray = prayRepository.getPrayById(history.getOriginPrayId());
return HistoryDetailResponseDto.shared(history, originPray);
Expand All @@ -84,8 +84,19 @@ public void deleteHistory(History history) {
historyRepository.delete(history);
}

@Transactional
@Transactional(readOnly = true)
public History getHistoryByIdAndMember(Long historyId, Member member) {
return historyRepository.getHistoryByIdAndMember(historyId, member);
return historyRepository.findByIdAndMember(historyId, member)
.orElseThrow(() -> new NotFoundException(
ErrorStatus.HISTORY_NOT_FOUND_EXCEPTION
));
}

@Transactional(readOnly = true)
public History getHistoryById(Long historyId) {
return historyRepository.findById(historyId)
.orElseThrow(() -> new NotFoundException(
ErrorStatus.HISTORY_NOT_FOUND_EXCEPTION
));
}
}

0 comments on commit c648f89

Please sign in to comment.