-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from sharemindteam/feature/153-post-counselor…
…Side feat: 일대다 상담 미답변 질문 상담사 사이드 조회 구현
- Loading branch information
Showing
11 changed files
with
230 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/sharemind/comment/repository/CommentCustomRepository.java
This file contains 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,11 @@ | ||
package com.example.sharemind.comment.repository; | ||
|
||
import com.example.sharemind.comment.domain.Comment; | ||
import com.example.sharemind.counselor.domain.Counselor; | ||
|
||
import java.util.List; | ||
|
||
public interface CommentCustomRepository { | ||
|
||
List<Comment> findAllByCounselorAndIsActivatedIsTrue(Counselor counselor, Boolean filter, Long postId, int size); | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/com/example/sharemind/comment/repository/CommentCustomRepositoryImpl.java
This file contains 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,53 @@ | ||
package com.example.sharemind.comment.repository; | ||
|
||
import com.example.sharemind.comment.domain.Comment; | ||
import com.example.sharemind.comment.domain.QComment; | ||
import com.example.sharemind.counselor.domain.Counselor; | ||
import com.example.sharemind.post.content.PostStatus; | ||
import com.example.sharemind.post.domain.QPost; | ||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
public class CommentCustomRepositoryImpl implements CommentCustomRepository { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
private final QComment comment = QComment.comment; | ||
private final QPost post = comment.post; | ||
|
||
@Override | ||
public List<Comment> findAllByCounselorAndIsActivatedIsTrue(Counselor counselor, Boolean filter, Long postId, int size) { | ||
return jpaQueryFactory | ||
.selectFrom(comment) | ||
.where( | ||
commentByCounselor(counselor), | ||
filterCondition(filter), | ||
postIdCondition(postId) | ||
) | ||
.orderBy(post.postId.desc()) | ||
.limit(size) | ||
.fetch(); | ||
} | ||
|
||
private BooleanExpression commentByCounselor(Counselor counselor) { | ||
return comment.isActivated.isTrue() | ||
.and(QComment.comment.counselor.eq(counselor)); | ||
} | ||
|
||
private BooleanExpression filterCondition(Boolean filter) { | ||
if (Boolean.FALSE.equals(filter)) { | ||
return QPost.post.postStatus.eq(PostStatus.PROCEEDING); | ||
} | ||
return null; | ||
} | ||
|
||
private BooleanExpression postIdCondition(Long postId) { | ||
if (postId != null && postId != 0) { | ||
return QPost.post.postId.lt(postId); | ||
} | ||
return null; | ||
} | ||
} |
This file contains 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 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 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 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 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
74 changes: 74 additions & 0 deletions
74
src/main/java/com/example/sharemind/post/dto/response/PostGetCounselorListResponse.java
This file contains 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,74 @@ | ||
package com.example.sharemind.post.dto.response; | ||
|
||
import com.example.sharemind.comment.domain.Comment; | ||
import com.example.sharemind.global.utils.TimeUtil; | ||
import com.example.sharemind.post.domain.Post; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.persistence.Column; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class PostGetCounselorListResponse { | ||
|
||
@Schema(description = "일대다 질문 아이디") | ||
private final Long postId; | ||
|
||
@Schema(description = "제목") | ||
private final String title; | ||
|
||
@Schema(description = "상담 내용") | ||
private final String content; | ||
|
||
@Schema(description = "상담 카테고리") | ||
private final String consultCategory; | ||
|
||
@Schema(description = "공개/비공개 여부") | ||
private final Boolean isPublic; | ||
|
||
@Schema(description = "좋아요 수") | ||
private final Long totalLike; | ||
|
||
@Schema(description = "스크랩 수") | ||
private final Long totalScrap; | ||
|
||
@Schema(description = "답변 수") | ||
private final Long totalComment; | ||
|
||
@Column(name = "게시글 등록 일자") | ||
private final String publishedAt; | ||
|
||
@Column(name = "셰어 채택 여부") | ||
private final Boolean isChosen; | ||
|
||
@Builder | ||
public PostGetCounselorListResponse(Long postId, String title, String content, String consultCategory, | ||
Boolean isPublic, Long totalLike, Long totalScrap, Long totalComment, | ||
String publishedAt, Boolean isChosen) { | ||
this.postId = postId; | ||
this.title = title; | ||
this.content = content; | ||
this.consultCategory = consultCategory; | ||
this.isPublic = isPublic; | ||
this.totalLike = totalLike; | ||
this.totalScrap = totalScrap; | ||
this.totalComment = totalComment; | ||
this.publishedAt = publishedAt; | ||
this.isChosen = isChosen; | ||
} | ||
|
||
public static PostGetCounselorListResponse of(Post post, Comment comment) { | ||
return PostGetCounselorListResponse.builder() | ||
.postId(post.getPostId()) | ||
.title(post.getTitle()) | ||
.content(post.getContent()) | ||
.consultCategory(post.getConsultCategory().getDisplayName()) | ||
.isPublic(post.getIsPublic()) | ||
.totalLike(post.getTotalLike()) | ||
.totalScrap(post.getTotalScrap()) | ||
.totalComment(post.getTotalComment()) | ||
.publishedAt(TimeUtil.getUpdatedAt(post.getPublishedAt())) | ||
.isChosen(comment.getIsChosen()) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.