Skip to content

Commit f2e5088

Browse files
committed
feat(community): communityBoard Repository 구조 변경 및 조회 기능 추가
1 parent 9ef829e commit f2e5088

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.somemore.community.repository;
2+
3+
import com.somemore.community.domain.CommunityBoard;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
6+
public interface CommunityBoardJpaRepository extends JpaRepository<CommunityBoard, Long> {
7+
}
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
package com.somemore.community.repository;
22

33
import com.somemore.community.domain.CommunityBoard;
4-
import org.springframework.data.jpa.repository.JpaRepository;
54

6-
public interface CommunityBoardRepository extends JpaRepository<CommunityBoard, Long> {
5+
import java.util.List;
6+
import java.util.Optional;
7+
import java.util.UUID;
78

9+
public interface CommunityBoardRepository {
10+
CommunityBoard save(CommunityBoard communityBoard);
11+
Optional<CommunityBoard> findById(Long id);
12+
List<CommunityBoard> getCommunityBoards();
13+
List<CommunityBoard> getCommunityBoardsByWriterId(UUID writerId);
14+
void deleteAllInBatch();
815
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.somemore.community.repository;
2+
3+
import com.querydsl.jpa.impl.JPAQueryFactory;
4+
import com.somemore.community.domain.CommunityBoard;
5+
import com.somemore.community.domain.QCommunityBoard;
6+
import lombok.RequiredArgsConstructor;
7+
import org.springframework.stereotype.Repository;
8+
9+
import java.util.List;
10+
import java.util.Optional;
11+
import java.util.UUID;
12+
13+
@RequiredArgsConstructor
14+
@Repository
15+
public class CommunityRepositoryImpl implements CommunityBoardRepository {
16+
17+
private final JPAQueryFactory queryFactory;
18+
private final CommunityBoardJpaRepository communityBoardJpaRepository;
19+
20+
@Override
21+
public CommunityBoard save(CommunityBoard communityBoard) {
22+
return communityBoardJpaRepository.save(communityBoard);
23+
}
24+
25+
@Override
26+
public Optional<CommunityBoard> findById(Long id) {
27+
return communityBoardJpaRepository.findById(id);
28+
}
29+
30+
@Override
31+
public List<CommunityBoard> getCommunityBoards() {
32+
QCommunityBoard communityBoard = QCommunityBoard.communityBoard;
33+
34+
return queryFactory
35+
.selectFrom(communityBoard)
36+
.where(communityBoard.deleted.eq(false))
37+
.orderBy(communityBoard.createdAt.desc())
38+
.fetch();
39+
}
40+
41+
@Override
42+
public List<CommunityBoard> getCommunityBoardsByWriterId(UUID writerId) {
43+
QCommunityBoard communityBoard = QCommunityBoard.communityBoard;
44+
45+
return queryFactory
46+
.selectFrom(communityBoard)
47+
.where(communityBoard.writerId.eq(writerId)
48+
.and(communityBoard.deleted.eq(false))
49+
)
50+
.orderBy(communityBoard.createdAt.desc())
51+
.fetch();
52+
}
53+
54+
@Override
55+
public void deleteAllInBatch() {
56+
communityBoardJpaRepository.deleteAllInBatch();
57+
}
58+
}

0 commit comments

Comments
 (0)