-
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
Changes from 9 commits
c309c6a
52dc2e6
09d5f0b
4180256
f726c0d
cf728c2
a043677
eb22bfd
653033b
c8ccff0
99ad625
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.somemore.community.domain; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public class CommunityBoardWithNickname { | ||
| private final CommunityBoard communityBoard; | ||
| private final String writerNickname; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,26 +5,27 @@ | |
| import com.somemore.community.domain.CommunityBoard; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.UUID; | ||
|
|
||
| @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
| public record CommunityBoardGetDetailResponseDto( | ||
| Long id, | ||
| UUID writerId, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. volunteerId보다 writerId가 좋을까요? 사실 저도 모르겠어요
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 혹시나 추후에 센터도 작성 가능하게 될 걸 고려해서 바꾸지 않았는데 volunteerId로 바꾸는게 나을까요?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이것도 자유롭게 결정해주셔도 될 것 같아요 |
||
| String title, | ||
| String content, | ||
| String imageUrl, | ||
| LocalDateTime createdAt, | ||
| LocalDateTime updatedAt, | ||
| WriterDetailDto writerDetailDto | ||
| LocalDateTime updatedAt | ||
| ) { | ||
| public static CommunityBoardGetDetailResponseDto fromEntity(CommunityBoard board, WriterDetailDto writer) { | ||
| public static CommunityBoardGetDetailResponseDto fromEntity(CommunityBoard board) { | ||
| return new CommunityBoardGetDetailResponseDto( | ||
| board.getId(), | ||
| board.getWriterId(), | ||
| board.getTitle(), | ||
| board.getContent(), | ||
| board.getImgUrl(), | ||
| board.getCreatedAt(), | ||
| board.getUpdatedAt(), | ||
| writer | ||
| board.getUpdatedAt() | ||
| ); | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| package com.somemore.community.repository; | ||
|
|
||
| import com.querydsl.core.types.Projections; | ||
| import com.querydsl.jpa.impl.JPAQueryFactory; | ||
| import com.somemore.community.domain.CommunityBoard; | ||
| import com.somemore.community.domain.CommunityBoardWithNickname; | ||
| import com.somemore.community.domain.QCommunityBoard; | ||
| import com.somemore.volunteer.domain.QVolunteer; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
|
|
@@ -34,22 +37,32 @@ public Optional<CommunityBoard> findById(Long id) { | |
| } | ||
|
|
||
| @Override | ||
| public List<CommunityBoard> getCommunityBoards() { | ||
| public List<CommunityBoardWithNickname> getCommunityBoards() { | ||
| QCommunityBoard communityBoard = QCommunityBoard.communityBoard; | ||
| QVolunteer volunteer = QVolunteer.volunteer; | ||
|
|
||
| return queryFactory | ||
| .selectFrom(communityBoard) | ||
| .select(Projections.constructor(CommunityBoardWithNickname.class, | ||
| communityBoard, | ||
| volunteer.nickname)) | ||
ayoung-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .from(communityBoard) | ||
| .join(volunteer).on(communityBoard.writerId.eq(volunteer.id)) | ||
| .where(communityBoard.deleted.eq(false)) | ||
| .orderBy(communityBoard.createdAt.desc()) | ||
| .fetch(); | ||
| } | ||
|
|
||
| @Override | ||
| public List<CommunityBoard> findByWriterId(UUID writerId) { | ||
| public List<CommunityBoardWithNickname> findByWriterId(UUID writerId) { | ||
| QCommunityBoard communityBoard = QCommunityBoard.communityBoard; | ||
| QVolunteer volunteer = QVolunteer.volunteer; | ||
|
|
||
| return queryFactory | ||
| .selectFrom(communityBoard) | ||
| .select(Projections.constructor(CommunityBoardWithNickname.class, | ||
| communityBoard, | ||
| volunteer.nickname)) | ||
| .from(communityBoard) | ||
| .join(volunteer).on(communityBoard.writerId.eq(volunteer.id)) | ||
| .where(communityBoard.writerId.eq(writerId) | ||
| .and(communityBoard.deleted.eq(false)) | ||
| ) | ||
|
|
||
This file was deleted.
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.
레코드는 어떨까요?
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.
그리고 이것 자체가 DTO 같은데 추가로 클래스를 만들지 않았다는 PR 포인트가 이해가 잘 안되는데 추가적인 설명을 부탁드리고 싶어요!
Uh oh!
There was an error while loading. Please reload this page.
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.
추가한 클래스는 repository-service에서 사용하는 엔티티? 개념으로 생각했습니다.
그래서 다른 DTO들과는 차이점이 있다고 생각해서 구분지어 말하려했는데 명확하지 않았던 거 같네요
네이밍을 다르게 해야할 거 같은데 뭐가 좋을지 고민이 되네요..
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.
CommunityBoardView를 추천해주는데
다들 어떠신지 이거 보시면 남겨주시면 감사하겠습니다
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.
저도 찾아봤는데 마땅히 끌리는게 없어서 아영 님 진행하는대로 따라가게씁니다
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.
repository-service에서 사용하는 엔티티라면 영속성 레이어의 엔티티라고 보면 되는걸까요?
그럼 서비스로 넘길때 뭔가 비즈니스 레이어에서 사용하는 형태로 변형시켜줘야 되는지도 궁금해요
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.
DB 테이블이랑 직접 매핑되지 않기도 하고 객체 같은 느낌이라 영속성 엔티티라고 보긴 어려울 거 같아요...
그럼.. repository-service단에서 사용하는 DTO라고 하는게 맞을까요?
지금은 기존 entity-dto 처럼 서비스에서 dto로 변환하고 있습니다!
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.
저는 지금 괜찮아보입니다.!
서로다른 두가지 테이블에 있는 데이터를 묶어주기 위한 엔티티로 보이네요