-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/19 커뮤니티 게시글 조회 기능 #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0c22359
test(community): communityBoard 조회 기능 테스트 작성
ayoung-dev fb2a309
test(center): center 이름 조회 기능 테스트 작성
ayoung-dev 946085f
test(volunteer): volunteer 닉네임 조회 기능 테스트 작성
ayoung-dev e28f14c
feat(community): communityBoard 조회 responseDto 생성
ayoung-dev 9ef829e
feat(community): communityBoard Query Usecase 및 Service 생성
ayoung-dev f2e5088
feat(community): communityBoard Repository 구조 변경 및 조회 기능 추가
ayoung-dev 59ae6cc
feat(center): 커뮤니티 조회에 사용할 ResponseDto 생성
ayoung-dev de43f60
feat(center): center Query Usecase 및 Service에 center 정보 조회 기능 추가
ayoung-dev b88355f
feat(center): center Repository 구조 변경 및 조회 기능 추가
ayoung-dev 76852a6
feat(volunteer): 커뮤니티 조회에 사용할 ResponseDto 생성
ayoung-dev 27f328d
feat(volunteer): volunteer Query Usecase 및 Service에 volunteer 정보 조회 기…
ayoung-dev 9006430
feat(volunteer): volunteer Repository 구조 변경 및 조회 기능 추가
ayoung-dev d625dae
feat(community): community 예외 메시지 추가
ayoung-dev c57f4dd
fix(community): sonarqube 이슈 사항 반영
ayoung-dev ce7ec93
refactor(community): 코드 리뷰 사항 반영
ayoung-dev d0dfeb2
Merge branch 'main' of https://github.com/prgrms-web-devcourse-final-…
ayoung-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/com/somemore/center/dto/response/CenterForCommunityResponseDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.somemore.center.dto.response; | ||
|
|
||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| import com.somemore.center.domain.Center; | ||
| import com.somemore.community.dto.response.WriterDetailDto; | ||
| import com.somemore.volunteer.domain.Tier; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
| public record CenterForCommunityResponseDto( | ||
| UUID id, | ||
| String name, | ||
| String imgUrl, | ||
| Tier tier | ||
| ) implements WriterDetailDto { | ||
|
|
||
| public static CenterForCommunityResponseDto fromEntity(Center center) { | ||
| return new CenterForCommunityResponseDto( | ||
| center.getId(), | ||
| center.getName(), | ||
| center.getImgUrl(), | ||
| null | ||
| ); | ||
| } | ||
| } | ||
|
|
||
12 changes: 12 additions & 0 deletions
12
src/main/java/com/somemore/center/repository/CenterJpaRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.somemore.center.repository; | ||
|
|
||
| import com.somemore.center.domain.Center; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
|
|
||
| public interface CenterJpaRepository extends JpaRepository<Center, Long> { | ||
| boolean existsById(UUID id); | ||
| Optional<Center> findCenterById(UUID id); | ||
| } |
9 changes: 4 additions & 5 deletions
9
src/main/java/com/somemore/center/repository/CenterRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,19 @@ | ||
| package com.somemore.center.repository; | ||
|
|
||
| import com.somemore.center.domain.Center; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
|
|
||
| @Repository | ||
| public interface CenterRepository extends JpaRepository<Center, UUID> { | ||
|
|
||
| public interface CenterRepository { | ||
| Center save(Center center); | ||
| boolean existsById(UUID id); | ||
|
|
||
| default boolean doesNotExistById(UUID id) { | ||
| return !existsById(id); | ||
| } | ||
|
|
||
| Optional<Center> findCenterById(UUID id); | ||
| String findNameById(UUID id); | ||
| void deleteAllInBatch(); | ||
| } |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/somemore/center/repository/CenterRepositoryImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package com.somemore.center.repository; | ||
|
|
||
| import com.querydsl.jpa.impl.JPAQueryFactory; | ||
| import com.somemore.center.domain.Center; | ||
| import com.somemore.center.domain.QCenter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Repository | ||
| public class CenterRepositoryImpl implements CenterRepository { | ||
|
|
||
| private final CenterJpaRepository centerJpaRepository; | ||
| private final JPAQueryFactory queryFactory; | ||
|
|
||
| @Override | ||
| public Center save(Center center) { | ||
| return centerJpaRepository.save(center); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean existsById(UUID id) { | ||
| return centerJpaRepository.existsById(id); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<Center> findCenterById(UUID id) { | ||
| return centerJpaRepository.findCenterById(id); | ||
| } | ||
|
|
||
| @Override | ||
| public String findNameById(UUID id) { | ||
| QCenter center = QCenter.center; | ||
|
|
||
| return queryFactory | ||
| .select(center.name) | ||
| .from(center) | ||
| .where(center.id.eq(id)) | ||
| .fetchOne(); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteAllInBatch() { | ||
| centerJpaRepository.deleteAllInBatch(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/com/somemore/community/dto/response/CommunityBoardGetDetailResponseDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package com.somemore.community.dto.response; | ||
|
|
||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| import com.somemore.community.domain.CommunityBoard; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
| public record CommunityBoardGetDetailResponseDto( | ||
| Long id, | ||
| String title, | ||
| String content, | ||
| String imageUrl, | ||
| LocalDateTime createdAt, | ||
| LocalDateTime updatedAt, | ||
| WriterDetailDto writerDetailDto | ||
| ) { | ||
| public static CommunityBoardGetDetailResponseDto fromEntity(CommunityBoard board, WriterDetailDto writer) { | ||
| return new CommunityBoardGetDetailResponseDto( | ||
| board.getId(), | ||
| board.getTitle(), | ||
| board.getContent(), | ||
| board.getImgUrl(), | ||
| board.getCreatedAt(), | ||
| board.getUpdatedAt(), | ||
| writer | ||
| ); | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/somemore/community/dto/response/CommunityBoardGetResponseDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.somemore.community.dto.response; | ||
|
|
||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| import com.somemore.community.domain.CommunityBoard; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @JsonNaming(SnakeCaseStrategy.class) | ||
| public record CommunityBoardGetResponseDto( | ||
| Long id, | ||
| String title, | ||
| String writerNickname, | ||
| LocalDateTime createdAt | ||
| ) { | ||
| public static CommunityBoardGetResponseDto fromEntity(CommunityBoard board, String writerNickname) { | ||
| return new CommunityBoardGetResponseDto( | ||
| board.getId(), | ||
| board.getTitle(), | ||
| writerNickname, | ||
| board.getCreatedAt() | ||
| ); | ||
| } | ||
| } | ||
|
|
12 changes: 12 additions & 0 deletions
12
src/main/java/com/somemore/community/dto/response/WriterDetailDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.somemore.community.dto.response; | ||
|
|
||
| import com.somemore.volunteer.domain.Tier; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public interface WriterDetailDto { | ||
| UUID id(); | ||
| String name(); | ||
| String imgUrl(); | ||
| Tier tier(); | ||
| } | ||
ayoung-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
7 changes: 7 additions & 0 deletions
7
src/main/java/com/somemore/community/repository/CommunityBoardJpaRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.somemore.community.repository; | ||
|
|
||
| import com.somemore.community.domain.CommunityBoard; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface CommunityBoardJpaRepository extends JpaRepository<CommunityBoard, Long> { | ||
| } |
11 changes: 9 additions & 2 deletions
11
src/main/java/com/somemore/community/repository/CommunityBoardRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,15 @@ | ||
| package com.somemore.community.repository; | ||
|
|
||
| import com.somemore.community.domain.CommunityBoard; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface CommunityBoardRepository extends JpaRepository<CommunityBoard, Long> { | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
|
|
||
| public interface CommunityBoardRepository { | ||
| CommunityBoard save(CommunityBoard communityBoard); | ||
| Optional<CommunityBoard> findById(Long id); | ||
| List<CommunityBoard> getCommunityBoards(); | ||
| List<CommunityBoard> getCommunityBoardsByWriterId(UUID writerId); | ||
| void deleteAllInBatch(); | ||
| } |
58 changes: 58 additions & 0 deletions
58
src/main/java/com/somemore/community/repository/CommunityRepositoryImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package com.somemore.community.repository; | ||
|
|
||
| import com.querydsl.jpa.impl.JPAQueryFactory; | ||
| import com.somemore.community.domain.CommunityBoard; | ||
| import com.somemore.community.domain.QCommunityBoard; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Repository | ||
| public class CommunityRepositoryImpl implements CommunityBoardRepository { | ||
|
|
||
| private final JPAQueryFactory queryFactory; | ||
| private final CommunityBoardJpaRepository communityBoardJpaRepository; | ||
|
|
||
| @Override | ||
| public CommunityBoard save(CommunityBoard communityBoard) { | ||
| return communityBoardJpaRepository.save(communityBoard); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<CommunityBoard> findById(Long id) { | ||
| return communityBoardJpaRepository.findById(id); | ||
| } | ||
|
|
||
| @Override | ||
| public List<CommunityBoard> getCommunityBoards() { | ||
| QCommunityBoard communityBoard = QCommunityBoard.communityBoard; | ||
|
|
||
| return queryFactory | ||
| .selectFrom(communityBoard) | ||
| .where(communityBoard.deleted.eq(false)) | ||
| .orderBy(communityBoard.createdAt.desc()) | ||
| .fetch(); | ||
| } | ||
|
|
||
| @Override | ||
| public List<CommunityBoard> getCommunityBoardsByWriterId(UUID writerId) { | ||
| QCommunityBoard communityBoard = QCommunityBoard.communityBoard; | ||
|
|
||
| return queryFactory | ||
| .selectFrom(communityBoard) | ||
| .where(communityBoard.writerId.eq(writerId) | ||
| .and(communityBoard.deleted.eq(false)) | ||
| ) | ||
| .orderBy(communityBoard.createdAt.desc()) | ||
| .fetch(); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteAllInBatch() { | ||
| communityBoardJpaRepository.deleteAllInBatch(); | ||
| } | ||
| } |
82 changes: 82 additions & 0 deletions
82
src/main/java/com/somemore/community/service/query/CommunityBoardQueryService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package com.somemore.community.service.query; | ||
|
|
||
| import com.somemore.center.usecase.query.CenterQueryUseCase; | ||
| import com.somemore.community.domain.CommunityBoard; | ||
| import com.somemore.community.dto.response.CommunityBoardGetDetailResponseDto; | ||
| import com.somemore.community.dto.response.CommunityBoardGetResponseDto; | ||
| import com.somemore.community.dto.response.WriterDetailDto; | ||
| import com.somemore.community.repository.CommunityBoardRepository; | ||
| import com.somemore.community.usecase.query.CommunityBoardQueryUseCase; | ||
| import com.somemore.global.exception.BadRequestException; | ||
| import com.somemore.volunteer.dto.response.VolunteerForCommunityResponseDto; | ||
| import com.somemore.volunteer.usecase.query.FindVolunteerIdUseCase; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_COMMUNITY_BOARD; | ||
|
|
||
|
|
||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| @Service | ||
| public class CommunityBoardQueryService implements CommunityBoardQueryUseCase { | ||
|
|
||
| private final CommunityBoardRepository communityBoardRepository; | ||
| private final CenterQueryUseCase centerQueryUseCase; | ||
| private final FindVolunteerIdUseCase findVolunteerIdUseCase; | ||
|
|
||
| @Override | ||
| public List<CommunityBoardGetResponseDto> getCommunityBoards() { | ||
| List<CommunityBoard> boards = communityBoardRepository.getCommunityBoards(); | ||
|
|
||
| return boards.stream() | ||
| .map(board -> { | ||
| String writerNickname = getWriterNickname(board.getWriterId()); | ||
| return CommunityBoardGetResponseDto.fromEntity(board, writerNickname); | ||
| }) | ||
| .toList(); | ||
| } | ||
|
|
||
| @Override | ||
| public List<CommunityBoardGetResponseDto> getCommunityBoardsByWriterId(UUID writerId) { | ||
| List<CommunityBoard> boards = communityBoardRepository.getCommunityBoardsByWriterId(writerId); | ||
| String writerNickname = getWriterNickname(writerId); | ||
|
|
||
| return boards.stream() | ||
| .map(board -> CommunityBoardGetResponseDto.fromEntity(board, writerNickname)) | ||
| .toList(); | ||
| } | ||
|
|
||
| @Override | ||
| public CommunityBoardGetDetailResponseDto getCommunityBoardDetail(Long id) { | ||
| CommunityBoard board = communityBoardRepository.findById(id) | ||
| .orElseThrow(() -> new BadRequestException(NOT_EXISTS_COMMUNITY_BOARD.getMessage())); | ||
|
|
||
| return CommunityBoardGetDetailResponseDto.fromEntity(board, getWriterDetail(board.getWriterId())); | ||
| } | ||
|
|
||
| private String getWriterNickname(UUID writerId) { | ||
| String nickname = findVolunteerIdUseCase.getNicknameById(writerId); | ||
|
|
||
| if (nickname == null) { | ||
| nickname = centerQueryUseCase.getNameById(writerId); | ||
| } | ||
|
|
||
| return nickname; | ||
| } | ||
|
|
||
| private WriterDetailDto getWriterDetail(UUID writerId) { | ||
| VolunteerForCommunityResponseDto volunteer = findVolunteerIdUseCase.getVolunteerDetailForCommunity(writerId); | ||
|
|
||
| if (volunteer == null) { | ||
| return centerQueryUseCase.getCenterDetailForCommunity(writerId); | ||
| } else { | ||
| return volunteer; | ||
| } | ||
| } | ||
| } | ||
ayoung-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.