Skip to content

Commit

Permalink
♻️ 댓글 생성/수정/삭제 구현 (#263) (#268)
Browse files Browse the repository at this point in the history
* ♻️ 코멘트 도메인 분리 (#263)

* ✨ 코멘트 공개/비공개, 유실물 ID 컬럼 추가로 인한 엔티티 변경 (#263)

* ♻️ 게시글 타입 분기 및 공개/비공개 여부 추가로 인한 코멘트 생성 로직 변경 (#263)

* ♻️ 코멘트 생성 API 스펙 변경으로 인한 Controller, REST Docs 변경 (#263)

* ♻️ 코멘트 컬럼 및 테이블명 변경 (#263)

* ♻️ 코멘트 비공개/공개 여부 isPrivate Boolean 필드 추가 (#263)

* ♻️ 코멘트 조회 및 생성 API 계층 구조 변경 (#263)

* ✨ 자식 코멘트 생성 시, 비공개 여부 필드 요청 시 예외처리 (#263)

* ✨ 부모 댓글 존재 시, 부모 visibility 따라가도록 설정 (#263)
  • Loading branch information
discphy authored Nov 24, 2024
1 parent ad4889b commit 0f69d34
Show file tree
Hide file tree
Showing 62 changed files with 1,224 additions and 795 deletions.
27 changes: 27 additions & 0 deletions application/src/docs/asciidoc/comment/comments.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
=== /comments

==== 코멘트 수정

.Request
include::{snippets}/update-comment/http-request.adoc[]
.Request Headers
include::{snippets}/update-comment/request-headers.adoc[]
.Path Parameters
include::{snippets}/update-comment/path-parameters.adoc[]
.Response
include::{snippets}/update-comment/http-response.adoc[]
.Response Fields
include::{snippets}/update-comment/response-fields.adoc[]

==== 코멘트 삭제

.Request
include::{snippets}/delete-comment/http-request.adoc[]
.Request Headers
include::{snippets}/delete-comment/request-headers.adoc[]
.Path Parameters
include::{snippets}/delete-comment/path-parameters.adoc[]
.Response
include::{snippets}/delete-comment/http-response.adoc[]
.Response Fields
include::{snippets}/delete-comment/response-fields.adoc[]
51 changes: 0 additions & 51 deletions application/src/docs/asciidoc/community/comments.adoc

This file was deleted.

26 changes: 26 additions & 0 deletions application/src/docs/asciidoc/community/posts-comments.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
==== 게시글 코멘트 조회

.Request
include::{snippets}/get-community-post-comments/http-request.adoc[]
.Path Parameters
include::{snippets}/get-community-post-comments/path-parameters.adoc[]
.Response
include::{snippets}/get-community-post-comments/http-response.adoc[]
.Response Fields
include::{snippets}/get-community-post-comments/response-fields.adoc[]

==== 게시글 코멘트 작성

.Request
include::{snippets}/create-community-post-comment/http-request.adoc[]
.Request Headers
include::{snippets}/create-community-post-comment/request-headers.adoc[]
.Path Parameters
include::{snippets}/create-community-post-comment/path-parameters.adoc[]
.Request Fields
include::{snippets}/create-community-post-comment/request-fields.adoc[]
.Response
include::{snippets}/create-community-post-comment/http-response.adoc[]
.Response Fields
include::{snippets}/create-community-post-comment/response-fields.adoc[]

10 changes: 8 additions & 2 deletions application/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,24 @@ include::member/members.adoc[]

include::member/error.adoc[]

== Comment

include::comment/comments.adoc[]

== Community

include::community/posts.adoc[]

include::community/posts-like.adoc[]
include::community/posts-comments.adoc[]

include::community/comments.adoc[]
include::community/posts-like.adoc[]

== Lost

include::lost/posts.adoc[]

include::lost/posts-comments.adoc[]

== Report

include::report/reports.adoc[]
Expand Down
26 changes: 26 additions & 0 deletions application/src/docs/asciidoc/lost/posts-comments.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
==== 유실물 코멘트 조회

.Request
include::{snippets}/get-lost-post-comments/http-request.adoc[]
.Path Parameters
include::{snippets}/get-lost-post-comments/path-parameters.adoc[]
.Response
include::{snippets}/get-lost-post-comments/http-response.adoc[]
.Response Fields
include::{snippets}/get-lost-post-comments/response-fields.adoc[]

==== 유실물 코멘트 작성

.Request
include::{snippets}/create-lost-post-comment/http-request.adoc[]
.Request Headers
include::{snippets}/create-lost-post-comment/request-headers.adoc[]
.Path Parameters
include::{snippets}/create-lost-post-comment/path-parameters.adoc[]
.Request Fields
include::{snippets}/create-lost-post-comment/request-fields.adoc[]
.Response
include::{snippets}/create-lost-post-comment/http-response.adoc[]
.Response Fields
include::{snippets}/create-lost-post-comment/response-fields.adoc[]

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package backend.team.ahachul_backend.api.comment.adapter.web.`in`

import backend.team.ahachul_backend.api.comment.adapter.web.`in`.dto.DeleteCommentDto
import backend.team.ahachul_backend.api.comment.adapter.web.`in`.dto.UpdateCommentDto
import backend.team.ahachul_backend.api.comment.application.command.DeleteCommentCommand
import backend.team.ahachul_backend.api.comment.application.port.`in`.CommentUseCase
import backend.team.ahachul_backend.common.annotation.Authentication
import backend.team.ahachul_backend.common.response.CommonResponse
import org.springframework.web.bind.annotation.*

@RestController
class CommentController(
private val commentUseCase: CommentUseCase
) {

@Authentication
@PatchMapping("/v1/comments/{commentId}")
fun updateComment(@PathVariable commentId: Long, @RequestBody request: UpdateCommentDto.Request): CommonResponse<UpdateCommentDto.Response> {
return CommonResponse.success(commentUseCase.updateComment(request.toCommand(commentId)))
}

@Authentication
@DeleteMapping("/v1/comments/{commentId}")
fun deleteComment(@PathVariable commentId: Long): CommonResponse<DeleteCommentDto.Response> {
return CommonResponse.success(commentUseCase.deleteComment(DeleteCommentCommand(commentId)))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package backend.team.ahachul_backend.api.comment.adapter.web.`in`.dto

import backend.team.ahachul_backend.api.comment.application.command.CreateCommentCommand
import backend.team.ahachul_backend.api.comment.domain.entity.CommentEntity import backend.team.ahachul_backend.api.comment.domain.model.CommentVisibility
import backend.team.ahachul_backend.api.comment.domain.model.PostType
import backend.team.ahachul_backend.common.exception.CommonException
import backend.team.ahachul_backend.common.response.ResponseCode

class CreateCommentDto {

data class Request(
val upperCommentId: Long?,
val content: String,
val isPrivate: Boolean?
) {
init {
validateChildComment()
}

fun toCommand(postId: Long, postType: PostType): CreateCommentCommand {
return CreateCommentCommand(
postId = postId,
postType = postType,
upperCommentId = upperCommentId,
content = content,
visibility = CommentVisibility.from(isPrivate)
)
}

private fun validateChildComment() {
if (isInvalidChildComment()) {
throw CommonException(ResponseCode.BAD_REQUEST)
}
}

private fun isInvalidChildComment(): Boolean {
return upperCommentId != null && isPrivate != null
}
}

data class Response(
val id: Long,
val upperCommentId: Long?,
val content: String,
) {
companion object {
fun from(entity: CommentEntity): Response {
return Response(
id = entity.id,
upperCommentId = entity.upperComment?.id,
content = entity.content
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package backend.team.ahachul_backend.api.comment.adapter.web.`in`.dto

class DeleteCommentDto {

data class Response(
val id: Long,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package backend.team.ahachul_backend.api.comment.adapter.web.`in`.dto

import backend.team.ahachul_backend.api.comment.domain.model.CommentType
import java.time.LocalDateTime

class GetCommentsDto {

data class Response(
val comments: List<CommentList>
)

data class CommentList(
val parentComment: Comment,
val childComments: List<Comment>
)

data class Comment(
val id: Long,
val upperCommentId: Long?,
val content: String,
val status: CommentType,
val createdAt: LocalDateTime,
val createdBy: String,
val writer: String,
)
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package backend.team.ahachul_backend.api.community.adapter.web.`in`.dto.comment
package backend.team.ahachul_backend.api.comment.adapter.web.`in`.dto

import backend.team.ahachul_backend.api.community.domain.entity.CommunityCommentEntity
import backend.team.ahachul_backend.api.comment.application.command.UpdateCommentCommand
import backend.team.ahachul_backend.api.comment.domain.entity.CommentEntity

class UpdateCommunityCommentDto {
class UpdateCommentDto {

data class Request(
val content: String,
) {
fun toCommand(id: Long): UpdateCommunityCommentCommand {
return UpdateCommunityCommentCommand(
fun toCommand(id: Long): UpdateCommentCommand {
return UpdateCommentCommand(
id = id,
content = content
)
Expand All @@ -20,7 +21,7 @@ class UpdateCommunityCommentDto {
val content: String,
) {
companion object {
fun from(entity: CommunityCommentEntity): Response {
fun from(entity: CommentEntity): Response {
return Response(
id = entity.id,
content = entity.content
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package backend.team.ahachul_backend.api.comment.application.port.`in`

import backend.team.ahachul_backend.api.comment.adapter.web.`in`.dto.CreateCommentDto
import backend.team.ahachul_backend.api.comment.adapter.web.`in`.dto.DeleteCommentDto
import backend.team.ahachul_backend.api.comment.adapter.web.`in`.dto.GetCommentsDto
import backend.team.ahachul_backend.api.comment.adapter.web.`in`.dto.UpdateCommentDto
import backend.team.ahachul_backend.api.comment.application.command.CreateCommentCommand
import backend.team.ahachul_backend.api.comment.application.command.DeleteCommentCommand
import backend.team.ahachul_backend.api.comment.application.command.GetCommentsCommand
import backend.team.ahachul_backend.api.comment.application.command.UpdateCommentCommand

interface CommentUseCase {

fun getComments(command: GetCommentsCommand): GetCommentsDto.Response

fun createComment(command: CreateCommentCommand): CreateCommentDto.Response

fun updateComment(command: UpdateCommentCommand): UpdateCommentDto.Response

fun deleteComment(command: DeleteCommentCommand): DeleteCommentDto.Response
}
Loading

0 comments on commit 0f69d34

Please sign in to comment.