Skip to content

Commit 6c410fa

Browse files
committed
test(community): CommunityBoard id로 조회 Service 및 Repository 수정
1 parent 394a2d2 commit 6c410fa

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/main/java/com/somemore/community/repository/CommunityBoardRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public interface CommunityBoardRepository {
1010
CommunityBoard save(CommunityBoard communityBoard);
11-
Optional<CommunityBoard> findById(Long id);
11+
Optional<CommunityBoard> getCommunityBoardWithId(Long id);
1212
List<CommunityBoard> getCommunityBoards();
1313
List<CommunityBoard> getCommunityBoardsByWriterId(UUID writerId);
1414
void deleteAllInBatch();

src/main/java/com/somemore/community/repository/CommunityRepositoryImpl.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ public CommunityBoard save(CommunityBoard communityBoard) {
2323
}
2424

2525
@Override
26-
public Optional<CommunityBoard> findById(Long id) {
27-
return communityBoardJpaRepository.findById(id);
26+
public Optional<CommunityBoard> getCommunityBoardWithId(Long id) {
27+
QCommunityBoard communityBoard = QCommunityBoard.communityBoard;
28+
29+
return Optional.ofNullable(queryFactory
30+
.selectFrom(communityBoard)
31+
.where(communityBoard.id.eq(id)
32+
.and(communityBoard.deleted.eq(false)))
33+
.fetchOne());
2834
}
2935

3036
@Override

src/main/java/com/somemore/community/service/query/CommunityBoardQueryService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public List<CommunityBoardGetResponseDto> getCommunityBoardsByWriterId(UUID writ
5353

5454
@Override
5555
public CommunityBoardGetDetailResponseDto getCommunityBoardDetail(Long id) {
56-
CommunityBoard board = communityBoardRepository.findById(id)
56+
CommunityBoard board = communityBoardRepository.getCommunityBoardWithId(id)
5757
.orElseThrow(() -> new BadRequestException(NOT_EXISTS_COMMUNITY_BOARD.getMessage()));
5858

5959
return CommunityBoardGetDetailResponseDto.fromEntity(board, getWriterDetail(board.getWriterId()));

0 commit comments

Comments
 (0)