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
@@ -0,0 +1,77 @@
package com.promsearch.community.interfaces;

import com.promsearch.community.interfaces.docs.CommentControllerDocs;
import com.promsearch.community.interfaces.dto.request.CreateCommentRequest;
import com.promsearch.community.interfaces.dto.request.UpdateCommentRequest;
import com.promsearch.community.interfaces.dto.response.CommentListResponse;
import com.promsearch.community.interfaces.dto.response.CommentReplyResponse;
import com.promsearch.community.interfaces.dto.response.CommentResponse;
import com.promsearch.global.exception.NotImplementedException;
import com.promsearch.global.response.ApiResponse;
import com.promsearch.global.security.AuthenticatedUserPrincipal;
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Validated
@RestController
@RequestMapping("/api/v1")
public class CommentController implements CommentControllerDocs {

@GetMapping("/prompts/{promptId}/comments")
@Override
public ApiResponse<CommentListResponse> getComments(
@PathVariable Long promptId,
@AuthenticationPrincipal AuthenticatedUserPrincipal user
) {
throw new NotImplementedException("댓글 목록 조회 기능은 아직 구현되지 않았습니다.");
}

@PostMapping("/prompts/{promptId}/comments")
@Override
public ResponseEntity<ApiResponse<CommentResponse>> createComment(
@PathVariable Long promptId,
@AuthenticationPrincipal AuthenticatedUserPrincipal user,
@Valid @RequestBody CreateCommentRequest request
) {
throw new NotImplementedException("댓글 작성 기능은 아직 구현되지 않았습니다.");
}

@PatchMapping("/comments/{commentId}")
@Override
public ApiResponse<CommentResponse> updateComment(
@PathVariable Long commentId,
@AuthenticationPrincipal AuthenticatedUserPrincipal user,
@Valid @RequestBody UpdateCommentRequest request
) {
throw new NotImplementedException("댓글 수정 기능은 아직 구현되지 않았습니다.");
}

@DeleteMapping("/comments/{commentId}")
@Override
public ApiResponse<Void> deleteComment(
@PathVariable Long commentId,
@AuthenticationPrincipal AuthenticatedUserPrincipal user
) {
throw new NotImplementedException("댓글 삭제 기능은 아직 구현되지 않았습니다.");
}

@PostMapping("/comments/{commentId}/replies")
@Override
public ResponseEntity<ApiResponse<CommentReplyResponse>> createReply(
@PathVariable Long commentId,
@AuthenticationPrincipal AuthenticatedUserPrincipal user,
@Valid @RequestBody CreateCommentRequest request
) {
throw new NotImplementedException("대댓글 작성 기능은 아직 구현되지 않았습니다.");
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.promsearch.community.interfaces.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;

@Schema(description = "댓글 또는 대댓글 작성 요청")
public record CreateCommentRequest(
@Schema(description = "댓글 내용", example = "좋은 프롬프트네요.")
@NotBlank(message = "content must not be blank")
String content
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.promsearch.community.interfaces.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;

@Schema(description = "댓글 수정 요청")
public record UpdateCommentRequest(
@Schema(description = "수정할 댓글 내용", example = "수정된 댓글 내용입니다.")
@NotBlank(message = "content must not be blank")
String content
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.promsearch.community.interfaces.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "댓글 작성자 공개 정보")
public record CommentAuthorResponse(
@Schema(description = "작성자 ID", example = "8")
Long userId,

@Schema(description = "작성자 닉네임", example = "홍길동")
String nickname,

@Schema(
description = "작성자 프로필 이미지 URL",
example = "https://cdn.promsearch.com/profiles/8.jpg",
nullable = true
)
String profileImageUrl
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.promsearch.community.interfaces.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;

@Schema(description = "페이지네이션 없이 전체 댓글을 반환하는 목록 응답")
public record CommentListResponse(
@Schema(description = "작성 시간 내림차순으로 정렬된 최상위 댓글 목록")
List<CommentResponse> comments
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.promsearch.community.interfaces.dto.response;

import com.promsearch.community.domain.enums.CommentStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.Instant;

@Schema(description = "대댓글 응답")
public record CommentReplyResponse(
@Schema(description = "대댓글 ID", example = "102")
Long commentId,

@Schema(description = "부모 댓글 ID", example = "101")
Long parentCommentId,

@Schema(description = "작성자 정보")
CommentAuthorResponse author,

@Schema(description = "대댓글 내용", example = "저도 그렇게 생각합니다.")
String content,

@Schema(description = "대댓글 상태", example = "ACTIVE")
CommentStatus status,

@Schema(description = "현재 로그인 사용자가 작성한 대댓글인지 여부", example = "true")
boolean mine,

@Schema(description = "프롬프트 작성자가 작성한 대댓글인지 여부", example = "false")
boolean promptAuthor,

@Schema(description = "작성 시각", example = "2026-07-23T03:10:00Z")
Instant createdAt,

@Schema(description = "수정 시각", example = "2026-07-23T03:10:00Z")
Instant updatedAt
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.promsearch.community.interfaces.dto.response;

import com.promsearch.community.domain.enums.CommentStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.Instant;
import java.util.List;

@Schema(description = "댓글 및 대댓글 응답")
public record CommentResponse(
@Schema(description = "댓글 ID", example = "101")
Long commentId,

@Schema(description = "부모 댓글 ID. 최상위 댓글이면 null입니다.", example = "100", nullable = true)
Long parentCommentId,

@Schema(description = "작성자 정보")
CommentAuthorResponse author,

@Schema(description = "댓글 내용", example = "좋은 프롬프트네요.")
String content,

@Schema(description = "댓글 상태", example = "ACTIVE")
CommentStatus status,

@Schema(description = "현재 로그인 사용자가 작성한 댓글인지 여부", example = "true")
boolean mine,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figma 댓글 컴포넌트에는 프롬프트 작성자의 댓글임을 나타내는 “작성자” 배지가 있고 mine은 로그인 사용자 본인의 댓글인지만 나타내고 있습니다.
그래서 boolean 형식의 필드를 추가해서 작성자 댓글인 것을 나타내면 좋을 것 같습니다!
아니면 상세 응답의 prompt.author.userIdcomment.author.userId를 프론트가 비교하는 방식으로 처리할지, 댓글 응답에 promptAuthor boolean을 제공할지 정하는 것도 좋을 것 같습니다!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

프론트에서 작성자 ID를 비교하는 방식도 가능하지만, 댓글 API만으로 UI 상태를 명확히 판단할 수 있도록 백엔드에서 제공하는 방향으로 반영했습니다. 기존 mine은 로그인 사용자 본인의 댓글 여부로 유지하고, 프롬프트 작성자의 댓글 여부를 나타내는 promptAuthor 필드를 댓글 및 대댓글 응답에 추가했습니다. 놓쳤던 세부 사항까지 꼼꼼하게 확인해 주셔서 감사합니다!


@Schema(description = "프롬프트 작성자가 작성한 댓글인지 여부", example = "false")
boolean promptAuthor,

@Schema(description = "작성 시각", example = "2026-07-23T01:30:00Z")
Instant createdAt,

@Schema(description = "수정 시각", example = "2026-07-23T01:30:00Z")
Instant updatedAt,

@Schema(description = "작성 시간 내림차순으로 정렬된 대댓글 목록")
List<CommentReplyResponse> replies
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,42 @@ public String getCode() {
public String getMessage() {
return message;
}

public static final class Examples {

public static final String BAD_REQUEST = """
{
"success": false,
"code": "COMMON-400",
"message": "잘못된 요청입니다."
}
""";

public static final String UNAUTHORIZED = """
{
"success": false,
"code": "COMMON-401",
"message": "인증이 필요합니다."
}
""";

public static final String FORBIDDEN = """
{
"success": false,
"code": "COMMON-403",
"message": "허용되지 않는 요청입니다."
}
""";

public static final String NOT_FOUND = """
{
"success": false,
"code": "COMMON-404",
"message": "요청한 리소스를 찾을 수 없습니다."
}
""";

private Examples() {
}
}
}
14 changes: 7 additions & 7 deletions src/main/java/com/promsearch/prompt/domain/Prompt.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Prompt {
private final String promptBody;
private final String thumbnailImage;
private final PromptOutputType outputType;
private final String authorTip;
private final String description;
private final PromptContentType contentType;
private final PromptStatus status;
private final Long pricePoint;
Expand All @@ -41,7 +41,7 @@ private Prompt(
String promptBody,
String thumbnailImage,
PromptOutputType outputType,
String authorTip,
String description,
PromptContentType contentType,
PromptStatus status,
Long pricePoint,
Expand All @@ -60,7 +60,7 @@ private Prompt(
this.promptBody = promptBody;
this.thumbnailImage = thumbnailImage;
this.outputType = outputType;
this.authorTip = authorTip;
this.description = description;
this.contentType = contentType;
this.status = status;
this.pricePoint = pricePoint;
Expand All @@ -80,7 +80,7 @@ public static Prompt create(
String promptBody,
String thumbnailImage,
PromptOutputType outputType,
String authorTip,
String description,
PromptContentType contentType,
Long pricePoint
) {
Expand All @@ -93,7 +93,7 @@ public static Prompt create(
.promptBody(promptBody)
.thumbnailImage(thumbnailImage)
.outputType(outputType)
.authorTip(authorTip)
.description(description)
.contentType(contentType)
.status(PromptStatus.DRAFT)
.pricePoint(pricePoint)
Expand All @@ -111,7 +111,7 @@ public static Prompt reconstruct(
String promptBody,
String thumbnailImage,
PromptOutputType outputType,
String authorTip,
String description,
PromptContentType contentType,
PromptStatus status,
Long pricePoint,
Expand All @@ -136,7 +136,7 @@ public static Prompt reconstruct(
.promptBody(promptBody)
.thumbnailImage(thumbnailImage)
.outputType(outputType)
.authorTip(authorTip)
.description(description)
.contentType(contentType)
.status(status)
.pricePoint(pricePoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public class PostJpaEntity extends BaseEntity {
@Column(name = "output_type", length = 20)
private PromptOutputType outputType;

@Column(name = "author_tip", columnDefinition = "TEXT")
private String authorTip;
@Column(name = "description", columnDefinition = "TEXT")
private String description;

@Enumerated(EnumType.STRING)
@Column(name = "content_type", length = 20)
Expand Down Expand Up @@ -83,29 +83,29 @@ public class PostJpaEntity extends BaseEntity {

@Builder(access = AccessLevel.PRIVATE)
private PostJpaEntity(Long userId, String title, String promptBody, String thumbnailImageUrl,
PromptOutputType outputType, String authorTip, PromptContentType contentType,
PromptOutputType outputType, String description, PromptContentType contentType,
Long pricePoint) {
this.userId = userId;
this.title = title;
this.promptBody = promptBody;
this.thumbnailImageUrl = thumbnailImageUrl;
this.outputType = outputType;
this.authorTip = authorTip;
this.description = description;
this.contentType = contentType;
this.status = PromptStatus.DRAFT;
this.pricePoint = pricePoint != null ? pricePoint : 0L;
}

public static PostJpaEntity create(Long userId, String title, String promptBody, String thumbnailImageUrl,
PromptOutputType outputType, String authorTip,
PromptOutputType outputType, String description,
PromptContentType contentType, Long pricePoint) {
return PostJpaEntity.builder()
.userId(userId)
.title(title)
.promptBody(promptBody)
.thumbnailImageUrl(thumbnailImageUrl)
.outputType(outputType)
.authorTip(authorTip)
.description(description)
.contentType(contentType)
.pricePoint(pricePoint)
.build();
Expand All @@ -119,7 +119,7 @@ public Prompt toDomain() {
promptBody,
thumbnailImageUrl,
outputType,
authorTip,
description,
contentType,
status,
pricePoint,
Expand Down
Loading
Loading