-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor/60 커뮤니티 게시글 조회 기능 리팩토링 #64
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 all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c309c6a
feat(center): 커뮤니티에서 센터 프로필 조회 기능 및 테스트 삭제
ayoung-dev 52dc2e6
feat(volunteer): 커뮤니티에서 봉사자 프로필 조회 기능 및 테스트 삭제
ayoung-dev 09d5f0b
test(community): 커뮤니티 게시글 리스트 조회 테스트 수정
ayoung-dev 4180256
feat(community): 커뮤니티 게시글 리스트 조회 반환 class 생성
ayoung-dev f726c0d
feat(community): 커뮤니티 게시글 리스트 조회 반환값 및 queryDSL 변경
ayoung-dev cf728c2
feat(community): 커뮤니티 게시글 상세 조회 responseDto 수정
ayoung-dev a043677
feat(community): 커뮤니티 게시글 query service 수정
ayoung-dev eb22bfd
chore: 불필요한 import 제거
ayoung-dev 653033b
chore: 불필요한 import 제거
ayoung-dev c8ccff0
fix: CoummunityBoardView 이름 변경 및 코드 리뷰 반영
ayoung-dev 99ad625
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: 0 additions & 28 deletions
28
src/main/java/com/somemore/center/dto/response/CenterForCommunityResponseDto.java
This file was deleted.
Oops, something went wrong.
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
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
6 changes: 6 additions & 0 deletions
6
src/main/java/com/somemore/community/domain/CommunityBoardView.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,6 @@ | ||
| package com.somemore.community.domain; | ||
|
|
||
| public record CommunityBoardView( | ||
| CommunityBoard communityBoard, | ||
| String writerNickname) { | ||
| } |
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
12 changes: 0 additions & 12 deletions
12
src/main/java/com/somemore/community/dto/response/WriterDetailDto.java
This file was deleted.
Oops, something went wrong.
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
52 changes: 12 additions & 40 deletions
52
src/main/java/com/somemore/community/service/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 |
|---|---|---|
| @@ -1,79 +1,51 @@ | ||
| package com.somemore.community.service; | ||
|
|
||
| import com.somemore.center.usecase.query.CenterQueryUseCase; | ||
| import com.somemore.community.domain.CommunityBoard; | ||
| import com.somemore.community.domain.CommunityBoardView; | ||
| 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.CommunityBoardQueryUseCase; | ||
| import com.somemore.global.exception.BadRequestException; | ||
| import com.somemore.volunteer.dto.response.VolunteerForCommunityResponseDto; | ||
| import com.somemore.volunteer.usecase.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.function.Function; | ||
|
|
||
| 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(); | ||
| List<CommunityBoardView> boards = communityBoardRepository.getCommunityBoards(); | ||
| return mapEntitiesToDtos(boards, CommunityBoardGetResponseDto::fromEntity); | ||
| } | ||
|
|
||
| @Override | ||
| public List<CommunityBoardGetResponseDto> getCommunityBoardsByWriterId(UUID writerId) { | ||
| List<CommunityBoard> boards = communityBoardRepository.findByWriterId(writerId); | ||
| String writerNickname = getWriterNickname(writerId); | ||
|
|
||
| return boards.stream() | ||
| .map(board -> CommunityBoardGetResponseDto.fromEntity(board, writerNickname)) | ||
| .toList(); | ||
| List<CommunityBoardView> boards = communityBoardRepository.findByWriterId(writerId); | ||
| return mapEntitiesToDtos(boards, CommunityBoardGetResponseDto::fromEntity); | ||
| } | ||
|
|
||
| @Override | ||
| public CommunityBoardGetDetailResponseDto getCommunityBoardDetail(Long id) { | ||
| CommunityBoard board = communityBoardRepository.findById(id) | ||
ayoung-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .orElseThrow(() -> new BadRequestException(NOT_EXISTS_COMMUNITY_BOARD.getMessage())); | ||
|
|
||
| return CommunityBoardGetDetailResponseDto.fromEntity(board, getWriterDetail(board.getWriterId())); | ||
| return CommunityBoardGetDetailResponseDto.fromEntity(board); | ||
| } | ||
|
|
||
| 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); | ||
| } | ||
| return volunteer; | ||
| private <T, R> List<R> mapEntitiesToDtos(List<T> entities, Function<T, R> mapper) { | ||
| return entities.stream() | ||
| .map(mapper) | ||
| .toList(); | ||
| } | ||
| } | ||
| } | ||
28 changes: 0 additions & 28 deletions
28
src/main/java/com/somemore/volunteer/dto/response/VolunteerForCommunityResponseDto.java
This file was deleted.
Oops, something went wrong.
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
volunteerId보다 writerId가 좋을까요? 사실 저도 모르겠어요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
혹시나 추후에 센터도 작성 가능하게 될 걸 고려해서 바꾸지 않았는데 volunteerId로 바꾸는게 나을까요?
저도 고민되어서 바꾸지 않고 그냥 뒀습니다..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이것도 자유롭게 결정해주셔도 될 것 같아요