-
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.
Browse files
Browse the repository at this point in the history
[FEAT]: �댓글 관련 API 구현
- Loading branch information
Showing
79 changed files
with
1,420 additions
and
81 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
community-application/src/main/kotlin/gloddy/article/port/in/ArticleCommandUseCase.kt
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,10 +1,12 @@ | ||
package gloddy.article.port.`in` | ||
|
||
import gloddy.article.port.`in`.dto.command.ArticleCreateRequest | ||
import gloddy.article.port.`in`.dto.command.ArticleUpsertCommentRequest | ||
import gloddy.article.port.`in`.dto.read.ArticleCreateResponse | ||
|
||
interface ArticleCommandUseCase { | ||
fun create(userId: Long, command: ArticleCreateRequest): ArticleCreateResponse | ||
fun delete(userId: Long, articleId: Long) | ||
fun upsertLike(userId: Long, articleId: Long) | ||
fun upsertComment(request: ArticleUpsertCommentRequest) | ||
} |
10 changes: 10 additions & 0 deletions
10
...ication/src/main/kotlin/gloddy/article/port/in/dto/command/ArticleUpsertCommentRequest.kt
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 gloddy.article.port.`in`.dto.command | ||
|
||
data class ArticleUpsertCommentRequest( | ||
val articleId: Long, | ||
val status: CommentStatus | ||
) | ||
|
||
enum class CommentStatus { | ||
CREATE, DELETE | ||
} |
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
6 changes: 6 additions & 0 deletions
6
community-application/src/main/kotlin/gloddy/comment/dto/ChildCommentGetRequest.kt
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,6 @@ | ||
package gloddy.comment.dto | ||
|
||
data class ChildCommentGetRequest( | ||
val parentId: Long, | ||
val userId: Long | ||
) |
9 changes: 9 additions & 0 deletions
9
community-application/src/main/kotlin/gloddy/comment/dto/CommentChildUpsertRequest.kt
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,9 @@ | ||
package gloddy.comment.dto | ||
|
||
import gloddy.article.port.`in`.dto.command.CommentStatus | ||
import gloddy.core.CommentId | ||
|
||
data class CommentChildUpsertRequest( | ||
val commentId: CommentId, | ||
val status: CommentStatus | ||
) |
19 changes: 19 additions & 0 deletions
19
community-application/src/main/kotlin/gloddy/comment/dto/CommentCreateRequest.kt
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,19 @@ | ||
package gloddy.comment.dto | ||
|
||
import gloddy.core.ArticleId | ||
import gloddy.core.CommentId | ||
import gloddy.core.UserId | ||
|
||
data class ParentCommentCreateRequest( | ||
val userId: UserId, | ||
val articleId: ArticleId, | ||
val content: String | ||
) | ||
|
||
data class ChildCommentCreateRequest( | ||
val userId: UserId, | ||
val articleId: ArticleId, | ||
val parentCommentId: CommentId, | ||
val content: String | ||
) | ||
|
11 changes: 11 additions & 0 deletions
11
community-application/src/main/kotlin/gloddy/comment/dto/CommentCreateResponse.kt
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,11 @@ | ||
package gloddy.comment.dto | ||
|
||
import gloddy.comment.Comment | ||
|
||
data class CommentCreateResponse( | ||
val commentId: Long | ||
) { | ||
constructor(comment: Comment) : this( | ||
commentId = comment.id!!.value | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
community-application/src/main/kotlin/gloddy/comment/dto/CommentDeleteRequest.kt
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,11 @@ | ||
package gloddy.comment.dto | ||
|
||
import gloddy.core.ArticleId | ||
import gloddy.core.CommentId | ||
import gloddy.core.UserId | ||
|
||
data class CommentDeleteRequest( | ||
val commentId: CommentId, | ||
val userId: UserId, | ||
val articleId: ArticleId | ||
) |
30 changes: 30 additions & 0 deletions
30
community-application/src/main/kotlin/gloddy/comment/dto/CommentGetResponse.kt
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,30 @@ | ||
package gloddy.comment.dto | ||
|
||
import gloddy.comment.Comment | ||
|
||
data class CommentGetResponse( | ||
val comments: List<CommentUnit> | ||
) | ||
|
||
data class CommentUnit( | ||
val commentId: Long, | ||
val content: String, | ||
val depth: Int, | ||
val likeCount: Long, | ||
val commentCount: Long, | ||
val isLiked: Boolean, | ||
val user: UserUnit | ||
) | ||
|
||
data class UserUnit( | ||
val userId: Long, | ||
val name: String, | ||
val imageUrl: String, | ||
val reliabilityLevel: String, | ||
val country: UserCountry | ||
) | ||
|
||
data class UserCountry( | ||
val name: String, | ||
val imageUrl: String | ||
) |
9 changes: 9 additions & 0 deletions
9
community-application/src/main/kotlin/gloddy/comment/dto/CommentLikeUpsertRequest.kt
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,9 @@ | ||
package gloddy.comment.dto | ||
|
||
import gloddy.core.CommentId | ||
import gloddy.core.UserId | ||
|
||
data class CommentLikeUpsertRequest( | ||
val userId: UserId, | ||
val commentId: CommentId | ||
) |
9 changes: 9 additions & 0 deletions
9
community-application/src/main/kotlin/gloddy/comment/dto/ParentCommentGetRequest.kt
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,9 @@ | ||
package gloddy.comment.dto | ||
|
||
import gloddy.core.ArticleId | ||
import gloddy.core.UserId | ||
|
||
data class ParentCommentGetRequest( | ||
val userId: UserId, | ||
val articleId: ArticleId | ||
) |
16 changes: 16 additions & 0 deletions
16
community-application/src/main/kotlin/gloddy/comment/dto/readModel/ChildCommentUnit.kt
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,16 @@ | ||
package gloddy.comment.dto.readModel | ||
|
||
import java.time.LocalDateTime | ||
|
||
data class ChildCommentUnit( | ||
val id: Long, | ||
val isWriter: Boolean, | ||
val isLiked: Boolean, | ||
val userId: Long, | ||
val articleId: Long, | ||
val parentId: Long, | ||
val content: String, | ||
val likeCount: Int, | ||
val createdAt: LocalDateTime, | ||
val updatedAt: LocalDateTime | ||
) |
8 changes: 8 additions & 0 deletions
8
...cation/src/main/kotlin/gloddy/comment/dto/readModel/FindChildCommentByParentIdResponse.kt
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,8 @@ | ||
package gloddy.comment.dto.readModel | ||
|
||
import gloddy.user.port.`in`.dto.UserPreviewUnit | ||
|
||
data class FindChildCommentByParentIdResponse( | ||
val childComment: ChildCommentUnit, | ||
val writer: UserPreviewUnit | ||
) |
5 changes: 5 additions & 0 deletions
5
...ation/src/main/kotlin/gloddy/comment/dto/readModel/FindChildCommentsByParentIdResponse.kt
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,5 @@ | ||
package gloddy.comment.dto.readModel | ||
|
||
data class FindChildCommentsByParentIdResponse( | ||
val childComments: List<FindChildCommentByParentIdResponse> | ||
) |
8 changes: 8 additions & 0 deletions
8
...tion/src/main/kotlin/gloddy/comment/dto/readModel/FindParentCommentByArticleIdResponse.kt
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,8 @@ | ||
package gloddy.comment.dto.readModel | ||
|
||
import gloddy.user.port.`in`.dto.UserPreviewUnit | ||
|
||
data class FindParentCommentByArticleIdResponse( | ||
val comment: ParentCommentUnit, | ||
val writer: UserPreviewUnit | ||
) |
5 changes: 5 additions & 0 deletions
5
...ion/src/main/kotlin/gloddy/comment/dto/readModel/FindParentCommentsByArticleIdResponse.kt
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,5 @@ | ||
package gloddy.comment.dto.readModel | ||
|
||
data class FindParentCommentsByArticleIdResponse( | ||
val comments: List<FindParentCommentByArticleIdResponse> | ||
) |
16 changes: 16 additions & 0 deletions
16
community-application/src/main/kotlin/gloddy/comment/dto/readModel/ParentCommentUnit.kt
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,16 @@ | ||
package gloddy.comment.dto.readModel | ||
|
||
import java.time.LocalDateTime | ||
|
||
data class ParentCommentUnit( | ||
val id: Long, | ||
val isWriter: Boolean, | ||
val isLiked: Boolean, | ||
val userId: Long, | ||
val articleId: Long, | ||
val content: String, | ||
val likeCount: Int, | ||
val commentCount: Int, | ||
val createdAt: LocalDateTime, | ||
val updatedAt: LocalDateTime, | ||
) |
10 changes: 10 additions & 0 deletions
10
community-application/src/main/kotlin/gloddy/comment/port/out/CommentCommandPort.kt
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 gloddy.comment.port.out | ||
|
||
import gloddy.comment.Comment | ||
import gloddy.comment.CommentLike | ||
|
||
interface CommentCommandPort { | ||
fun save(comment: Comment): Comment | ||
fun delete(comment: Comment) | ||
fun upsertLike(commentLike: CommentLike, comment: Comment) | ||
} |
8 changes: 8 additions & 0 deletions
8
community-application/src/main/kotlin/gloddy/comment/port/out/CommentLikeCommandPort.kt
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,8 @@ | ||
package gloddy.comment.port.out | ||
|
||
import gloddy.comment.CommentLike | ||
|
||
interface CommentLikeCommandPort { | ||
fun save(commentLike: CommentLike): CommentLike | ||
fun delete(commentLike: CommentLike) | ||
} |
9 changes: 9 additions & 0 deletions
9
community-application/src/main/kotlin/gloddy/comment/port/out/CommentLikeQueryPort.kt
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,9 @@ | ||
package gloddy.comment.port.out | ||
|
||
import gloddy.comment.CommentLike | ||
import gloddy.core.CommentId | ||
import gloddy.core.UserId | ||
|
||
interface CommentLikeQueryPort { | ||
fun findByCommentIdAndUserIdOrNull(commentId: CommentId, userId: UserId): CommentLike? | ||
} |
13 changes: 13 additions & 0 deletions
13
community-application/src/main/kotlin/gloddy/comment/port/out/CommentQueryPort.kt
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,13 @@ | ||
package gloddy.comment.port.out | ||
|
||
import gloddy.comment.Comment | ||
import gloddy.comment.dto.readModel.ChildCommentUnit | ||
import gloddy.comment.dto.readModel.ParentCommentUnit | ||
import gloddy.core.CommentId | ||
|
||
|
||
interface CommentQueryPort { | ||
fun findById(id: CommentId): Comment | ||
fun findParentComments(articleId: Long, userId: Long): List<ParentCommentUnit> | ||
fun findChildComments(parentId: Long, userId: Long): List<ChildCommentUnit> | ||
} |
49 changes: 49 additions & 0 deletions
49
community-application/src/main/kotlin/gloddy/comment/service/CommentCreateService.kt
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,49 @@ | ||
package gloddy.comment.service | ||
|
||
import gloddy.article.port.out.ArticleQueryPersistencePort | ||
import gloddy.comment.Comment | ||
import gloddy.comment.dto.ChildCommentCreateRequest | ||
import gloddy.comment.dto.CommentCreateResponse | ||
import gloddy.comment.dto.ParentCommentCreateRequest | ||
import gloddy.comment.port.out.CommentCommandPort | ||
import gloddy.comment.port.out.CommentQueryPort | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class CommentCreateService( | ||
private val commentCommandPort: CommentCommandPort, | ||
private val articleQueryPort: ArticleQueryPersistencePort, | ||
) { | ||
fun createParent(request: ParentCommentCreateRequest): CommentCreateResponse { | ||
val article = articleQueryPort.findById(request.articleId.value) | ||
|
||
return Comment.parent( | ||
userId = request.userId, | ||
article = article, | ||
content = request.content | ||
) | ||
.let { | ||
commentCommandPort.save(it) | ||
} | ||
.run { | ||
CommentCreateResponse(this) | ||
} | ||
} | ||
|
||
fun createChild(request: ChildCommentCreateRequest): CommentCreateResponse { | ||
val article = articleQueryPort.findById(request.articleId.value) | ||
|
||
return Comment.child( | ||
userId = request.userId, | ||
article = article, | ||
content = request.content, | ||
parentCommentId = request.parentCommentId | ||
) | ||
.let { | ||
commentCommandPort.save(it) | ||
} | ||
.run { | ||
CommentCreateResponse(this) | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
community-application/src/main/kotlin/gloddy/comment/service/CommentDeleteService.kt
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 gloddy.comment.service | ||
|
||
import gloddy.comment.dto.CommentDeleteRequest | ||
import gloddy.comment.port.out.CommentCommandPort | ||
import gloddy.comment.port.out.CommentQueryPort | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class CommentDeleteService( | ||
private val commentCommandPort: CommentCommandPort, | ||
private val commentQueryPort: CommentQueryPort, | ||
) { | ||
|
||
fun delete(request: CommentDeleteRequest) { | ||
val comment = commentQueryPort.findById(request.commentId) | ||
commentCommandPort.delete(comment.delete(request.userId)) | ||
} | ||
} |
Oops, something went wrong.