-
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 #49 from Team-Shaka/feat/39
✨ Feat : 댓글 작성, 목록 조회, 삭제 API 구현
- Loading branch information
Showing
15 changed files
with
273 additions
and
6 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/treehouse/server/api/comment/business/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 |
---|---|---|
@@ -1,4 +1,53 @@ | ||
package treehouse.server.api.comment.business; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import treehouse.server.api.comment.presentation.dto.CommentResponseDTO; | ||
import treehouse.server.api.member.business.MemberMapper; | ||
import treehouse.server.global.entity.User.User; | ||
import treehouse.server.global.entity.comment.Comment; | ||
import treehouse.server.global.entity.member.Member; | ||
import treehouse.server.global.entity.post.Post; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class CommentMapper { | ||
|
||
|
||
public static CommentResponseDTO.CommentInfoDto toCommentInfoDto(Comment comment) { | ||
return CommentResponseDTO.CommentInfoDto.builder() | ||
.commentedAt(comment.getCreatedAt().toString()) | ||
.commentId(comment.getId()) | ||
.context(comment.getContent()) | ||
// .reactionList(comment.) 리액션 관련 로직 구현 후 추가. | ||
.memberProfile(MemberMapper.toGetMemberProfile(comment.getWriter())) | ||
.build(); | ||
|
||
} | ||
|
||
public static CommentResponseDTO.CommentListDto toCommentListDto(List<Comment> commentList) { | ||
List<CommentResponseDTO.CommentInfoDto> commentInfoDtoList = commentList.stream() | ||
.map(comment -> | ||
toCommentInfoDto(comment)).toList(); | ||
return CommentResponseDTO.CommentListDto.builder() | ||
.commentList(commentInfoDtoList) | ||
.build(); | ||
} | ||
|
||
public static Comment toComment(Member writer, Post post, String content) { | ||
return Comment.builder() | ||
.writer(writer) | ||
.post(post) | ||
.content(content) | ||
.build(); | ||
} | ||
|
||
public static CommentResponseDTO.CommentIdResponseDto toIdResponseDto(Long commentId) { | ||
return CommentResponseDTO.CommentIdResponseDto.builder() | ||
.commentId(commentId) | ||
.build(); | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
src/main/java/treehouse/server/api/comment/implementation/CommentCommandAdapter.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 |
---|---|---|
@@ -1,4 +1,22 @@ | ||
package treehouse.server.api.comment.implementation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import treehouse.server.api.comment.persistence.CommentRepository; | ||
import treehouse.server.global.annotations.Adapter; | ||
import treehouse.server.global.entity.comment.Comment; | ||
|
||
@Adapter | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class CommentCommandAdapter { | ||
private final CommentRepository commentRepository; | ||
|
||
public Comment createComment(Comment comment) { | ||
return commentRepository.save(comment); | ||
} | ||
|
||
public void deleteComment(Comment comment) { | ||
commentRepository.delete(comment); | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
src/main/java/treehouse/server/api/comment/persistence/CommentRepository.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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
package treehouse.server.api.comment.persistence; | ||
|
||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import treehouse.server.global.entity.comment.Comment; | ||
|
||
import java.util.List; | ||
|
||
public interface CommentRepository extends JpaRepository<Comment, Long> { | ||
|
||
List<Comment> findAllByPostId(Long postId, Pageable pageable); | ||
|
||
} |
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
40 changes: 40 additions & 0 deletions
40
src/main/java/treehouse/server/api/comment/presentation/dto/CommentResponseDTO.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 |
---|---|---|
@@ -1,4 +1,44 @@ | ||
package treehouse.server.api.comment.presentation.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import treehouse.server.api.member.presentation.dto.MemberResponseDTO; | ||
import treehouse.server.api.reaction.presentation.dto.ReactionResponseDTO; | ||
|
||
import java.util.List; | ||
|
||
public class CommentResponseDTO { | ||
|
||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class CommentInfoDto{ | ||
|
||
MemberResponseDTO.getMemberProfile memberProfile; | ||
ReactionResponseDTO.reactionSimpleResponseDTO reactionList; | ||
Long commentId; | ||
String context; | ||
String commentedAt; | ||
} | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class CommentListDto{ | ||
List<CommentInfoDto> commentList; | ||
|
||
} | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class CommentIdResponseDto{ | ||
Long commentId; | ||
} | ||
} |
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
4 changes: 4 additions & 0 deletions
4
src/main/java/treehouse/server/api/reaction/presentation/dto/ReactionRequestDTO.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,4 @@ | ||
package treehouse.server.api.reaction.presentation.dto; | ||
|
||
public class ReactionRequestDTO { | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/treehouse/server/api/reaction/presentation/dto/ReactionResponseDTO.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,29 @@ | ||
package treehouse.server.api.reaction.presentation.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
public class ReactionResponseDTO { | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class reactionSimpleResponseDTO{ | ||
String reactionName; | ||
Long reactionCount; | ||
boolean isPushed; | ||
} | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class reactionSimpleListDTO{ | ||
List<reactionSimpleResponseDTO> simpleResponseDTOList; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/treehouse/server/api/report/implementation/ReportQueryAdapter.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,18 @@ | ||
package treehouse.server.api.report.implementation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import treehouse.server.api.report.persistent.ReportRepository; | ||
import treehouse.server.global.annotations.Adapter; | ||
import treehouse.server.global.entity.comment.Comment; | ||
|
||
@Adapter | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class ReportQueryAdapter { | ||
private final ReportRepository reportRepository; | ||
|
||
public boolean isReportedComment(Comment comment){ | ||
return reportRepository.existsByComment(comment); | ||
} | ||
} |
Oops, something went wrong.