Skip to content

Commit

Permalink
Merge: Main Merge 34차 (#159)
Browse files Browse the repository at this point in the history
* 🐛 Hotfix: 댓글 수정 request dto 추가 (#149)

* Hotfix : 댓글 삭제 시 게시물의 댓글 수 차감 로직 수정 (#151)

* 🐛 Hotfix: 댓글 수정 request dto 추가

* 🐛 Hotfix: 댓글 삭제 시 게시물의 댓글 수 차감 로직 수정

* Feat: 프로필 이모지 설정 로직 구현 (#153)

* 🗃️ profile 속성의 Enum value ProfileEmoji 생성

* 🗃️ profile 속성 ProfileEmoji 설정

* ✨ Feat: 회원 가입 및 정보 수정에 프로필 이모지 설정 로직 추가

* Refactor : 모델 삭제 시 soft delete 구현 (#155)

* 🗃️ versionStatus 속성의 Enum value VersionStatus 생성

* 🗃️ versionStatus 속성 추가

* 👔 모델 삭제 시 sofe delete 구현

* 👔 모델 삭제 시 sofe delete 구현

* Fix: 타 사용자 자소서 조회 시 포인트 사용 로직 수정 (#157)

* 🗃️ coverletter 외래키 추가

* 👔 자소서 조회 포인트 사용 시, point 데이터에 coverletter 삽입 로직 추가

* 👔 자소서 상세 조회 시 포인트를 사용한 자소서인지 나타내는 변수 추가

* Refactor: 댓글 대댓글 계층 구조 적용 (#158)

* 🗃️ 댓글 계층 구조 나타내는 속성 추가

* 🗃️ db 변경 사항에 따른 댓글 작성 로직 수정

* 👔 db 변경 사항에 따른 댓글 목록 조회 로직 수정

* 🔥 필요 없는 메소드 삭제

* 👔 비활성/탈퇴 회원 제거 로직 추가
  • Loading branch information
joowojr authored May 20, 2024
1 parent 806f918 commit 60af4bf
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
public interface EmploymentBoardRepository extends JpaRepository<EmploymentBoard, Long> {

@Query("SELECT " +
"NEW com.codez4.meetfolio.domain.board.dto.BoardQueryItem(eb, eb.member.email,(SELECT l.status FROM Like l WHERE l.member = :member AND eb = l.board)) FROM EmploymentBoard eb WHERE eb.id = :boardId")
"NEW com.codez4.meetfolio.domain.board.dto.BoardQueryItem(eb, eb.member.email,(SELECT l.status FROM Like l WHERE l.member = :member AND eb = l.board)) FROM EmploymentBoard eb WHERE eb.id = :boardId AND eb.member.status = 'ACTIVE'")
BoardQueryItem queryFindEmploymentBoard(Member member,Long boardId);

@Query("SELECT " +
"NEW com.codez4.meetfolio.domain.board.dto.BoardQueryItem(eb, eb.member.email,(SELECT l.status FROM Like l WHERE l.member = :member AND eb = l.board)) FROM EmploymentBoard eb")
"NEW com.codez4.meetfolio.domain.board.dto.BoardQueryItem(eb, eb.member.email,(SELECT l.status FROM Like l WHERE l.member = :member AND eb = l.board)) FROM EmploymentBoard eb WHERE eb.member.status = 'ACTIVE'")
Page<BoardQueryItem> queryFindAllEmploymentBoards(Member member, Pageable pageable);

@Query("SELECT " +
"NEW com.codez4.meetfolio.domain.board.dto.BoardQueryItem(eb, eb.member.email, (SELECT l.status FROM Like l WHERE l.member = :member AND eb = l.board)) FROM EmploymentBoard eb WHERE eb.jobKeyword = :jobKeyword ")
"NEW com.codez4.meetfolio.domain.board.dto.BoardQueryItem(eb, eb.member.email, (SELECT l.status FROM Like l WHERE l.member = :member AND eb = l.board)) FROM EmploymentBoard eb WHERE eb.jobKeyword = :jobKeyword AND eb.member.status = 'ACTIVE'")
Page<BoardQueryItem> queryFindAllEmploymentBoardsByJobKeyword(Member member, JobKeyword jobKeyword, Pageable pageable);

@Query(value = "SELECT " +
"NEW com.codez4.meetfolio.domain.board.dto.BoardQueryItem(eb, eb.member.email, (SELECT l.status from Like l WHERE l.member = :member AND l.board = eb)) FROM EmploymentBoard eb WHERE eb.title LIKE CONCAT('%', :keyword , '%') ")
"NEW com.codez4.meetfolio.domain.board.dto.BoardQueryItem(eb, eb.member.email, (SELECT l.status from Like l WHERE l.member = :member AND l.board = eb)) FROM EmploymentBoard eb WHERE eb.title LIKE CONCAT('%', :keyword , '%') AND eb.member.status = 'ACTIVE'")
Page<BoardQueryItem> queryFindBoardsByKeyword(Member member, String keyword, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@

public interface GroupBoardRepository extends JpaRepository<GroupBoard, Long> {
@Query("SELECT " +
"NEW com.codez4.meetfolio.domain.board.dto.BoardQueryItem(gb, gb.member.email,(SELECT l.status FROM Like l WHERE l.member = :member AND gb = l.board)) FROM GroupBoard gb WHERE gb.id = :boardId")
"NEW com.codez4.meetfolio.domain.board.dto.BoardQueryItem(gb, gb.member.email,(SELECT l.status FROM Like l WHERE l.member = :member AND gb = l.board)) FROM GroupBoard gb WHERE gb.id = :boardId AND gb.member.status = 'ACTIVE'")
BoardQueryItem queryFindBoard(Member member, Long boardId);

@Query("SELECT " +
"NEW com.codez4.meetfolio.domain.board.dto.BoardQueryItem(gb, gb.member.email,(SELECT l.status FROM Like l WHERE l.member = :member AND gb = l.board)) FROM GroupBoard gb")
"NEW com.codez4.meetfolio.domain.board.dto.BoardQueryItem(gb, gb.member.email,(SELECT l.status FROM Like l WHERE l.member = :member AND gb = l.board)) FROM GroupBoard gb WHERE gb.member.status = 'ACTIVE'")
Page<BoardQueryItem> queryFindAllBoards(Member member, Pageable pageable);

@Query("SELECT " +
"NEW com.codez4.meetfolio.domain.board.dto.BoardQueryItem(gb, gb.member.email, (SELECT l.status FROM Like l WHERE l.member = :member AND gb = l.board)) FROM GroupBoard gb WHERE gb.groupCategory = :groupCategory ")
"NEW com.codez4.meetfolio.domain.board.dto.BoardQueryItem(gb, gb.member.email, (SELECT l.status FROM Like l WHERE l.member = :member AND gb = l.board)) FROM GroupBoard gb WHERE gb.groupCategory = :groupCategory AND gb.member.status = 'ACTIVE'")
Page<BoardQueryItem> queryFindAllBoardsByGroupCategory(Member member, GroupCategory groupCategory, Pageable pageable);

@Query(value = "SELECT " +
"NEW com.codez4.meetfolio.domain.board.dto.BoardQueryItem(gb, gb.member.email, (SELECT l.status from Like l WHERE l.member = :member AND l.board = gb)) FROM GroupBoard gb WHERE gb.title LIKE CONCAT('%', :keyword , '%') ")
"NEW com.codez4.meetfolio.domain.board.dto.BoardQueryItem(gb, gb.member.email, (SELECT l.status from Like l WHERE l.member = :member AND l.board = gb)) FROM GroupBoard gb WHERE gb.title LIKE CONCAT('%', :keyword , '%') AND gb.member.status = 'ACTIVE'")
Page<BoardQueryItem> queryFindBoardsByKeyword(Member member, String keyword, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ public class Comment extends BaseTimeEntity {
@OneToMany(mappedBy = "parentComment", orphanRemoval = true, cascade = CascadeType.ALL)
private List<Comment> children = new ArrayList<>();

@Column(nullable = false)
private int ref;

@Column(nullable = false)
private int refOrder;

@Column(nullable = false)
private int step;

/**
* update
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,14 @@ public static class MyCommentList {
}


public static CommentResult toCommentResult(Slice<Comment> comments) {

// 부모 댓글만 반환하기 (자식 댓글은 부모 댓글 안에 담아서 전달)
List<CommentItem> commentItems = comments.stream()
.filter(comment -> comment.getParentComment() == null)
.map(CommentResponse::toCommentItem)
.toList();
public static CommentResult toCommentResult(List<CommentItem> commentItems, Slice<Comment> comments) {

return CommentResult.builder()
.commentItems(commentItems)
.hasNext(comments.hasNext())
.isFirst(comments.isFirst())
.isLast(comments.isLast())
.build();
.commentItems(commentItems)
.hasNext(comments.hasNext())
.isFirst(comments.isFirst())
.isLast(comments.isLast())
.build();
}

public static MyCommentResult toMyCommentResult(MemberResponse.MemberInfo memberInfo, Page<MyCommentItem> comments) {
Expand All @@ -103,7 +97,7 @@ public static MyCommentResult toMyCommentResult(MemberResponse.MemberInfo member
.build();
}

public static MyCommentList toMyCommentList(Page<MyCommentItem> comments){
public static MyCommentList toMyCommentList(Page<MyCommentItem> comments) {
List<MyCommentItem> commentItems = comments.stream().toList();
return MyCommentList.builder()
.commentInfo(commentItems)
Expand Down Expand Up @@ -166,7 +160,7 @@ public static class MyCommentItem {

}

public static MyCommentItem toMyCommentItem(Comment comment){
public static MyCommentItem toMyCommentItem(Comment comment) {
Board board = comment.getBoard();
return MyCommentItem.builder()
.commentId(comment.getId())
Expand All @@ -177,28 +171,19 @@ public static MyCommentItem toMyCommentItem(Comment comment){
.build();
}

public static CommentItem toCommentItem(Comment comment) {
public static CommentItem toCommentItem(Comment comment, List<CommentItem> childComments) {

Member member = comment.getMember();
long sinceCreation = TimeUtils.getSinceCreation(comment.getCreatedAt());

return CommentItem.builder()
.commentId(comment.getId())
.content(comment.getContent())
.memberName(member.getEmail().split("@")[0])
.profile(member.getProfile().name())
.sinceCreation(sinceCreation)
.childComments(getChildList(comment))
.build();
}

private static List<CommentItem> getChildList(Comment comment) {

return Optional.ofNullable(comment.getChildren())
.orElse(new ArrayList<>())
.stream()
.map(CommentResponse::toCommentItem)
.toList();
.commentId(comment.getId())
.content(comment.getContent())
.memberName(member.getEmail().split("@")[0])
.profile(member.getProfile().name())
.sinceCreation(sinceCreation)
.childComments(childComments)
.build();
}

@Schema(description = "댓글 처리 응답 DTO")
Expand All @@ -218,20 +203,23 @@ public static class CommentProc {
public static CommentProc toCommentProc(Long commentId) {

return CommentProc.builder()
.commentId(commentId)
.createdAt(LocalDateTime.now())
.build();
.commentId(commentId)
.createdAt(LocalDateTime.now())
.build();
}

public static Comment toEntity(Member member, Board board, String content,
Comment parentComment) {
public static Comment toEntity(Member member, Board board, String content,Comment parentComment, int ref, int refOrder, int
step) {

return Comment.builder()
.member(member)
.board(board)
.content(content)
.parentComment(parentComment)
.build();
.member(member)
.board(board)
.content(content)
.parentComment(parentComment)
.ref(ref)
.refOrder(refOrder)
.step(step)
.build();
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.codez4.meetfolio.domain.comment.repository;

import com.codez4.meetfolio.domain.board.Board;
import com.codez4.meetfolio.domain.comment.Comment;
import com.codez4.meetfolio.domain.member.Member;
import org.springframework.data.domain.Page;
Expand All @@ -10,16 +11,32 @@
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CommentRepository extends JpaRepository<Comment, Long> {

void deleteByMember(Member member);

@Query(value = "SELECT c FROM Comment c JOIN FETCH Board b ON b = c.board WHERE c.member = :member ")
@Query(value = "SELECT c FROM Comment c JOIN FETCH Board b ON b = c.board WHERE c.member = :member AND c.member.status = 'ACTIVE'")
Page<Comment> findByMemberFetchJoinBoard(@Param("member") Member member,
PageRequest pageRequest);

@Query("SELECT c FROM Comment c JOIN FETCH c.member where c.board.id = :boardId")
@Query("SELECT c FROM Comment c JOIN FETCH c.member where c.board.id = :boardId AND c.member.status = 'ACTIVE'")
Slice<Comment> findByBoardFetchJoinMember(@Param("boardId") Long boardId,
PageRequest pageRequest);

@Query("SELECT c.ref FROM Comment c WHERE c.board = :board and c.id = :parent")
int getRefNumOfParent(Board board, Long parent);

@Query("SELECT IFNULL(MAX(c.ref), 0) FROM Comment c WHERE c.board = :board")
int getRefNum(Board board);

@Query("SELECT IFNULL(MAX(c.refOrder), 0) FROM Comment c WHERE c.board = :board and c.ref = :ref")
int getRefOrder(Board board, Integer ref);

@Query("SELECT c.step FROM Comment c WHERE c.board = :board and c.id = :parent")
int getStep(Board board, Long parent);

List<Comment> findAllByBoard_IdAndRef(Long boardId, int ref);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ private Comment createComment(CommentVO commentVO) {

if (parentId != null) {
Comment parentComment = getParentComment(parentId);
return CommentResponse.toEntity(member, board, content, parentComment);
int ref = commentRepository.getRefNumOfParent(board, parentId);
int refOrder = commentRepository.getRefOrder(board, ref);
int step = commentRepository.getStep(board, parentId);
return CommentResponse.toEntity(member, board, content, parentComment, ref, refOrder+1, step+1);
}
else {
int ref = commentRepository.getRefNum(board);
return CommentResponse.toEntity(member, board, content, null, ref + 1, 0, 0);
}
return CommentResponse.toEntity(member, board, content, null);
}

public Comment getParentComment(Long parentId) {
Comment parentComment = commentQueryService.findById(parentId);

// 부모의 댓글이 있는 경우 -> 에러 발생 (대댓글까지만 가능)
if (parentComment.getParentComment() != null) {
throw new ApiException(ErrorStatus._COMMENT_OVER_DEPTH_);
}
return parentComment;
return commentQueryService.findById(parentId);
}

public CommentResponse.CommentProc update(String content, Long commentId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

import static com.codez4.meetfolio.domain.comment.dto.CommentResponse.toCommentItem;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand Down Expand Up @@ -42,6 +47,13 @@ public CommentResponse.CommentResult findCommentsByBoard(Long boardId, int page)
Slice<Comment> comments = commentRepository.findByBoardFetchJoinMember(
boardId, pageRequest);

return CommentResponse.toCommentResult(comments);
// 부모 댓글만 반환하기 (자식 댓글은 부모 댓글 안에 담아서 전달)
List<CommentResponse.CommentItem> parentComments = comments.stream()
.filter(comment -> comment.getParentComment() == null)
.map(comment -> toCommentItem(comment,commentRepository.findAllByBoard_IdAndRef(boardId,
comment.getRef()).stream().filter(child -> child.getRefOrder() != 0).map(child -> {return toCommentItem(child,new ArrayList<>());}).toList() ))
.toList();

return CommentResponse.toCommentResult(parentComments,comments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ApiResponse<CoverLetterResult> getCoverLetter(@AuthenticationMember Membe
@PathVariable(name = "coverLetterId") Long coverLetterId) {

MemberInfo memberInfo = MemberResponse.toMemberInfo(member);
CoverLetterInfo coverLetterInfo = coverLetterQueryService.getCoverLetterInfo(coverLetterId);
CoverLetterInfo coverLetterInfo = coverLetterQueryService.getCoverLetterInfo(member, coverLetterId);
FeedbackInfo feedbackInfo = feedbackQueryService.getFeedbackInfo(coverLetterId);
AnalysisInfo analysisInfo = analysisQueryService.getAnalysisInfo(coverLetterId);
CoverLetterResult coverLetterResult = CoverLetterResponse.toCoverLetterResult(memberInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ public static class CoverLetterInfo {

@Schema(description = "지원 직무")
private String jobKeyword;

@Schema(description = "타 사용자 자소서 조회할 때, 포인트 사용 여부")
private Boolean isPaid;
}

public static CoverLetterInfo toCoverLetterInfo(CoverLetter coverLetter) {
public static CoverLetterInfo toCoverLetterInfo(CoverLetter coverLetter, Boolean isPaid) {

return CoverLetterInfo.builder()
.coverLetterId(coverLetter.getId())
Expand All @@ -57,6 +60,7 @@ public static CoverLetterInfo toCoverLetterInfo(CoverLetter coverLetter) {
.keyword1(coverLetter.getKeyword1())
.keyword2(coverLetter.getKeyword2())
.jobKeyword(coverLetter.getJobKeyword() != null ? coverLetter.getJobKeyword().getDescription() : null)
.isPaid(isPaid)
.build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,37 @@
import com.codez4.meetfolio.domain.coverLetter.dto.CoverLetterResponse.CoverLetterInfo;
import com.codez4.meetfolio.domain.coverLetter.repository.CoverLetterRepository;
import com.codez4.meetfolio.domain.member.Member;
import com.codez4.meetfolio.domain.point.repository.PointRepository;
import com.codez4.meetfolio.global.exception.ApiException;
import com.codez4.meetfolio.global.response.code.status.ErrorStatus;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class CoverLetterQueryService {

private final CoverLetterRepository coverLetterRepository;
private final PointRepository pointRepository;

public CoverLetterInfo getCoverLetterInfo(Long coverLetterId) {

public CoverLetterInfo getCoverLetterInfo(Member member, Long coverLetterId) {
CoverLetter coverLetter = findById(coverLetterId);
return CoverLetterResponse.toCoverLetterInfo(coverLetter);
Boolean isPaid;
Member coverletterMember = coverLetter.getMember();
if(member != coverletterMember) {
isPaid = pointRepository.getPointByCoverLetterAndMember(coverLetter, member).isPresent();
}
else {
isPaid = null;
}
return CoverLetterResponse.toCoverLetterInfo(coverLetter,isPaid);
}

public CoverLetter findById(Long coverLetterId) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/codez4/meetfolio/domain/point/Point.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.codez4.meetfolio.domain.point;

import com.codez4.meetfolio.domain.common.BaseTimeEntity;
import com.codez4.meetfolio.domain.coverLetter.CoverLetter;
import com.codez4.meetfolio.domain.enums.PointType;
import com.codez4.meetfolio.domain.member.Member;
import com.codez4.meetfolio.domain.payment.Payment;
Expand Down Expand Up @@ -35,4 +36,8 @@ public class Point extends BaseTimeEntity {
@Column(nullable = false)
@Enumerated(EnumType.STRING)
private PointType pointType;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "coverletter_id", nullable = true)
private CoverLetter coverLetter;
}
Loading

0 comments on commit 60af4bf

Please sign in to comment.