File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed
main/java/com/somemore/community/repository/board Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -12,5 +12,9 @@ public interface CommunityBoardRepository {
1212 Optional <CommunityBoard > findById (Long id );
1313 List <CommunityBoardView > getCommunityBoards ();
1414 List <CommunityBoardView > findByWriterId (UUID writerId );
15+ boolean existsById (Long id );
16+ default boolean doesNotExistById (Long id ) {
17+ return !existsById (id );
18+ }
1519 void deleteAllInBatch ();
1620}
Original file line number Diff line number Diff line change @@ -52,6 +52,18 @@ public List<CommunityBoardView> findByWriterId(UUID writerId) {
5252 .fetch ();
5353 }
5454
55+ @ Override
56+ public boolean existsById (Long id ) {
57+ QCommunityBoard communityBoard = QCommunityBoard .communityBoard ;
58+
59+ return queryFactory
60+ .selectOne ()
61+ .from (communityBoard )
62+ .where (communityBoard .id .eq (id )
63+ .and (communityBoard .deleted .eq (false )))
64+ .fetchFirst () != null ;
65+ }
66+
5567 private JPAQuery <CommunityBoardView > getCommunityBoardsQuery () {
5668 QCommunityBoard communityBoard = QCommunityBoard .communityBoard ;
5769 QVolunteer volunteer = QVolunteer .volunteer ;
Original file line number Diff line number Diff line change @@ -158,4 +158,27 @@ void getCommunityBoardsByWriterId() {
158158 assertThat (communityBoards .getLast ().writerNickname ()).isEqualTo (volunteer .getNickname ());
159159 assertThat (communityBoards .getLast ().communityBoard ().getCreatedAt ()).isEqualTo (communityBoard1 .getCreatedAt ());
160160 }
161+
162+ @ DisplayName ("게시글 id로 게시글이 존재하는지 확인할 수 있다." )
163+ @ Test
164+ void existsById () {
165+
166+ //given
167+ UUID writerId = UUID .randomUUID ();
168+
169+ CommunityBoard communityBoard = CommunityBoard .builder ()
170+ .title ("테스트 커뮤니티 게시글 제목" )
171+ .content ("테스트 커뮤니티 게시글 내용" )
172+ .imgUrl ("http://community.example.com/123" )
173+ .writerId (writerId )
174+ .build ();
175+
176+ CommunityBoard savedComment = communityBoardRepository .save (communityBoard );
177+
178+ //when
179+ boolean isExist = communityBoardRepository .existsById (savedComment .getId ());
180+
181+ //then
182+ assertThat (isExist ).isTrue ();
183+ }
161184}
You can’t perform that action at this time.
0 commit comments