-
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 #48 from Team-Shaka/feat/47
✨ Feat : 댓글 신고 API 구현
- Loading branch information
Showing
14 changed files
with
208 additions
and
11 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package treehouse.server.api.comment.business; | ||
|
||
public class CommentMapper { | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/treehouse/server/api/comment/business/CommentService.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,59 @@ | ||
package treehouse.server.api.comment.business; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import treehouse.server.api.comment.implementation.CommentQueryAdapter; | ||
import treehouse.server.api.comment.presentation.dto.CommentRequestDTO; | ||
import treehouse.server.api.member.implementation.MemberQueryAdapter; | ||
import treehouse.server.api.post.implement.PostQueryAdapter; | ||
import treehouse.server.api.report.business.ReportMapper; | ||
import treehouse.server.api.report.implementation.ReportCommandAdapter; | ||
import treehouse.server.api.treehouse.implementation.TreehouseQueryAdapter; | ||
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.report.Report; | ||
import treehouse.server.global.entity.treeHouse.TreeHouse; | ||
import treehouse.server.global.exception.GlobalErrorCode; | ||
import treehouse.server.global.exception.ThrowClass.CommentException; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@Transactional | ||
public class CommentService { | ||
|
||
private final ReportCommandAdapter reportCommandAdapter; | ||
|
||
private final MemberQueryAdapter memberQueryAdapter; | ||
|
||
private final CommentQueryAdapter commentQueryAdapter; | ||
|
||
private final PostQueryAdapter postQueryAdapter; | ||
|
||
private final TreehouseQueryAdapter treehouseQueryAdapter; | ||
|
||
|
||
public void reportComment(User user, CommentRequestDTO.reportComment reqeust, Long treehouseId, Long postId, Long commentId){ | ||
|
||
TreeHouse treehouse = treehouseQueryAdapter.getTreehouseById(treehouseId); | ||
|
||
Member reporter = memberQueryAdapter.findByUserAndTreehouse(user, treehouse); | ||
|
||
Comment comment = commentQueryAdapter.getCommentById(commentId); | ||
|
||
if (!comment.getPost().getId().equals(postId)) | ||
throw new CommentException(GlobalErrorCode.COMMENT_NOT_FOUND); | ||
|
||
Member target = comment.getWriter(); | ||
|
||
if (target.equals(reporter)) | ||
throw new CommentException(GlobalErrorCode.COMMENT_SELF_REPORT); | ||
|
||
Report report = ReportMapper.toCommentReport(reqeust, comment, reporter, target); | ||
|
||
reportCommandAdapter.createReport(report); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package treehouse.server.api.comment.implementation; | ||
|
||
public class CommentCommandAdapter { | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/treehouse/server/api/comment/implementation/CommentQueryAdapter.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 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; | ||
import treehouse.server.global.exception.GlobalErrorCode; | ||
import treehouse.server.global.exception.ThrowClass.CommentException; | ||
|
||
@Adapter | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class CommentQueryAdapter { | ||
|
||
private final CommentRepository commentRepository; | ||
|
||
public Comment getCommentById(Long commentId){ | ||
return commentRepository.findById(commentId).orElseThrow(()->new CommentException(GlobalErrorCode.COMMENT_NOT_FOUND)); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package treehouse.server.api.comment.persistence; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import treehouse.server.global.entity.comment.Comment; | ||
|
||
public interface CommentRepository extends JpaRepository<Comment, Long> { | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/treehouse/server/api/comment/presentation/CommentApi.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,39 @@ | ||
package treehouse.server.api.comment.presentation; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
import treehouse.server.api.comment.business.CommentService; | ||
import treehouse.server.api.comment.presentation.dto.CommentRequestDTO; | ||
import treehouse.server.global.common.CommonResponse; | ||
import treehouse.server.global.entity.User.User; | ||
import treehouse.server.global.security.handler.annotation.AuthMember; | ||
|
||
@RequestMapping("/treehouses/{treehouseId}/feeds/posts/{postId}/comments") | ||
@RequiredArgsConstructor | ||
@RestController | ||
@Slf4j | ||
@Tag(name = "📃 Comment API", description = "트리하우스 댓글 관련 API 입니다.") | ||
public class CommentApi { | ||
|
||
private final CommentService commentService; | ||
|
||
@Operation(summary = "댓글 신고 API 🔑", description = "댓글을 신고하는 API 입니다.") | ||
@PostMapping("/{commentId}/reports") | ||
public CommonResponse reportComment( | ||
@PathVariable(name = "treehouseId") Long treehouseId, | ||
@PathVariable(name = "postId") Long postId, | ||
@PathVariable(name = "commentId") Long commentId, | ||
@Parameter(hidden = true) @AuthMember User user, | ||
@RequestBody @Validated CommentRequestDTO.reportComment request | ||
) | ||
{ | ||
commentService.reportComment(user,request,treehouseId,postId,commentId); | ||
return CommonResponse.onSuccess(null); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/treehouse/server/api/comment/presentation/dto/CommentRequestDTO.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,23 @@ | ||
package treehouse.server.api.comment.presentation.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Getter; | ||
|
||
public class CommentRequestDTO { | ||
|
||
@Getter | ||
public static class reportComment{ | ||
|
||
@JsonProperty("reason") | ||
@Schema(description = "신고 사유", example = "부적절한 댓글") | ||
private String reason; | ||
|
||
@JsonProperty("targetMemberId") | ||
@Schema(description = "신고 대상 멤버 아이디", example = "1") | ||
@NotNull(message = "신고 대상 멤버 아이디는 필수입니다.") | ||
private Long targetMemberId; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package treehouse.server.api.comment.presentation.dto; | ||
|
||
public class CommentResponseDTO { | ||
} |
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
29 changes: 29 additions & 0 deletions
29
src/main/java/treehouse/server/api/report/business/ReportMapper.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.report.business; | ||
|
||
import treehouse.server.api.comment.presentation.dto.CommentRequestDTO; | ||
import treehouse.server.api.post.presentation.dto.PostRequestDTO; | ||
import treehouse.server.global.entity.comment.Comment; | ||
import treehouse.server.global.entity.member.Member; | ||
import treehouse.server.global.entity.post.Post; | ||
import treehouse.server.global.entity.report.Report; | ||
|
||
public class ReportMapper { | ||
|
||
public static Report toPostReport(PostRequestDTO.reportPost request, Post post, Member reporter, Member target){ | ||
return Report.builder() | ||
.reason(request.getReason()) | ||
.post(post) | ||
.reporterMember(reporter) | ||
.targetMember(target) | ||
.build(); | ||
} | ||
|
||
public static Report toCommentReport(CommentRequestDTO.reportComment request, Comment comment, Member reporter, Member target){ | ||
return Report.builder() | ||
.reason(request.getReason()) | ||
.comment(comment) | ||
.reporterMember(reporter) | ||
.targetMember(target) | ||
.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
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
10 changes: 10 additions & 0 deletions
10
src/main/java/treehouse/server/global/exception/ThrowClass/CommentException.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,10 @@ | ||
package treehouse.server.global.exception.ThrowClass; | ||
|
||
import treehouse.server.global.exception.BaseErrorCode; | ||
|
||
public class CommentException extends GeneralException{ | ||
|
||
public CommentException(BaseErrorCode errorCode){ | ||
super(errorCode); | ||
} | ||
} |