Skip to content

Commit

Permalink
[BE] 댓글 멤버 참조 (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertImKr authored Nov 30, 2023
2 parents e04241e + bb82768 commit a096fcf
Show file tree
Hide file tree
Showing 73 changed files with 979 additions and 385 deletions.
27 changes: 27 additions & 0 deletions be/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,25 @@ operation::readAllStoreMood[snippets='http-request,http-response']
== 좋아요

=== 좋아요 등록

==== 성공

operation::like[snippets='http-request,http-response']

==== 이미 좋아요 된 피드일 때

operation::likeFailed[snippets='http-request,http-response']

=== 좋아요 취소

==== 성공

operation::unLike[snippets='http-request,http-response']

==== 좋아요 된 피드가 없을 때

operation::unLikeFailed[snippets='http-request,http-response']

[[auth]]
== 인증/인가

Expand Down Expand Up @@ -191,6 +208,16 @@ operation::fetchMemberProfile_success[snippets='http-request,http-response']

operation::fetchMemberProfile_failedByIdNotFound[snippets='http-response']

=== 회원별 피드 조회

==== 성공

operation::fetchMemberFeeds_success[snippets='http-request,http-response']

==== 성공 - 해당 회원이 작성한 피드가 없을 때

operation::fetchMemberFeedsEmpty_success[snippets='http-response']

=== 테이스트 무드 조회

==== 성공
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.foodymoody.be.comment.application;

import com.foodymoody.be.comment.application.dto.request.RegisterCommentRequest;
import com.foodymoody.be.comment.application.dto.response.MemberCommentSummary;
import com.foodymoody.be.comment.application.dto.response.MemberCommentSummaryResponse;
import com.foodymoody.be.comment.application.dto.response.MemberReplySummary;
import com.foodymoody.be.comment.application.dto.response.MemberReplySummaryResponse;
import com.foodymoody.be.comment.application.dto.response.MemberSummaryResponse;
import com.foodymoody.be.comment.domain.entity.Comment;
import com.foodymoody.be.comment.domain.entity.CommentId;
import com.foodymoody.be.comment.domain.entity.Reply;
import com.foodymoody.be.comment.domain.entity.ReplyId;
import java.time.LocalDateTime;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Component;

@Component
public class CommentMapper {

public static Slice<MemberCommentSummaryResponse> mapToSummaryResponse(
Slice<MemberCommentSummary> withMemberAllByFeedId) {
return withMemberAllByFeedId.map(
summary -> new MemberCommentSummaryResponse(
summary.getId(),
summary.getContent(),
summary.getCreatedAt(),
summary.getUpdatedAt(),
new MemberSummaryResponse(summary.getMemberId(), summary.getNickname(), summary.getImageUrl()),
summary.isHasReply(), summary.getReplyCount()
)
);
}

public Comment toEntity(RegisterCommentRequest request, LocalDateTime createdAt, CommentId commentId,
String memberId) {
return new Comment(commentId, request.getContent(), request.getFeedId(), false, memberId, createdAt);
}

public Reply toReply(ReplyId replyId, LocalDateTime now, String memberId, @NotNull @NotBlank String content) {
return new Reply(replyId, content, false, memberId, now, now);
}

public Slice<MemberReplySummaryResponse> toReplySummaryResponse(Slice<MemberReplySummary> memberReplySummaries) {
return memberReplySummaries.map(
summary -> new MemberReplySummaryResponse(
summary.getReplyId(),
summary.getContent(),
summary.getCreatedAt(),
summary.getUpdatedAt(),
new MemberSummaryResponse(summary.getMemberId(), summary.getNickname(), summary.getImageUrl())
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.foodymoody.be.comment.application;

import com.foodymoody.be.comment.domain.entity.Comment;
import com.foodymoody.be.comment.domain.entity.CommentId;
import com.foodymoody.be.comment.domain.repository.CommentRepository;
import com.foodymoody.be.common.exception.CommentNotExistsException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Service
public class CommentReadService {

private final CommentRepository commentRepository;

@Transactional(readOnly = true)
public Comment fetchById(CommentId id) {
return commentRepository.findById(id).orElseThrow(CommentNotExistsException::new);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.foodymoody.be.comment.service;

import com.foodymoody.be.comment.controller.dto.EditCommentRequest;
import com.foodymoody.be.comment.controller.dto.RegisterCommentRequest;
import com.foodymoody.be.comment.controller.dto.RegisterReplyRequest;
import com.foodymoody.be.comment.domain.Comment;
import com.foodymoody.be.comment.domain.CommentId;
import com.foodymoody.be.comment.domain.Reply;
import com.foodymoody.be.comment.domain.ReplyId;
import com.foodymoody.be.comment.repository.CommentRepository;
package com.foodymoody.be.comment.application;

import com.foodymoody.be.comment.application.dto.request.EditCommentRequest;
import com.foodymoody.be.comment.application.dto.request.RegisterCommentRequest;
import com.foodymoody.be.comment.application.dto.request.RegisterReplyRequest;
import com.foodymoody.be.comment.domain.entity.Comment;
import com.foodymoody.be.comment.domain.entity.CommentId;
import com.foodymoody.be.comment.domain.entity.Reply;
import com.foodymoody.be.comment.domain.entity.ReplyId;
import com.foodymoody.be.comment.domain.repository.CommentRepository;
import com.foodymoody.be.common.exception.CommentNotExistsException;
import com.foodymoody.be.common.util.IdGenerator;
import com.foodymoody.be.feed.service.FeedService;
import java.time.LocalDateTime;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand All @@ -19,15 +18,13 @@

@RequiredArgsConstructor
@Service
public class CommentService {
public class CommentWriteService {

private final FeedService feedService;
private final CommentRepository commentRepository;
private final CommentMapper commentMapper;

@Transactional
public CommentId registerComment(RegisterCommentRequest request, String memberId) {
feedService.validate(request.getFeedId());
String newId = IdGenerator.generate();
LocalDateTime now = LocalDateTime.now();
CommentId commentId = new CommentId(newId);
Expand All @@ -51,10 +48,6 @@ public void delete(String id, String memberId) {
comment.delete(memberId, LocalDateTime.now());
}

public Comment fetchById(CommentId id) {
return commentRepository.findById(id).orElseThrow(CommentNotExistsException::new);
}

@Transactional
public void reply(String id, @Valid RegisterReplyRequest request, String memberId) {
Comment comment = fetchById(CommentId.from(id));
Expand All @@ -63,5 +56,7 @@ public void reply(String id, @Valid RegisterReplyRequest request, String memberI
comment.addReply(reply);
}


private Comment fetchById(CommentId id) {
return commentRepository.findById(id).orElseThrow(CommentNotExistsException::new);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.foodymoody.be.comment.application;

import com.foodymoody.be.comment.application.dto.response.MemberCommentSummaryResponse;
import com.foodymoody.be.comment.domain.repository.CommentRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Service
public class FeedCommentReadService {

private final CommentRepository commentRepository;
private final CommentMapper commentMapper;

@Transactional(readOnly = true)
public Slice<MemberCommentSummaryResponse> fetchComments(String feedId, Pageable pageable) {
return CommentMapper.mapToSummaryResponse(commentRepository.findWithMemberAllByFeedId(feedId, pageable));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.foodymoody.be.comment.application;

import com.foodymoody.be.comment.application.dto.response.MemberReplySummary;
import com.foodymoody.be.comment.application.dto.response.MemberReplySummaryResponse;
import com.foodymoody.be.comment.domain.entity.CommentId;
import com.foodymoody.be.comment.domain.repository.ReplyRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Service
public class ReplyService {

private final ReplyRepository replyRepository;
private final CommentMapper commentMapper;

@Transactional(readOnly = true)
public Slice<MemberReplySummaryResponse> fetchAllReply(CommentId commentId, Pageable pageable) {
Slice<MemberReplySummary> memberReplySummaries = replyRepository.findByCommentId(commentId, pageable);
return commentMapper.toReplySummaryResponse(memberReplySummaries);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.foodymoody.be.comment.controller.dto;
package com.foodymoody.be.comment.application.dto.request;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.foodymoody.be.comment.controller.dto;
package com.foodymoody.be.comment.application.dto.request;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.foodymoody.be.comment.controller.dto;
package com.foodymoody.be.comment.application.dto.request;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.foodymoody.be.comment.application.dto.response;

import java.time.LocalDateTime;

public interface MemberCommentSummary {


String getId();

String getContent();

LocalDateTime getCreatedAt();

LocalDateTime getUpdatedAt();

String getMemberId();

String getNickname();

String getImageUrl();

boolean isHasReply();

int getReplyCount();
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
package com.foodymoody.be.comment.controller.dto;
package com.foodymoody.be.comment.application.dto.response;

import java.time.LocalDateTime;

public class CommentResponse {
public class MemberCommentSummaryResponse {

private String id;
private String content;
private MemberResponse member;
private boolean hasReply;
private int replyCount;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private MemberSummaryResponse member;
private boolean hasReply;
private int replyCount;

public CommentResponse(String id, String content, String memberId, String memberName,
String memberProfileImage, boolean hasReply, int replyCount, LocalDateTime createdAt,
LocalDateTime updatedAt) {
public MemberCommentSummaryResponse(String id, String content, LocalDateTime createdAt, LocalDateTime updatedAt,
MemberSummaryResponse member, boolean hasReply, int replyCount) {
this.id = id;
this.content = content;
this.member = new MemberResponse(memberId, memberName, memberProfileImage);
this.hasReply = hasReply;
this.replyCount = replyCount;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.member = member;
this.hasReply = hasReply;
this.replyCount = replyCount;
}


public String getId() {
return id;
}
Expand All @@ -41,7 +39,7 @@ public LocalDateTime getUpdatedAt() {
return updatedAt;
}

public MemberResponse getMember() {
public MemberSummaryResponse getMember() {
return member;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.foodymoody.be.comment.application.dto.response;

import java.time.LocalDateTime;

public interface MemberReplySummary {

String getReplyId();

String getContent();

String getMemberId();

String getNickname();

String getImageUrl();

LocalDateTime getCreatedAt();

LocalDateTime getUpdatedAt();
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package com.foodymoody.be.comment.controller.dto;
package com.foodymoody.be.comment.application.dto.response;

import java.time.LocalDateTime;

public class ReplyResponse {
public class MemberReplySummaryResponse {

private String id;
private String content;
private MemberResponse member;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private MemberSummaryResponse member;

public ReplyResponse(String id, String content, String memberId, String memberName, String memberProfileImage,
LocalDateTime createdAt,
LocalDateTime updatedAt) {
public MemberReplySummaryResponse(String id, String content, LocalDateTime createdAt, LocalDateTime updatedAt,
MemberSummaryResponse member) {
this.id = id;
this.content = content;
this.member = new MemberResponse(memberId, memberProfileImage, memberName);
this.createdAt = createdAt;
this.updatedAt = updatedAt;
this.member = member;
}

public String getId() {
Expand All @@ -28,15 +27,15 @@ public String getContent() {
return content;
}

public MemberResponse getMember() {
return member;
}

public LocalDateTime getCreatedAt() {
return createdAt;
}

public LocalDateTime getUpdatedAt() {
return updatedAt;
}

public MemberSummaryResponse getMember() {
return member;
}
}
Loading

0 comments on commit a096fcf

Please sign in to comment.