Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import konkuk.thip.comment.adapter.in.web.response.CommentDeleteResponse;
import konkuk.thip.comment.adapter.in.web.response.CommentCreateResponse;
import konkuk.thip.comment.adapter.in.web.response.CommentIsLikeResponse;
import konkuk.thip.comment.adapter.in.web.response.CommentReportResponse;
import konkuk.thip.comment.application.port.in.CommentCreateUseCase;
import konkuk.thip.comment.application.port.in.CommentDeleteUseCase;
import konkuk.thip.comment.application.port.in.CommentLikeUseCase;
import konkuk.thip.comment.application.port.in.CommentReportUseCase;
import konkuk.thip.common.dto.BaseResponse;
import konkuk.thip.common.security.annotation.UserId;
import konkuk.thip.common.swagger.annotation.ExceptionDescription;
Expand All @@ -28,6 +30,7 @@ public class CommentCommandController {
private final CommentCreateUseCase commentCreateUseCase;
private final CommentLikeUseCase commentLikeUseCase;
private final CommentDeleteUseCase commentDeleteUseCase;
private final CommentReportUseCase commentReportUseCase;

/**
* 댓글/답글 작성
Expand Down Expand Up @@ -74,4 +77,15 @@ public BaseResponse<CommentDeleteResponse> deleteComment(
return BaseResponse.ok(CommentDeleteResponse.of(commentDeleteUseCase.deleteComment(commentId,userId)));
}

@Operation(
summary = "댓글 신고",
description = "사용자가 댓글을 신고합니다. 신고 횟수만 증가하며 별도의 처리는 이루어지지 않습니다."
)
@ExceptionDescription(COMMENT_REPORT)
@PostMapping("/comments/{commentId}/report")
public BaseResponse<CommentReportResponse> reportComment(
@Parameter(description = "신고하려는 댓글 ID", example = "1") @PathVariable("commentId") final Long commentId) {
return BaseResponse.ok(CommentReportResponse.of(commentReportUseCase.reportComment(commentId)));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package konkuk.thip.comment.adapter.in.web.response;

import konkuk.thip.comment.application.port.in.dto.CommentReportResult;

public record CommentReportResponse(
Long commentId,
int reportCount
) {
public static CommentReportResponse of(CommentReportResult commentReportResult) {
return new CommentReportResponse(commentReportResult.commentId(), commentReportResult.reportCount());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package konkuk.thip.comment.application.port.in;

import konkuk.thip.comment.application.port.in.dto.CommentReportResult;

public interface CommentReportUseCase {
CommentReportResult reportComment(Long commentId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package konkuk.thip.comment.application.port.in.dto;

public record CommentReportResult(
Long commentId,
int reportCount
) {
public static CommentReportResult of(Long commentId, int reportCount) {
return new CommentReportResult(commentId, reportCount);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package konkuk.thip.comment.application.service;

import konkuk.thip.comment.application.port.in.CommentReportUseCase;
import konkuk.thip.comment.application.port.in.dto.CommentReportResult;
import konkuk.thip.comment.application.port.out.CommentCommandPort;
import konkuk.thip.comment.domain.Comment;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class CommentReportService implements CommentReportUseCase {

private final CommentCommandPort commentCommandPort;

@Override
@Transactional
public CommentReportResult reportComment(Long commentId) {
Comment comment = commentCommandPort.getByIdOrThrow(commentId);
comment.increaseReportCount();
commentCommandPort.update(comment);

return CommentReportResult.of(comment.getId(), comment.getReportCount());
}
}
4 changes: 4 additions & 0 deletions src/main/java/konkuk/thip/comment/domain/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ public static void validateCommentCreate(boolean isReplyRequest, Long parentId)
}
}

public void increaseReportCount() {
reportCount++;
}

public void updateLikeCount(Boolean like) {
if (like) {
likeCount++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ public enum SwaggerResponseDescription {
FEED_NOT_FOUND,
FEED_ACCESS_FORBIDDEN
))),
FEED_REPORT(new LinkedHashSet<>(Set.of(
FEED_NOT_FOUND
))),

// Comment
COMMENT_CREATE(new LinkedHashSet<>(Set.of(
Expand Down Expand Up @@ -309,6 +312,9 @@ public enum SwaggerResponseDescription {
ROOM_IS_EXPIRED,
ROOM_NOT_IN_PROGRESS
))),
COMMENT_REPORT(new LinkedHashSet<>(Set.of(
COMMENT_NOT_FOUND
))),

// Book
CHANGE_BOOK_SAVED_STATE(new LinkedHashSet<>(Set.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import konkuk.thip.feed.adapter.in.web.response.FeedIdResponse;
import konkuk.thip.feed.adapter.in.web.response.FeedIsLikeResponse;
import konkuk.thip.feed.adapter.in.web.response.FeedIsSavedResponse;
import konkuk.thip.feed.adapter.in.web.response.FeedReportResponse;
import konkuk.thip.feed.adapter.in.web.response.FeedUploadImagePresignedUrlResponse;
import konkuk.thip.feed.adapter.out.s3.S3Service;
import konkuk.thip.feed.application.port.in.*;
Expand All @@ -32,6 +33,7 @@ public class FeedCommandController {
private final FeedSavedUseCase feedSavedUseCase;
private final PostLikeUseCase postLikeUseCase;
private final FeedDeleteUseCase feedDeleteUseCase;
private final FeedReportUseCase feedReportUseCase;

private final S3Service s3Service;

Expand Down Expand Up @@ -114,4 +116,15 @@ public BaseResponse<Void> deleteFeed(
return BaseResponse.ok(null);
}

@Operation(
summary = "피드 신고",
description = "사용자가 피드를 신고합니다. 신고 횟수만 증가하며 별도의 처리는 이루어지지 않습니다."
)
@ExceptionDescription(FEED_REPORT)
@PostMapping("/feeds/{feedId}/report")
public BaseResponse<FeedReportResponse> reportFeed(
@Parameter(description = "신고하려는 피드 ID", example = "1") @PathVariable("feedId") final Long feedId) {
return BaseResponse.ok(FeedReportResponse.of(feedReportUseCase.reportFeed(feedId)));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package konkuk.thip.feed.adapter.in.web.response;

import konkuk.thip.feed.application.port.in.dto.FeedReportResult;

public record FeedReportResponse(
Long feedId,
int reportCount
) {
public static FeedReportResponse of(FeedReportResult feedReportResult) {
return new FeedReportResponse(feedReportResult.feedId(), feedReportResult.reportCount());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package konkuk.thip.feed.application.port.in;

import konkuk.thip.feed.application.port.in.dto.FeedReportResult;

public interface FeedReportUseCase {
FeedReportResult reportFeed(Long feedId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package konkuk.thip.feed.application.port.in.dto;

public record FeedReportResult(
Long feedId,
int reportCount
) {
public static FeedReportResult of(Long feedId, int reportCount) {
return new FeedReportResult(feedId, reportCount);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package konkuk.thip.feed.application.service;

import konkuk.thip.feed.application.port.in.FeedReportUseCase;
import konkuk.thip.feed.application.port.in.dto.FeedReportResult;
import konkuk.thip.feed.application.port.out.FeedCommandPort;
import konkuk.thip.feed.domain.Feed;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class FeedReportService implements FeedReportUseCase {

private final FeedCommandPort feedCommandPort;

@Override
@Transactional
public FeedReportResult reportFeed(Long feedId) {
Feed feed = feedCommandPort.getByIdOrThrow(feedId);
feed.increaseReportCount();
feedCommandPort.update(feed);

return FeedReportResult.of(feed.getId(), feed.getReportCount());
}
}
4 changes: 4 additions & 0 deletions src/main/java/konkuk/thip/feed/domain/Feed.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ public void updateImages(Long userId, List<String> newImageUrls) {
this.contentList = convertToContentList(newImageUrls);
}

public void increaseReportCount() {
reportCount++;
}

@Override
public void increaseCommentCount() {
commentCount++;
Expand Down
Loading