Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
run: chmod +x ./gradlew

- name: Build and Test with Gradle
run: ./gradlew bootJar -Pprofile=dev
run: ./gradlew bootJar -Pprofile=dev --info



3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ dependencies {
implementation 'org.opensearch.client:spring-data-opensearch:1.3.0'
implementation 'org.opensearch.client:opensearch-java:2.9.1'

// mybatis
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.4'

compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'
Expand Down
37 changes: 37 additions & 0 deletions src/docs/asciidoc/api/mypage/comment-get.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[[Comment-Get]]
== 내가 썼어요 댓글/답글 조회 API(GET: /devdevdev/api/v1/mypage/comments)

* 회원이 작성한 댓글/답글을 조회한다.
* 최초 요청시 pickCommentId, techCommentId 는 가장 큰 숫자 값을 요청해야 합니다.

=== 정상 요청/응답

==== HTTP Request

include::{snippets}/mypage-comments/http-request.adoc[]

==== HTTP Request Header Fields

include::{snippets}/mypage-comments/request-headers.adoc[]

==== HTTP Request Query Parameters Fields

include::{snippets}/mypage-comments/query-parameters.adoc[]

==== HTTP Response

include::{snippets}/mypage-comments/http-response.adoc[]

==== HTTP Response Fields

include::{snippets}/mypage-comments/response-fields.adoc[]

=== 예외

==== HTTP Response

* `익명 회원은 사용할 수 없는 기능 입니다.`: 익명 회원인 경우
* `회원을 찾을 수 없습니다.`: 회원이 존재하지 않는 경우
* `유효하지 않은 회원 입니다.`: 회원이 유효하지 않은 경우

include::{snippets}/mypage-comments-member-exception/response-body.adoc[]
1 change: 1 addition & 0 deletions src/docs/asciidoc/api/mypage/mypage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ include::mypick-main.adoc[]
include::exit-member.adoc[]
include::exit-survey.adoc[]
include::record-exit-survey.adoc[]
include::comment-get.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class Pick extends BasicTime {
private List<String> embeddings;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
@JoinColumn(name = "member_id", nullable = false)
private Member member;

@OneToMany(mappedBy = "pick")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dreamypatisiel.devdevdev.domain.entity;

import com.dreamypatisiel.devdevdev.domain.entity.embedded.Count;
import com.dreamypatisiel.devdevdev.domain.entity.embedded.Title;
import com.dreamypatisiel.devdevdev.domain.entity.embedded.Url;
import com.dreamypatisiel.devdevdev.domain.policy.TechArticlePopularScorePolicy;
import com.dreamypatisiel.devdevdev.elastic.domain.document.ElasticTechArticle;
Expand Down Expand Up @@ -35,6 +36,8 @@ public class TechArticle extends BasicTime {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private Title title;

@Embedded
@AttributeOverride(name = "count",
column = @Column(name = "view_total_count")
Expand Down Expand Up @@ -79,8 +82,10 @@ public class TechArticle extends BasicTime {
private List<TechArticleRecommend> recommends = new ArrayList<>();

@Builder
private TechArticle(Count viewTotalCount, Count recommendTotalCount, Count commentTotalCount, Count popularScore,
private TechArticle(Title title, Count viewTotalCount, Count recommendTotalCount, Count commentTotalCount,
Count popularScore,
Url techArticleUrl, Company company, String elasticId) {
this.title = title;
this.techArticleUrl = techArticleUrl;
this.viewTotalCount = viewTotalCount;
this.recommendTotalCount = recommendTotalCount;
Expand All @@ -92,6 +97,7 @@ private TechArticle(Count viewTotalCount, Count recommendTotalCount, Count comme

public static TechArticle createTechArticle(ElasticTechArticle elasticTechArticle, Company company) {
TechArticle techArticle = TechArticle.builder()
.title(new Title(elasticTechArticle.getTitle()))
.techArticleUrl(new Url(elasticTechArticle.getTechArticleUrl()))
.viewTotalCount(new Count(elasticTechArticle.getViewTotalCount()))
.recommendTotalCount(new Count(elasticTechArticle.getRecommendTotalCount()))
Expand All @@ -105,10 +111,11 @@ public static TechArticle createTechArticle(ElasticTechArticle elasticTechArticl
return techArticle;
}

public static TechArticle createTechArticle(Url techArticleUrl, Count viewTotalCount, Count recommendTotalCount,
Count commentTotalCount,
Count popularScore, String elasticId, Company company) {
public static TechArticle createTechArticle(Title title, Url techArticleUrl, Count viewTotalCount,
Count recommendTotalCount, Count commentTotalCount, Count popularScore,
String elasticId, Company company) {
return TechArticle.builder()
.title(title)
.techArticleUrl(techArticleUrl)
.viewTotalCount(viewTotalCount)
.recommendTotalCount(recommendTotalCount)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.dreamypatisiel.devdevdev.domain.repository.comment;

import com.dreamypatisiel.devdevdev.domain.repository.comment.mybatis.CommentMapper;
import com.dreamypatisiel.devdevdev.domain.repository.pick.PickCommentRepository;
import com.dreamypatisiel.devdevdev.domain.repository.techArticle.TechCommentRepository;
import com.dreamypatisiel.devdevdev.web.dto.SliceCustom;
import com.dreamypatisiel.devdevdev.web.dto.request.comment.MyWrittenCommentFilter;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class CommentRepository {

private final CommentMapper commentMapper;
private final PickCommentRepository pickCommentRepository;
private final TechCommentRepository techCommentRepository;

public SliceCustom<MyWrittenCommentDto> findMyWrittenCommentsByCursor(Long memberId,
Long pickCommentId,
Long techCommentId,
MyWrittenCommentFilter myWrittenCommentSort,
Pageable pageable) {

// 픽픽픽
if (MyWrittenCommentFilter.PICK.equals(myWrittenCommentSort)) {
return pickCommentRepository.findMyWrittenPickCommentsByCursor(memberId, pickCommentId, pageable);
}

// 기술블로그
if (MyWrittenCommentFilter.TECH_ARTICLE.equals(myWrittenCommentSort)) {
return techCommentRepository.findMyWrittenTechCommentsByCursor(memberId, techCommentId, pageable);
}

// 전체
// 회원이 작성한 픽픽픽, 기술블로그 댓글 조회
List<MyWrittenCommentDto> findMyWrittenComments = commentMapper.findByMemberIdAndPickCommentIdAndTechCommentIdOrderByCommentCreatedAtDesc(
memberId, pickCommentId, techCommentId, pageable.getPageSize());

// 다음 페이지 존재 여부
boolean hasNext = findMyWrittenComments.size() >= pageable.getPageSize();

// 회원이 작성한 댓글 총 갯수(삭제 미포함)
Long commentTotalCount = countByCreatedByIdAndDeletedAtIsNull(memberId);

return new SliceCustom<>(findMyWrittenComments, pageable, hasNext, commentTotalCount);
}

private Long countByCreatedByIdAndDeletedAtIsNull(Long createdById) {

// 회원이 작성한 픽픽픽 댓글 갯수(삭제 미포함)
Long pickCommentTotal = pickCommentRepository.countByCreatedByIdAndDeletedAtIsNull(createdById);

// 회원이 작성한 기술블로그 댓글 갯수(삭제 미포함)
Long techCommentTotal = techCommentRepository.countByCreatedByIdAndDeletedAtIsNull(createdById);

return pickCommentTotal + techCommentTotal;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.dreamypatisiel.devdevdev.domain.repository.comment;

import com.querydsl.core.annotations.QueryProjection;
import java.time.LocalDateTime;
import lombok.Data;

@Data
public class MyWrittenCommentDto {
private Long postId;
private String postTitle;
private Long commentId;
private String commentType;
private String commentContents;
private Long commentRecommendTotalCount;
private LocalDateTime commentCreatedAt;
private String pickOptionTitle;
private String pickOptionType;

@QueryProjection
public MyWrittenCommentDto(Long postId, String postTitle, Long commentId, String commentType,
String commentContents, Long commentRecommendTotalCount, LocalDateTime commentCreatedAt,
String pickOptionTitle, String pickOptionType) {
this.postId = postId;
this.postTitle = postTitle;
this.commentId = commentId;
this.commentType = commentType;
this.commentContents = commentContents;
this.commentRecommendTotalCount = commentRecommendTotalCount;
this.commentCreatedAt = commentCreatedAt;
this.pickOptionTitle = pickOptionTitle;
this.pickOptionType = pickOptionType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.dreamypatisiel.devdevdev.domain.repository.comment.mybatis;

import com.dreamypatisiel.devdevdev.domain.repository.comment.MyWrittenCommentDto;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

@Mapper
public interface CommentMapper {
List<MyWrittenCommentDto> findByMemberIdAndPickCommentIdAndTechCommentIdOrderByCommentCreatedAtDesc(
@Param("memberId") Long memberId,
@Param("pickCommentId") Long pickCommentId,
@Param("techCommentId") Long techCommentId,
@Param("limit") int limit);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ List<PickComment> findWithMemberWithPickWithPickVoteWithPickCommentRecommendsByO
Long countByOriginParentIdIn(Set<Long> pickIds);

Long countByPickIdAndOriginParentIsNullAndParentIsNullAndDeletedAtIsNull(Long pickId);

Long countByCreatedByIdAndDeletedAtIsNull(Long createdById);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.dreamypatisiel.devdevdev.domain.entity.PickComment;
import com.dreamypatisiel.devdevdev.domain.entity.enums.PickOptionType;
import com.dreamypatisiel.devdevdev.domain.repository.comment.MyWrittenCommentDto;
import com.dreamypatisiel.devdevdev.domain.repository.pick.PickCommentSort;
import com.dreamypatisiel.devdevdev.web.dto.SliceCustom;
import java.util.EnumSet;
import java.util.List;
import org.springframework.data.domain.Pageable;
Expand All @@ -17,4 +19,7 @@ Slice<PickComment> findOriginParentPickCommentsByCursor(Pageable pageable, Long

List<PickComment> findOriginParentPickCommentsByPickIdAndPickOptionTypeIn(Long pickId,
EnumSet<PickOptionType> pickOptionTypes);

SliceCustom<MyWrittenCommentDto> findMyWrittenPickCommentsByCursor(Long memberId, Long pickCommentId,
Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
import com.dreamypatisiel.devdevdev.domain.entity.PickComment;
import com.dreamypatisiel.devdevdev.domain.entity.enums.ContentStatus;
import com.dreamypatisiel.devdevdev.domain.entity.enums.PickOptionType;
import com.dreamypatisiel.devdevdev.domain.repository.comment.MyWrittenCommentDto;
import com.dreamypatisiel.devdevdev.domain.repository.comment.QMyWrittenCommentDto;
import com.dreamypatisiel.devdevdev.domain.repository.pick.PickCommentSort;
import com.dreamypatisiel.devdevdev.web.dto.SliceCustom;
import com.dreamypatisiel.devdevdev.web.dto.request.comment.MyWrittenCommentFilter;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.JPQLQueryFactory;
import java.util.Arrays;
import java.util.EnumSet;
Expand Down Expand Up @@ -83,6 +88,41 @@ public List<PickComment> findOriginParentPickCommentsByPickIdAndPickOptionTypeIn
.fetch();
}

@Override
public SliceCustom<MyWrittenCommentDto> findMyWrittenPickCommentsByCursor(Long memberId, Long pickCommentId,
Pageable pageable) {
// 회원이 작성한 픽픽픽 댓글 조회
List<MyWrittenCommentDto> contents = query.select(
new QMyWrittenCommentDto(pick.id,
pick.title.title,
pickComment.id,
Expressions.constant(MyWrittenCommentFilter.PICK.name()),
pickComment.contents.commentContents,
pickComment.recommendTotalCount.count,
pickComment.createdAt,
pickOption.title.title,
pickOption.pickOptionType.stringValue()))
.from(pickComment)
.leftJoin(pickComment.pickVote, pickVote)
.leftJoin(pickVote.pickOption, pickOption)
.innerJoin(pick).on(pick.id.eq(pickComment.pick.id).and(pick.contentStatus.eq(ContentStatus.APPROVAL)))
.where(pickComment.createdBy.id.eq(memberId)
.and(pickComment.deletedAt.isNull())
.and(pickComment.id.lt(pickCommentId)))
.orderBy(pickComment.createdAt.desc())
.limit(pageable.getPageSize())
.fetch();

// 회원이 작성한 픽픽픽 댓글 총 갯수(삭제 미포함)
long totalElements = query.select(pickComment.count())
.from(pickComment)
.where(pickComment.createdBy.id.eq(memberId)
.and(pickComment.deletedAt.isNull()))
.fetchCount();

return new SliceCustom<>(contents, pageable, hasNextPage(contents, pageable.getPageSize()), totalElements);
}

private static BooleanExpression pickOptionTypeIn(EnumSet<PickOptionType> pickOptionTypes) {
if (ObjectUtils.isEmpty(pickOptionTypes)) {
return null;
Expand Down Expand Up @@ -131,7 +171,7 @@ private OrderSpecifier<?> pickCommentSort(PickCommentSort pickCommentSort) {
.orElse(PickCommentSort.LATEST).getOrderSpecifierByPickCommentSort();
}

private boolean hasNextPage(List<PickComment> contents, int pageSize) {
private <T> boolean hasNextPage(List<T> contents, int pageSize) {
return contents.size() >= pageSize;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ List<TechComment> findWithMemberWithTechArticleByOriginParentIdInAndParentIsNotN
Set<Long> originParentIds);

Long countByTechArticleIdAndOriginParentIsNullAndParentIsNullAndDeletedAtIsNull(Long techArticleId);

Long countByCreatedByIdAndDeletedAtIsNull(Long createdById);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.dreamypatisiel.devdevdev.domain.repository.techArticle.custom;

import com.dreamypatisiel.devdevdev.domain.entity.TechComment;
import com.dreamypatisiel.devdevdev.domain.repository.comment.MyWrittenCommentDto;
import com.dreamypatisiel.devdevdev.domain.repository.techArticle.TechCommentSort;
import com.dreamypatisiel.devdevdev.web.dto.SliceCustom;
import java.util.List;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
Expand All @@ -11,4 +13,7 @@ Slice<TechComment> findOriginParentTechCommentsByCursor(Long techArticleId, Long
TechCommentSort techCommentSort, Pageable pageable);

List<TechComment> findOriginParentTechBestCommentsByTechArticleIdAndOffset(Long techArticleId, int size);

SliceCustom<MyWrittenCommentDto> findMyWrittenTechCommentsByCursor(Long memberId, Long techCommentId,
Pageable pageable);
}
Loading
Loading