forked from codesquad-members-2023/FoodyMoody-team-06
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
979 additions
and
385 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
56 changes: 56 additions & 0 deletions
56
be/src/main/java/com/foodymoody/be/comment/application/CommentMapper.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,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()) | ||
) | ||
); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
be/src/main/java/com/foodymoody/be/comment/application/CommentReadService.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,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); | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
be/src/main/java/com/foodymoody/be/comment/application/FeedCommentReadService.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,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)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
be/src/main/java/com/foodymoody/be/comment/application/ReplyService.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,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); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...nt/controller/dto/EditCommentRequest.java → ...ation/dto/request/EditCommentRequest.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
2 changes: 1 addition & 1 deletion
2
...ontroller/dto/RegisterCommentRequest.java → ...n/dto/request/RegisterCommentRequest.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
2 changes: 1 addition & 1 deletion
2
.../controller/dto/RegisterReplyRequest.java → ...ion/dto/request/RegisterReplyRequest.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
25 changes: 25 additions & 0 deletions
25
...rc/main/java/com/foodymoody/be/comment/application/dto/response/MemberCommentSummary.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,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(); | ||
} |
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
20 changes: 20 additions & 0 deletions
20
be/src/main/java/com/foodymoody/be/comment/application/dto/response/MemberReplySummary.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,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(); | ||
} |
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
Oops, something went wrong.