From 6c41c542d245c92958f2edcb484a0c2e91a2741e Mon Sep 17 00:00:00 2001 From: kpeel Date: Sun, 31 Aug 2025 23:22:46 +0900 Subject: [PATCH 1/2] feat: implement post comment reporting with reasons and custom input handling --- .../comment/PostCommentReportController.kt | 13 ++--- .../com/wespot/post/PostReportController.kt | 10 ++-- .../comment/dto/PostCommentReportRequest.kt | 8 +++ .../port/in/PostCommentReportUseCase.kt | 4 +- .../port/out/PostCommentReportReasonPort.kt | 14 +++++ .../service/PostCommentReportService.kt | 30 +++++++++-- .../post/dto/request/PostReportRequest.kt | 4 +- .../wespot/post/port/in/PostReportUseCase.kt | 2 +- .../post/port/out/PostReportReasonPort.kt | 11 ++++ .../wespot/post/service/PostReportService.kt | 36 +++++++++---- .../wespot/report/dto/ReportReasonRequest.kt | 7 +++ .../report/port/out/ReportReasonPort.kt | 2 + .../com/wespot/comment/PostCommentReport.kt | 8 +++ .../wespot/comment/PostCommentReportReason.kt | 19 +++++++ .../main/kotlin/com/wespot/post/PostReport.kt | 10 +++- .../com/wespot/post/PostReportReason.kt | 15 ++++++ .../kotlin/com/wespot/report/ReportReason.kt | 1 + .../report/ReportReasonWithCustomReason.kt | 14 +++++ .../comment/PostCommentReportReasonEntity.kt | 25 +++++++++ .../adapter/PostCommentReportAdapter.kt | 24 +++++++-- .../adapter/PostCommentReportReasonAdapter.kt | 51 +++++++++++++++++++ .../comment/mapper/PostCommentReportMapper.kt | 7 ++- .../mapper/PostCommentReportReasonMapper.kt | 43 ++++++++++++++++ .../PostCommentReportReasonJpaRepository.kt | 10 ++++ .../com/wespot/post/PostReportEntity.kt | 3 -- .../com/wespot/post/PostReportReasonEntity.kt | 31 +++++++++++ .../wespot/post/adapter/PostReportAdapter.kt | 15 +++--- .../post/adapter/PostReportReasonAdapter.kt | 50 ++++++++++++++++++ .../wespot/post/mapper/PostReportMapper.kt | 7 ++- .../post/mapper/PostReportReasonMapper.kt | 40 +++++++++++++++ .../PostReportReasonJpaRepository.kt | 10 ++++ .../com/wespot/report/ReportReasonAdapter.kt | 5 ++ .../wespot/report/ReportReasonJpaEntity.kt | 4 +- .../com/wespot/report/ReportReasonMapper.kt | 6 ++- 34 files changed, 490 insertions(+), 49 deletions(-) create mode 100644 core/src/main/kotlin/com/wespot/comment/dto/PostCommentReportRequest.kt create mode 100644 core/src/main/kotlin/com/wespot/comment/port/out/PostCommentReportReasonPort.kt create mode 100644 core/src/main/kotlin/com/wespot/post/port/out/PostReportReasonPort.kt create mode 100644 core/src/main/kotlin/com/wespot/report/dto/ReportReasonRequest.kt create mode 100644 domain/src/main/kotlin/com/wespot/comment/PostCommentReportReason.kt create mode 100644 domain/src/main/kotlin/com/wespot/post/PostReportReason.kt create mode 100644 domain/src/main/kotlin/com/wespot/report/ReportReasonWithCustomReason.kt create mode 100644 infrastructure/mysql/src/main/kotlin/com/wespot/comment/PostCommentReportReasonEntity.kt create mode 100644 infrastructure/mysql/src/main/kotlin/com/wespot/comment/adapter/PostCommentReportReasonAdapter.kt create mode 100644 infrastructure/mysql/src/main/kotlin/com/wespot/comment/mapper/PostCommentReportReasonMapper.kt create mode 100644 infrastructure/mysql/src/main/kotlin/com/wespot/comment/repository/PostCommentReportReasonJpaRepository.kt create mode 100644 infrastructure/mysql/src/main/kotlin/com/wespot/post/PostReportReasonEntity.kt create mode 100644 infrastructure/mysql/src/main/kotlin/com/wespot/post/adapter/PostReportReasonAdapter.kt create mode 100644 infrastructure/mysql/src/main/kotlin/com/wespot/post/mapper/PostReportReasonMapper.kt create mode 100644 infrastructure/mysql/src/main/kotlin/com/wespot/post/repository/PostReportReasonJpaRepository.kt diff --git a/app/src/main/kotlin/com/wespot/comment/PostCommentReportController.kt b/app/src/main/kotlin/com/wespot/comment/PostCommentReportController.kt index b1a95f3f..bc45c0b9 100644 --- a/app/src/main/kotlin/com/wespot/comment/PostCommentReportController.kt +++ b/app/src/main/kotlin/com/wespot/comment/PostCommentReportController.kt @@ -1,12 +1,10 @@ package com.wespot.comment +import com.wespot.comment.dto.PostCommentReportRequest import com.wespot.comment.port.`in`.PostCommentReportUseCase import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController +import org.springframework.web.bind.annotation.* @RestController @RequestMapping("/api/v1/post/comment") @@ -15,8 +13,11 @@ class PostCommentReportController( ) { @PostMapping("/{commentId}/report") - fun reportPostComment(@PathVariable commentId: Long): ResponseEntity { - postCommentReportUseCase.reportComment(commentId) + fun reportPostComment( + @PathVariable commentId: Long, + @RequestBody(required = false) request: PostCommentReportRequest? + ): ResponseEntity { + postCommentReportUseCase.reportComment(commentId, request) return ResponseEntity.status(HttpStatus.CREATED) .build() diff --git a/app/src/main/kotlin/com/wespot/post/PostReportController.kt b/app/src/main/kotlin/com/wespot/post/PostReportController.kt index f5942a67..d96ca36b 100644 --- a/app/src/main/kotlin/com/wespot/post/PostReportController.kt +++ b/app/src/main/kotlin/com/wespot/post/PostReportController.kt @@ -4,10 +4,7 @@ import com.wespot.post.dto.request.PostReportRequest import com.wespot.post.port.`in`.PostReportUseCase import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController +import org.springframework.web.bind.annotation.* @RestController @RequestMapping("/api/v1/post") @@ -16,7 +13,10 @@ class PostReportController( ) { @PostMapping("/{postId}/report") - fun reportPost(@PathVariable postId: Long, request: PostReportRequest): ResponseEntity { + fun reportPost( + @PathVariable postId: Long, + @RequestBody(required = false) request: PostReportRequest? + ): ResponseEntity { postReportUseCase.reportPost(postId, request) return ResponseEntity.status(HttpStatus.CREATED) diff --git a/core/src/main/kotlin/com/wespot/comment/dto/PostCommentReportRequest.kt b/core/src/main/kotlin/com/wespot/comment/dto/PostCommentReportRequest.kt new file mode 100644 index 00000000..d9e6171a --- /dev/null +++ b/core/src/main/kotlin/com/wespot/comment/dto/PostCommentReportRequest.kt @@ -0,0 +1,8 @@ +package com.wespot.comment.dto + +import com.wespot.report.dto.ReportReasonRequest + +data class PostCommentReportRequest( + val reportReasonRequests: List, +) { +} diff --git a/core/src/main/kotlin/com/wespot/comment/port/in/PostCommentReportUseCase.kt b/core/src/main/kotlin/com/wespot/comment/port/in/PostCommentReportUseCase.kt index a49896e0..fd394d7f 100644 --- a/core/src/main/kotlin/com/wespot/comment/port/in/PostCommentReportUseCase.kt +++ b/core/src/main/kotlin/com/wespot/comment/port/in/PostCommentReportUseCase.kt @@ -1,7 +1,9 @@ package com.wespot.comment.port.`in` +import com.wespot.comment.dto.PostCommentReportRequest + interface PostCommentReportUseCase { - fun reportComment(commentId: Long) + fun reportComment(commentId: Long, request: PostCommentReportRequest?) } diff --git a/core/src/main/kotlin/com/wespot/comment/port/out/PostCommentReportReasonPort.kt b/core/src/main/kotlin/com/wespot/comment/port/out/PostCommentReportReasonPort.kt new file mode 100644 index 00000000..495f3f1c --- /dev/null +++ b/core/src/main/kotlin/com/wespot/comment/port/out/PostCommentReportReasonPort.kt @@ -0,0 +1,14 @@ +package com.wespot.comment.port.out + +import com.wespot.comment.PostCommentReportReason + +interface PostCommentReportReasonPort { + + fun saveAll( + postCommentReportId: Long, + postCommentReportReasons: List + ): List + + fun findAllByPostCommentReportId(postCommentReportId: Long): List + +} diff --git a/core/src/main/kotlin/com/wespot/comment/service/PostCommentReportService.kt b/core/src/main/kotlin/com/wespot/comment/service/PostCommentReportService.kt index ab778b86..d2ea4003 100644 --- a/core/src/main/kotlin/com/wespot/comment/service/PostCommentReportService.kt +++ b/core/src/main/kotlin/com/wespot/comment/service/PostCommentReportService.kt @@ -2,10 +2,14 @@ package com.wespot.comment.service import com.wespot.auth.service.SecurityUtils import com.wespot.comment.PostCommentReport +import com.wespot.comment.PostCommentReportReason +import com.wespot.comment.dto.PostCommentReportRequest import com.wespot.comment.port.`in`.PostCommentReportUseCase import com.wespot.comment.port.out.PostCommentPort import com.wespot.comment.port.out.PostCommentReportPort import com.wespot.exception.CustomException +import com.wespot.report.ReportReasonWithCustomReason +import com.wespot.report.port.out.ReportReasonPort import com.wespot.user.port.out.UserPort import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @@ -14,13 +18,15 @@ import org.springframework.transaction.annotation.Transactional class PostCommentReportService( private val userPort: UserPort, private val postCommentReportPort: PostCommentReportPort, - private val postCommentPort: PostCommentPort + private val postCommentPort: PostCommentPort, + private val reportReasonPort: ReportReasonPort ) : PostCommentReportUseCase { @Transactional - override fun reportComment(commentId: Long) { + override fun reportComment(commentId: Long, request: PostCommentReportRequest?) { val loginUser = SecurityUtils.getLoginUser(userPort = userPort) val postComment = postCommentPort.findById(commentId) ?: throw CustomException(message = "존재하지 않는 댓글입니다.") + postCommentReportPort.findByPostCommentIdAndUserId(postCommentId = commentId, userId = loginUser.id) ?.let { postCommentReportPort.deleteById(it.id) @@ -28,8 +34,26 @@ class PostCommentReportService( postCommentPort.save(removedReportPostComment) } ?: run { - val postCommentReport = PostCommentReport(postCommentId = commentId, userId = loginUser.id) + if (request == null) { + throw CustomException(message = "신고 사유를 선택해주세요.") + } + + val postCommentReport = + PostCommentReport(postCommentId = commentId, userId = loginUser.id) + val postCommentReportReasons = request.reportReasonRequests + .map { + PostCommentReportReason( + reportReasonWithCustomReason = ReportReasonWithCustomReason( + reportReason = reportReasonPort.findById(it.reportReasonId) ?: throw CustomException( + message = "존재하지 않는 신고 사유입니다." + ), + customReason = it.customReason + ) + ) + } + postCommentReport.addReportReasons(postCommentReportReason = postCommentReportReasons) postCommentReportPort.save(postCommentReport) + val addedReportPostComment = postComment.addReport() postCommentPort.save(addedReportPostComment) } diff --git a/core/src/main/kotlin/com/wespot/post/dto/request/PostReportRequest.kt b/core/src/main/kotlin/com/wespot/post/dto/request/PostReportRequest.kt index 597c4866..0e4550fa 100644 --- a/core/src/main/kotlin/com/wespot/post/dto/request/PostReportRequest.kt +++ b/core/src/main/kotlin/com/wespot/post/dto/request/PostReportRequest.kt @@ -1,6 +1,8 @@ package com.wespot.post.dto.request +import com.wespot.report.dto.ReportReasonRequest + data class PostReportRequest( - val reportReasonId: Long, + val reportReasonRequests: List, ) { } diff --git a/core/src/main/kotlin/com/wespot/post/port/in/PostReportUseCase.kt b/core/src/main/kotlin/com/wespot/post/port/in/PostReportUseCase.kt index 8dd14f45..6f5e54b1 100644 --- a/core/src/main/kotlin/com/wespot/post/port/in/PostReportUseCase.kt +++ b/core/src/main/kotlin/com/wespot/post/port/in/PostReportUseCase.kt @@ -4,6 +4,6 @@ import com.wespot.post.dto.request.PostReportRequest interface PostReportUseCase { - fun reportPost(postId: Long, postReportRequest: PostReportRequest) + fun reportPost(postId: Long, postReportRequest: PostReportRequest?) } diff --git a/core/src/main/kotlin/com/wespot/post/port/out/PostReportReasonPort.kt b/core/src/main/kotlin/com/wespot/post/port/out/PostReportReasonPort.kt new file mode 100644 index 00000000..cfd642c4 --- /dev/null +++ b/core/src/main/kotlin/com/wespot/post/port/out/PostReportReasonPort.kt @@ -0,0 +1,11 @@ +package com.wespot.post.port.out + +import com.wespot.post.PostReportReason + +interface PostReportReasonPort { + + fun saveAll(postReportId: Long, postReportReasons: List): List + + fun findByPostReportId(postReportId: Long): List + +} diff --git a/core/src/main/kotlin/com/wespot/post/service/PostReportService.kt b/core/src/main/kotlin/com/wespot/post/service/PostReportService.kt index b444459f..81fae4e7 100644 --- a/core/src/main/kotlin/com/wespot/post/service/PostReportService.kt +++ b/core/src/main/kotlin/com/wespot/post/service/PostReportService.kt @@ -1,11 +1,14 @@ package com.wespot.post.service import com.wespot.auth.service.SecurityUtils +import com.wespot.exception.CustomException import com.wespot.post.PostReport +import com.wespot.post.PostReportReason import com.wespot.post.dto.request.PostReportRequest import com.wespot.post.port.`in`.PostReportUseCase import com.wespot.post.port.out.PostPort import com.wespot.post.port.out.PostReportPort +import com.wespot.report.ReportReasonWithCustomReason import com.wespot.report.port.out.ReportReasonPort import com.wespot.user.port.out.UserPort import org.springframework.stereotype.Service @@ -20,25 +23,38 @@ class PostReportService( ) : PostReportUseCase { @Transactional - override fun reportPost(postId: Long, postReportRequest: PostReportRequest) { + override fun reportPost(postId: Long, postReportRequest: PostReportRequest?) { val loginUser = SecurityUtils.getLoginUser(userPort = userPort) val post = postPort.findById(postId) - ?: throw IllegalArgumentException("존재하지 않는 게시글입니다.") - val reportReason = reportReasonPort.findById(postReportRequest.reportReasonId) - ?: throw IllegalArgumentException("존재하지 않는 신고 사유입니다.") + ?: throw CustomException(message = "존재하지 않는 게시글입니다.") postReportPort.findByPostIdAndUserId(postId, loginUser.id) ?.let { postReportPort.deleteById(id = it.id) } ?: run { - val postReport = - PostReport( - postId = post.id, - userId = loginUser.id, - reportReason = reportReason - ) + if (postReportRequest == null) { + throw CustomException(message = "신고 사유를 선택해주세요.") + } + + val postReport = PostReport( + postId = post.id, + userId = loginUser.id, + ) + + val postReportReasons = postReportRequest.reportReasonRequests + .map { + PostReportReason( + reportReasonWithCustomReason = ReportReasonWithCustomReason( + reportReason = reportReasonPort.findById(it.reportReasonId) + ?: throw CustomException(message = "존재하지 않는 신고 사유입니다."), + customReason = it.customReason + ) + ) + } + + postReport.addReportReasons(postReportReasons) postReportPort.save(postReport) } } diff --git a/core/src/main/kotlin/com/wespot/report/dto/ReportReasonRequest.kt b/core/src/main/kotlin/com/wespot/report/dto/ReportReasonRequest.kt new file mode 100644 index 00000000..09d6a3fc --- /dev/null +++ b/core/src/main/kotlin/com/wespot/report/dto/ReportReasonRequest.kt @@ -0,0 +1,7 @@ +package com.wespot.report.dto + +data class ReportReasonRequest( + val reportReasonId: Long, + val customReason: String? +) { +} diff --git a/core/src/main/kotlin/com/wespot/report/port/out/ReportReasonPort.kt b/core/src/main/kotlin/com/wespot/report/port/out/ReportReasonPort.kt index 41abb838..ed88bec7 100644 --- a/core/src/main/kotlin/com/wespot/report/port/out/ReportReasonPort.kt +++ b/core/src/main/kotlin/com/wespot/report/port/out/ReportReasonPort.kt @@ -8,4 +8,6 @@ interface ReportReasonPort { fun findById(reportReasonId: Long): ReportReason? + fun findAllByIdIn(ids: List): List + } diff --git a/domain/src/main/kotlin/com/wespot/comment/PostCommentReport.kt b/domain/src/main/kotlin/com/wespot/comment/PostCommentReport.kt index 2bdceb00..26970de6 100644 --- a/domain/src/main/kotlin/com/wespot/comment/PostCommentReport.kt +++ b/domain/src/main/kotlin/com/wespot/comment/PostCommentReport.kt @@ -6,6 +6,14 @@ class PostCommentReport( val id: Long = 0L, val postCommentId: Long, val userId: Long, + val postCommentReportReasons: List = mutableListOf(), val createdAt: LocalDateTime = LocalDateTime.now() ) { + + fun addReportReasons(postCommentReportReason: List) { + postCommentReportReason.forEach { + this.postCommentReportReasons.plus(it) + } + } + } diff --git a/domain/src/main/kotlin/com/wespot/comment/PostCommentReportReason.kt b/domain/src/main/kotlin/com/wespot/comment/PostCommentReportReason.kt new file mode 100644 index 00000000..2c97eba9 --- /dev/null +++ b/domain/src/main/kotlin/com/wespot/comment/PostCommentReportReason.kt @@ -0,0 +1,19 @@ +package com.wespot.comment + +import com.wespot.report.ReportReasonWithCustomReason +import java.time.LocalDateTime + +data class PostCommentReportReason( + val id: Long = 0L, + val postCommentReportId: Long = 0L, + val reportReasonWithCustomReason: ReportReasonWithCustomReason, + + val createdAt: LocalDateTime = LocalDateTime.now(), + val updatedAt: LocalDateTime = LocalDateTime.now(), +) { + + fun registeredInPostCommentReport(postCommentReportId: Long): PostCommentReportReason { + return copy(postCommentReportId = postCommentReportId) + } + +} diff --git a/domain/src/main/kotlin/com/wespot/post/PostReport.kt b/domain/src/main/kotlin/com/wespot/post/PostReport.kt index 241e63b8..1b598a07 100644 --- a/domain/src/main/kotlin/com/wespot/post/PostReport.kt +++ b/domain/src/main/kotlin/com/wespot/post/PostReport.kt @@ -1,13 +1,19 @@ package com.wespot.post -import com.wespot.report.ReportReason import java.time.LocalDateTime class PostReport( val id: Long = 0L, val postId: Long, val userId: Long, - val reportReason: ReportReason, + val postReportReasons: List = mutableListOf(), val createdAt: LocalDateTime = LocalDateTime.now() ) { + + fun addReportReasons(postReportReasons: List) { + postReportReasons.forEach { + this.postReportReasons.plus(it) + } + } + } diff --git a/domain/src/main/kotlin/com/wespot/post/PostReportReason.kt b/domain/src/main/kotlin/com/wespot/post/PostReportReason.kt new file mode 100644 index 00000000..f093d34f --- /dev/null +++ b/domain/src/main/kotlin/com/wespot/post/PostReportReason.kt @@ -0,0 +1,15 @@ +package com.wespot.post + +import com.wespot.report.ReportReasonWithCustomReason +import java.time.LocalDateTime + +data class PostReportReason( + val id: Long = 0L, + val postReportId: Long = 0L, + val reportReasonWithCustomReason: ReportReasonWithCustomReason, + + val createdAt: LocalDateTime = LocalDateTime.now(), + val updatedAt: LocalDateTime = LocalDateTime.now() +) { + +} diff --git a/domain/src/main/kotlin/com/wespot/report/ReportReason.kt b/domain/src/main/kotlin/com/wespot/report/ReportReason.kt index 2af13823..da302256 100644 --- a/domain/src/main/kotlin/com/wespot/report/ReportReason.kt +++ b/domain/src/main/kotlin/com/wespot/report/ReportReason.kt @@ -3,5 +3,6 @@ package com.wespot.report data class ReportReason( val id: Long = 0L, val content: String, + val canReceiveReason: Boolean, ) { } diff --git a/domain/src/main/kotlin/com/wespot/report/ReportReasonWithCustomReason.kt b/domain/src/main/kotlin/com/wespot/report/ReportReasonWithCustomReason.kt new file mode 100644 index 00000000..9aae81c9 --- /dev/null +++ b/domain/src/main/kotlin/com/wespot/report/ReportReasonWithCustomReason.kt @@ -0,0 +1,14 @@ +package com.wespot.report + +data class ReportReasonWithCustomReason( + val reportReason: ReportReason, + val customReason: String?, +) { + + init { + if (!reportReason.canReceiveReason && customReason != null) { + throw IllegalArgumentException("신고 사유를 입력 받을 수 없는 유형입니다.") + } + } + +} diff --git a/infrastructure/mysql/src/main/kotlin/com/wespot/comment/PostCommentReportReasonEntity.kt b/infrastructure/mysql/src/main/kotlin/com/wespot/comment/PostCommentReportReasonEntity.kt new file mode 100644 index 00000000..b6ce7185 --- /dev/null +++ b/infrastructure/mysql/src/main/kotlin/com/wespot/comment/PostCommentReportReasonEntity.kt @@ -0,0 +1,25 @@ +package com.wespot.comment + +import com.wespot.common.BaseEntity +import jakarta.persistence.* +import jakarta.validation.constraints.NotNull + +@Entity +@Table(name = "post_comment_report_reason") +data class PostCommentReportReasonEntity( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long, + + @field: NotNull + val postCommentReportId: Long, + + @field: NotNull + val reportReasonId: Long, + + val customReason: String? = null, + + @Embedded + val baseEntity: BaseEntity +) { +} diff --git a/infrastructure/mysql/src/main/kotlin/com/wespot/comment/adapter/PostCommentReportAdapter.kt b/infrastructure/mysql/src/main/kotlin/com/wespot/comment/adapter/PostCommentReportAdapter.kt index 4556c16a..b7adc5dd 100644 --- a/infrastructure/mysql/src/main/kotlin/com/wespot/comment/adapter/PostCommentReportAdapter.kt +++ b/infrastructure/mysql/src/main/kotlin/com/wespot/comment/adapter/PostCommentReportAdapter.kt @@ -3,17 +3,28 @@ package com.wespot.comment.adapter import com.wespot.comment.PostCommentReport import com.wespot.comment.mapper.PostCommentReportMapper import com.wespot.comment.port.out.PostCommentReportPort +import com.wespot.comment.port.out.PostCommentReportReasonPort import com.wespot.comment.repository.PostCommentReportJpaRepository +import com.wespot.exception.CustomException +import com.wespot.post.port.out.PostReportReasonPort +import com.wespot.report.port.out.ReportReasonPort +import org.springframework.http.HttpStatus import org.springframework.stereotype.Repository @Repository class PostCommentReportAdapter( private val postCommentReportJpaRepository: PostCommentReportJpaRepository, + private val postCommentReportReasonPort: PostCommentReportReasonPort, ) : PostCommentReportPort { override fun findByPostCommentIdAndUserId(postCommentId: Long, userId: Long): PostCommentReport? { return postCommentReportJpaRepository.findByPostCommentIdAndUserId(postCommentId, userId) - ?.let { PostCommentReportMapper.toDomain(it) } + ?.let { + PostCommentReportMapper.toDomain( + it, + postCommentReportReasons = postCommentReportReasonPort.findAllByPostCommentReportId(it.id), + ) + } } override fun deleteById(id: Long) { @@ -23,8 +34,15 @@ class PostCommentReportAdapter( override fun save(postCommentReport: PostCommentReport): PostCommentReport { val postCommentReportEntity = PostCommentReportMapper.toEntity(postCommentReport) val savedPostCommentReportEntity = postCommentReportJpaRepository.save(postCommentReportEntity) - - return PostCommentReportMapper.toDomain(savedPostCommentReportEntity) + val postCommentReportReasons = postCommentReportReasonPort.saveAll( + postCommentReportId = postCommentReport.id, + postCommentReportReasons = postCommentReport.postCommentReportReasons + ) + + return PostCommentReportMapper.toDomain( + entity = savedPostCommentReportEntity, + postCommentReportReasons = postCommentReportReasons + ) } override fun deleteByPostCommentIdIn(postCommentId: List) { diff --git a/infrastructure/mysql/src/main/kotlin/com/wespot/comment/adapter/PostCommentReportReasonAdapter.kt b/infrastructure/mysql/src/main/kotlin/com/wespot/comment/adapter/PostCommentReportReasonAdapter.kt new file mode 100644 index 00000000..ffe1f629 --- /dev/null +++ b/infrastructure/mysql/src/main/kotlin/com/wespot/comment/adapter/PostCommentReportReasonAdapter.kt @@ -0,0 +1,51 @@ +package com.wespot.comment.adapter + +import com.wespot.comment.PostCommentReportReason +import com.wespot.comment.mapper.PostCommentReportReasonMapper +import com.wespot.comment.port.out.PostCommentReportReasonPort +import com.wespot.comment.repository.PostCommentReportReasonJpaRepository +import com.wespot.report.port.out.ReportReasonPort +import org.springframework.stereotype.Repository + +@Repository +class PostCommentReportReasonAdapter( + private val postCommentReportReasonJpaRepository: PostCommentReportReasonJpaRepository, + private val reportReasonPort: ReportReasonPort, +) : PostCommentReportReasonPort { + + override fun saveAll( + postCommentReportId: Long, + postCommentReportReasons: List + ): List { + val postCommentReportReasonEntities = + postCommentReportReasons.map { it.registeredInPostCommentReport(postCommentReportId) } + .map { PostCommentReportReasonMapper.toEntity(it) } + val reportReasonIdToReportReason = + postCommentReportReasons + .map { it.reportReasonWithCustomReason.reportReason } + .associateBy { it.id } + + return postCommentReportReasonJpaRepository.saveAll(postCommentReportReasonEntities) + .map { + PostCommentReportReasonMapper.toDomain( + it, + reportReason = reportReasonIdToReportReason[it.reportReasonId]!! + ) + } + } + + override fun findAllByPostCommentReportId(postCommentReportId: Long): List { + val postCommentReportReasonEntities = + postCommentReportReasonJpaRepository.findByPostCommentReportId(postCommentReportId) + val reportReasonIds = postCommentReportReasonEntities.map { it.reportReasonId } + val reportReasonIdToReportReason = reportReasonPort.findAllByIdIn(reportReasonIds) + .associateBy { it.id } + + return postCommentReportReasonEntities.map { + PostCommentReportReasonMapper.toDomain( + it, + reportReason = reportReasonIdToReportReason[it.reportReasonId]!! + ) + } + } +} diff --git a/infrastructure/mysql/src/main/kotlin/com/wespot/comment/mapper/PostCommentReportMapper.kt b/infrastructure/mysql/src/main/kotlin/com/wespot/comment/mapper/PostCommentReportMapper.kt index bd89b773..f1721bf9 100644 --- a/infrastructure/mysql/src/main/kotlin/com/wespot/comment/mapper/PostCommentReportMapper.kt +++ b/infrastructure/mysql/src/main/kotlin/com/wespot/comment/mapper/PostCommentReportMapper.kt @@ -2,6 +2,7 @@ package com.wespot.comment.mapper import com.wespot.comment.PostCommentReport import com.wespot.comment.PostCommentReportEntity +import com.wespot.comment.PostCommentReportReason import com.wespot.common.BaseEntity import java.time.LocalDateTime @@ -16,11 +17,15 @@ object PostCommentReportMapper { ) } - fun toDomain(entity: PostCommentReportEntity): PostCommentReport { + fun toDomain( + entity: PostCommentReportEntity, + postCommentReportReasons: List + ): PostCommentReport { return PostCommentReport( id = entity.id, postCommentId = entity.postCommentId, userId = entity.userId, + postCommentReportReasons = postCommentReportReasons, createdAt = entity.baseEntity.createdAt ) } diff --git a/infrastructure/mysql/src/main/kotlin/com/wespot/comment/mapper/PostCommentReportReasonMapper.kt b/infrastructure/mysql/src/main/kotlin/com/wespot/comment/mapper/PostCommentReportReasonMapper.kt new file mode 100644 index 00000000..004f9e42 --- /dev/null +++ b/infrastructure/mysql/src/main/kotlin/com/wespot/comment/mapper/PostCommentReportReasonMapper.kt @@ -0,0 +1,43 @@ +package com.wespot.comment.mapper + +import com.wespot.comment.PostCommentReport +import com.wespot.comment.PostCommentReportReason +import com.wespot.comment.PostCommentReportReasonEntity +import com.wespot.common.BaseEntity +import com.wespot.report.ReportReason +import com.wespot.report.ReportReasonWithCustomReason + +object PostCommentReportReasonMapper { + + fun toDomain( + postCommentReportReasonEntity: PostCommentReportReasonEntity, + reportReason: ReportReason + ): PostCommentReportReason { + return PostCommentReportReason( + id = postCommentReportReasonEntity.id, + postCommentReportId = postCommentReportReasonEntity.postCommentReportId, + reportReasonWithCustomReason = ReportReasonWithCustomReason( + reportReason = reportReason, + customReason = postCommentReportReasonEntity.customReason + ), + + createdAt = postCommentReportReasonEntity.baseEntity.createdAt, + updatedAt = postCommentReportReasonEntity.baseEntity.updatedAt + ) + } + + fun toEntity(postCommentReportReason: PostCommentReportReason): PostCommentReportReasonEntity { + return PostCommentReportReasonEntity( + id = postCommentReportReason.id, + postCommentReportId = postCommentReportReason.postCommentReportId, + reportReasonId = postCommentReportReason.reportReasonWithCustomReason.reportReason.id, + customReason = postCommentReportReason.reportReasonWithCustomReason.customReason, + + baseEntity = BaseEntity( + createdAt = postCommentReportReason.createdAt, + updatedAt = postCommentReportReason.updatedAt + ) + ) + } + +} diff --git a/infrastructure/mysql/src/main/kotlin/com/wespot/comment/repository/PostCommentReportReasonJpaRepository.kt b/infrastructure/mysql/src/main/kotlin/com/wespot/comment/repository/PostCommentReportReasonJpaRepository.kt new file mode 100644 index 00000000..8b19b098 --- /dev/null +++ b/infrastructure/mysql/src/main/kotlin/com/wespot/comment/repository/PostCommentReportReasonJpaRepository.kt @@ -0,0 +1,10 @@ +package com.wespot.comment.repository + +import com.wespot.comment.PostCommentReportReasonEntity +import org.springframework.data.jpa.repository.JpaRepository + +interface PostCommentReportReasonJpaRepository : JpaRepository { + + fun findByPostCommentReportId(postCommentReportId: Long): List + +} diff --git a/infrastructure/mysql/src/main/kotlin/com/wespot/post/PostReportEntity.kt b/infrastructure/mysql/src/main/kotlin/com/wespot/post/PostReportEntity.kt index cc06f03b..352836fb 100644 --- a/infrastructure/mysql/src/main/kotlin/com/wespot/post/PostReportEntity.kt +++ b/infrastructure/mysql/src/main/kotlin/com/wespot/post/PostReportEntity.kt @@ -17,9 +17,6 @@ class PostReportEntity( @field: NotNull val userId: Long, - @field:NotNull - val reportReasonId: Long, - @Embedded val baseEntity: BaseEntity ) { diff --git a/infrastructure/mysql/src/main/kotlin/com/wespot/post/PostReportReasonEntity.kt b/infrastructure/mysql/src/main/kotlin/com/wespot/post/PostReportReasonEntity.kt new file mode 100644 index 00000000..20ae43c6 --- /dev/null +++ b/infrastructure/mysql/src/main/kotlin/com/wespot/post/PostReportReasonEntity.kt @@ -0,0 +1,31 @@ +package com.wespot.post + +import com.wespot.common.BaseEntity +import jakarta.persistence.* +import jakarta.validation.constraints.NotNull + + +@Entity +@Table(name = "post_report_reason") +data class PostReportReasonEntity( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long, + + @field: NotNull + val postReportId: Long, + + @field: NotNull + val reportReasonId: Long, + + val customReason: String? = null, + + @Embedded + val baseEntity: BaseEntity +) { + + fun registeredInPostReport(postReportId: Long): PostReportReasonEntity { + return copy(postReportId = postReportId) + } + +} diff --git a/infrastructure/mysql/src/main/kotlin/com/wespot/post/adapter/PostReportAdapter.kt b/infrastructure/mysql/src/main/kotlin/com/wespot/post/adapter/PostReportAdapter.kt index b7128e5d..9e941e31 100644 --- a/infrastructure/mysql/src/main/kotlin/com/wespot/post/adapter/PostReportAdapter.kt +++ b/infrastructure/mysql/src/main/kotlin/com/wespot/post/adapter/PostReportAdapter.kt @@ -3,14 +3,14 @@ package com.wespot.post.adapter import com.wespot.post.PostReport import com.wespot.post.mapper.PostReportMapper import com.wespot.post.port.out.PostReportPort +import com.wespot.post.port.out.PostReportReasonPort import com.wespot.post.repository.PostReportJpaRepository -import com.wespot.report.port.out.ReportReasonPort import org.springframework.stereotype.Repository @Repository class PostReportAdapter( private val postReportJpaRepository: PostReportJpaRepository, - private val reportReasonPort: ReportReasonPort, + private val postReportReasonPort: PostReportReasonPort, ) : PostReportPort { override fun findByPostIdAndUserId(postId: Long, userId: Long): PostReport? { @@ -18,8 +18,7 @@ class PostReportAdapter( ?.let { PostReportMapper.toDomain( it, - reportReason = reportReasonPort.findById(it.reportReasonId) - ?: throw IllegalStateException("신고 사유가 존재하지 않습니다.") + postReportReasons = postReportReasonPort.findByPostReportId(postReportId = it.id) ) } } @@ -31,9 +30,13 @@ class PostReportAdapter( override fun save(postBlock: PostReport): PostReport { val postBlockEntity = PostReportMapper.toEntity(postBlock) val savedPostBlockEntity = postReportJpaRepository.save(postBlockEntity) + val savedPostReportReasons = postReportReasonPort.saveAll( + postReportId = savedPostBlockEntity.id, + postReportReasons = postBlock.postReportReasons + ) return PostReportMapper.toDomain( - savedPostBlockEntity, - reportReason = postBlock.reportReason + entity = savedPostBlockEntity, + postReportReasons = savedPostReportReasons ) } diff --git a/infrastructure/mysql/src/main/kotlin/com/wespot/post/adapter/PostReportReasonAdapter.kt b/infrastructure/mysql/src/main/kotlin/com/wespot/post/adapter/PostReportReasonAdapter.kt new file mode 100644 index 00000000..baad0db0 --- /dev/null +++ b/infrastructure/mysql/src/main/kotlin/com/wespot/post/adapter/PostReportReasonAdapter.kt @@ -0,0 +1,50 @@ +package com.wespot.post.adapter + +import com.wespot.post.PostReportReason +import com.wespot.post.mapper.PostReportReasonMapper +import com.wespot.post.port.out.PostReportReasonPort +import com.wespot.post.repository.PostReportReasonJpaRepository +import com.wespot.report.port.out.ReportReasonPort +import org.springframework.stereotype.Repository + +@Repository +class PostReportReasonAdapter( + private val postReportReasonJpaRepository: PostReportReasonJpaRepository, + private val reportReasonPort: ReportReasonPort, +) : PostReportReasonPort { + + override fun saveAll( + postReportId: Long, + postReportReasons: List + ): List { + val postReportReasonEntities = postReportReasons.map { PostReportReasonMapper.toEntity(it) } + .map { it.registeredInPostReport(postReportId = postReportId) } + val reportReasonIdToReportReason = + postReportReasons.map { it.reportReasonWithCustomReason.reportReason } + .associateBy { it.id } + + return postReportReasonJpaRepository.saveAll(postReportReasonEntities) + .map { + PostReportReasonMapper.toDomain( + it, + reportReasonIdToReportReason[it.reportReasonId]!! + ) + } + } + + override fun findByPostReportId(postReportId: Long): List { + val postReportReasonEntities = + postReportReasonJpaRepository.findByPostReportId(postReportId = postReportId) + val reportReasonIds = postReportReasonEntities.map { it.reportReasonId } + val reportReasonIdToReportReason = reportReasonPort.findAllByIdIn(ids = reportReasonIds) + .associateBy { it.id } + + return postReportReasonEntities.map { + PostReportReasonMapper.toDomain( + it, + reportReason = reportReasonIdToReportReason[it.reportReasonId]!! + ) + } + } + +} diff --git a/infrastructure/mysql/src/main/kotlin/com/wespot/post/mapper/PostReportMapper.kt b/infrastructure/mysql/src/main/kotlin/com/wespot/post/mapper/PostReportMapper.kt index 4259cd32..f7d7e77f 100644 --- a/infrastructure/mysql/src/main/kotlin/com/wespot/post/mapper/PostReportMapper.kt +++ b/infrastructure/mysql/src/main/kotlin/com/wespot/post/mapper/PostReportMapper.kt @@ -3,7 +3,7 @@ package com.wespot.post.mapper import com.wespot.common.BaseEntity import com.wespot.post.PostReport import com.wespot.post.PostReportEntity -import com.wespot.report.ReportReason +import com.wespot.post.PostReportReason import java.time.LocalDateTime object PostReportMapper { @@ -13,7 +13,6 @@ object PostReportMapper { id = postReport.id, postId = postReport.postId, userId = postReport.userId, - reportReasonId = postReport.reportReason.id, baseEntity = BaseEntity( createdAt = postReport.createdAt, updatedAt = LocalDateTime.now() @@ -21,12 +20,12 @@ object PostReportMapper { ) } - fun toDomain(entity: PostReportEntity, reportReason: ReportReason): PostReport { + fun toDomain(entity: PostReportEntity, postReportReasons: List): PostReport { return PostReport( id = entity.id, postId = entity.postId, userId = entity.userId, - reportReason = reportReason, + postReportReasons = postReportReasons, createdAt = entity.baseEntity.createdAt ) } diff --git a/infrastructure/mysql/src/main/kotlin/com/wespot/post/mapper/PostReportReasonMapper.kt b/infrastructure/mysql/src/main/kotlin/com/wespot/post/mapper/PostReportReasonMapper.kt new file mode 100644 index 00000000..21b6ecff --- /dev/null +++ b/infrastructure/mysql/src/main/kotlin/com/wespot/post/mapper/PostReportReasonMapper.kt @@ -0,0 +1,40 @@ +package com.wespot.post.mapper + +import com.wespot.post.PostReportReason +import com.wespot.post.PostReportReasonEntity +import com.wespot.report.ReportReason +import com.wespot.report.ReportReasonWithCustomReason + +object PostReportReasonMapper { + + fun toDomain( + postReportReasonEntity: PostReportReasonEntity, + reportReason: ReportReason + ): PostReportReason { + return PostReportReason( + id = postReportReasonEntity.id, + postReportId = postReportReasonEntity.postReportId, + reportReasonWithCustomReason = ReportReasonWithCustomReason( + reportReason = reportReason, + customReason = postReportReasonEntity.customReason + ), + + createdAt = postReportReasonEntity.baseEntity.createdAt, + updatedAt = postReportReasonEntity.baseEntity.updatedAt + ) + } + + fun toEntity(postReportReason: PostReportReason): PostReportReasonEntity { + return PostReportReasonEntity( + id = postReportReason.id, + postReportId = postReportReason.postReportId, + reportReasonId = postReportReason.reportReasonWithCustomReason.reportReason.id, + customReason = postReportReason.reportReasonWithCustomReason.customReason, + baseEntity = com.wespot.common.BaseEntity( + createdAt = postReportReason.createdAt, + updatedAt = postReportReason.updatedAt + ) + ) + } + +} diff --git a/infrastructure/mysql/src/main/kotlin/com/wespot/post/repository/PostReportReasonJpaRepository.kt b/infrastructure/mysql/src/main/kotlin/com/wespot/post/repository/PostReportReasonJpaRepository.kt new file mode 100644 index 00000000..673f42d6 --- /dev/null +++ b/infrastructure/mysql/src/main/kotlin/com/wespot/post/repository/PostReportReasonJpaRepository.kt @@ -0,0 +1,10 @@ +package com.wespot.post.repository + +import com.wespot.post.PostReportReasonEntity +import org.springframework.data.jpa.repository.JpaRepository + +interface PostReportReasonJpaRepository : JpaRepository { + + fun findByPostReportId(postReportId: Long): List + +} diff --git a/infrastructure/mysql/src/main/kotlin/com/wespot/report/ReportReasonAdapter.kt b/infrastructure/mysql/src/main/kotlin/com/wespot/report/ReportReasonAdapter.kt index 52989b7f..c8f92531 100644 --- a/infrastructure/mysql/src/main/kotlin/com/wespot/report/ReportReasonAdapter.kt +++ b/infrastructure/mysql/src/main/kotlin/com/wespot/report/ReportReasonAdapter.kt @@ -19,4 +19,9 @@ class ReportReasonAdapter( ?.let { ReportReasonMapper.toDomain(it) } } + override fun findAllByIdIn(ids: List): List { + return reportReasonJpaRepository.findAllById(ids) + .map { ReportReasonMapper.toDomain(it) } + } + } diff --git a/infrastructure/mysql/src/main/kotlin/com/wespot/report/ReportReasonJpaEntity.kt b/infrastructure/mysql/src/main/kotlin/com/wespot/report/ReportReasonJpaEntity.kt index 5b8455fd..54fb14cb 100644 --- a/infrastructure/mysql/src/main/kotlin/com/wespot/report/ReportReasonJpaEntity.kt +++ b/infrastructure/mysql/src/main/kotlin/com/wespot/report/ReportReasonJpaEntity.kt @@ -13,7 +13,9 @@ data class ReportReasonJpaEntity( val id: Long = 0L, @field:NotNull - val content: String + val content: String, + + val canReceiveReason: Boolean ) { } diff --git a/infrastructure/mysql/src/main/kotlin/com/wespot/report/ReportReasonMapper.kt b/infrastructure/mysql/src/main/kotlin/com/wespot/report/ReportReasonMapper.kt index c7c4ca8c..845a8105 100644 --- a/infrastructure/mysql/src/main/kotlin/com/wespot/report/ReportReasonMapper.kt +++ b/infrastructure/mysql/src/main/kotlin/com/wespot/report/ReportReasonMapper.kt @@ -5,14 +5,16 @@ object ReportReasonMapper { fun toDomain(entity: ReportReasonJpaEntity): ReportReason { return ReportReason( id = entity.id, - content = entity.content + content = entity.content, + canReceiveReason = entity.canReceiveReason ) } fun toEntity(domain: ReportReason): ReportReasonJpaEntity { return ReportReasonJpaEntity( id = domain.id, - content = domain.content + content = domain.content, + canReceiveReason = domain.canReceiveReason ) } From 0a2de2a307abebbf67f69ee98070c221f148c6f6 Mon Sep 17 00:00:00 2001 From: kpeel Date: Sun, 31 Aug 2025 23:40:09 +0900 Subject: [PATCH 2/2] feat: enhance comment notification system with user-specific profile names and notification type updates --- .../service/listener/CommentNotificationListener.kt | 11 +++++++---- .../src/main/kotlin/com/wespot/comment/PostComment.kt | 4 ++++ .../com/wespot/notification/NotificationType.kt | 2 +- domain/src/main/kotlin/com/wespot/post/Post.kt | 11 +++++++++++ domain/src/main/kotlin/com/wespot/user/User.kt | 7 +++++++ 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/core/src/main/kotlin/com/wespot/notification/service/listener/CommentNotificationListener.kt b/core/src/main/kotlin/com/wespot/notification/service/listener/CommentNotificationListener.kt index 8a1a9d4f..671e2937 100644 --- a/core/src/main/kotlin/com/wespot/notification/service/listener/CommentNotificationListener.kt +++ b/core/src/main/kotlin/com/wespot/notification/service/listener/CommentNotificationListener.kt @@ -8,6 +8,7 @@ import com.wespot.notification.NotificationType import com.wespot.notification.service.NotificationHelper import com.wespot.post.port.out.PostNotificationPort import com.wespot.post.port.out.PostPort +import com.wespot.post.port.out.PostProfilePort import org.springframework.http.HttpStatus import org.springframework.scheduling.annotation.Async import org.springframework.stereotype.Component @@ -19,6 +20,7 @@ import org.springframework.transaction.event.TransactionalEventListener @Component class CommentNotificationListener( private val postPort: PostPort, + private val postProfilePort: PostProfilePort, private val postNotificationPort: PostNotificationPort, private val notificationHelper: NotificationHelper, ) { @@ -26,7 +28,7 @@ class CommentNotificationListener( @Async @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) @Transactional(propagation = Propagation.REQUIRES_NEW) - fun listenCreatedPostCommentEvent(postCommentCreatedEvent: PostCommentCreatedEvent) { // TODO : 일단, 본인은 알림 못받게 해야하고, 익명 프로필로 + fun listenCreatedPostCommentEvent(postCommentCreatedEvent: PostCommentCreatedEvent) { val postComment = postCommentCreatedEvent.postComment val post = postPort.findById(postComment.postId) ?: throw CustomException( status = HttpStatus.BAD_REQUEST, @@ -35,14 +37,15 @@ class CommentNotificationListener( val commentRegister = postComment.user val postNotifications = postNotificationPort.findAllByPostId(post.id) - val users = listOf(post.user) + postNotifications.map { it.user }.distinct() + val users = postNotifications.map { it.user }.distinct() val notifications = users.stream() + .filter { postComment.isNotAuthor(it.id) } .map { Notification.create( userId = it.id, - type = NotificationType.COMMENT, + type = NotificationType.POST_COMMENT, targetId = post.id, - title = "${commentRegister.name} 님이 댓글을 남겼습니다.", + title = "${post.commentProfileName(commentRegister)} 님이 댓글을 남겼습니다.", body = NotificationUtil.summaryContent( content = postComment.content.content ), diff --git a/domain/src/main/kotlin/com/wespot/comment/PostComment.kt b/domain/src/main/kotlin/com/wespot/comment/PostComment.kt index d776df01..57170a4d 100644 --- a/domain/src/main/kotlin/com/wespot/comment/PostComment.kt +++ b/domain/src/main/kotlin/com/wespot/comment/PostComment.kt @@ -85,4 +85,8 @@ class PostComment( return user.id == id } + fun isNotAuthor(id: Long): Boolean { + return !isAuthor(id) + } + } diff --git a/domain/src/main/kotlin/com/wespot/notification/NotificationType.kt b/domain/src/main/kotlin/com/wespot/notification/NotificationType.kt index 304a8945..7cc3ec31 100644 --- a/domain/src/main/kotlin/com/wespot/notification/NotificationType.kt +++ b/domain/src/main/kotlin/com/wespot/notification/NotificationType.kt @@ -20,7 +20,7 @@ enum class NotificationType( PROFILE_UPDATE({ it.isEnableMarketingNotification() }, SpecificNotificationType.UPDATE), // 프로필 업데이트 이벤트 UPDATE_REQUIRED({ it.isEnableMarketingNotification() }, SpecificNotificationType.UPDATE), // 업데이트를 아직 안한 유저 - COMMENT({ it.isEnableMarketingNotification() }, SpecificNotificationType.POST) + POST_COMMENT({ it.isEnablePostNotification() }, SpecificNotificationType.POST) // 게시글 댓글 알림 ; fun isVote(): Boolean { diff --git a/domain/src/main/kotlin/com/wespot/post/Post.kt b/domain/src/main/kotlin/com/wespot/post/Post.kt index 3b934ff7..ba432a5c 100644 --- a/domain/src/main/kotlin/com/wespot/post/Post.kt +++ b/domain/src/main/kotlin/com/wespot/post/Post.kt @@ -28,6 +28,9 @@ class Post( companion object { + const val VIEWER_COMMENT_PROFILE_NAME = "익명의 댓쓴이" + const val AUTHOR_COMMENT_PROFILE_NAME = "익명의 글쓴이" + fun of( category: PostCategory, user: User, @@ -142,4 +145,12 @@ class Post( return copyAndUpdateField(bookmarkedCount = this.bookmarkedCount + 1) } + fun commentProfileName(user: User): String { + if (isAuthor(user.id)) { + return AUTHOR_COMMENT_PROFILE_NAME + } + + return VIEWER_COMMENT_PROFILE_NAME + } + } diff --git a/domain/src/main/kotlin/com/wespot/user/User.kt b/domain/src/main/kotlin/com/wespot/user/User.kt index 61dd7148..90f0a4cf 100644 --- a/domain/src/main/kotlin/com/wespot/user/User.kt +++ b/domain/src/main/kotlin/com/wespot/user/User.kt @@ -326,4 +326,11 @@ data class User( return setting.isEnableMessage } + fun isEnablePostNotification(): Boolean { + if (isWithDraw() || isKeepRestrict()) { + return false + } + return setting.isEnablePostNotification + } + }