Compare commits

..

4 Commits

Author SHA1 Message Date
1c0d40aed9 feat(chat-character-comment): 캐릭터 댓글에 글쓴이 ID 추가 2025-08-20 00:26:11 +09:00
1444afaae2 feat(chat-character-comment): 캐릭터 댓글 삭제 및 신고 API 추가
- 삭제 API: 본인 댓글에 대해 soft delete 처리
- 신고 API: 신고 내용을 그대로 저장하는 CharacterCommentReport 엔티티/리포지토리 도입
- Controller: 삭제, 신고 엔드포인트 추가 및 인증/본인인증 체크
- Service: 비즈니스 로직 구현 및 예외 처리 강화

왜: 캐릭터 댓글 관리 기능 요구사항(삭제/신고)을 충족하기 위함
무엇: 엔드포인트, 서비스 로직, DTO 및 JPA 엔티티/리포지토리 추가
2025-08-20 00:13:13 +09:00
a05bc369b7 feat(character-comment): 댓글/대댓글 API
- 커서를 추가하여 페이징 처리
2025-08-19 23:57:46 +09:00
6c7f411869 feat(character-comment): 캐릭터 댓글/답글 API 및 응답 확장
- 댓글 리스트에 댓글 개수 추가
2025-08-19 23:37:24 +09:00
6 changed files with 170 additions and 13 deletions

View File

@@ -5,6 +5,7 @@ import kr.co.vividnext.sodalive.common.SodaException
import kr.co.vividnext.sodalive.member.Member
import org.springframework.beans.factory.annotation.Value
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
@@ -54,12 +55,13 @@ class CharacterCommentController(
fun listComments(
@PathVariable characterId: Long,
@RequestParam(required = false, defaultValue = "20") limit: Int,
@RequestParam(required = false) cursor: Long?,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
if (member.auth == null) throw SodaException("본인인증을 하셔야 합니다.")
val data = service.listComments(imageHost, characterId, limit)
val data = service.listComments(imageHost, characterId, cursor, limit)
ApiResponse.ok(data)
}
@@ -68,13 +70,39 @@ class CharacterCommentController(
@PathVariable characterId: Long,
@PathVariable commentId: Long,
@RequestParam(required = false, defaultValue = "20") limit: Int,
@RequestParam(required = false) cursor: Long?,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
if (member.auth == null) throw SodaException("본인인증을 하셔야 합니다.")
// characterId는 서비스 내부 검증(원본 댓글과 캐릭터 일치)에서 검증됨
val data = service.getReplies(imageHost, commentId, limit)
val data = service.getReplies(imageHost, commentId, cursor, limit)
ApiResponse.ok(data)
}
@DeleteMapping("/{characterId}/comments/{commentId}")
fun deleteComment(
@PathVariable characterId: Long,
@PathVariable commentId: Long,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
if (member.auth == null) throw SodaException("본인인증을 하셔야 합니다.")
service.deleteComment(characterId, commentId, member)
ApiResponse.ok(true, "댓글이 삭제되었습니다.")
}
@PostMapping("/{characterId}/comments/{commentId}/reports")
fun reportComment(
@PathVariable characterId: Long,
@PathVariable commentId: Long,
@RequestBody request: ReportCharacterCommentRequest,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
if (member.auth == null) throw SodaException("본인인증을 하셔야 합니다.")
service.reportComment(characterId, commentId, member, request.content)
ApiResponse.ok(true, "신고가 접수되었습니다.")
}
}

View File

@@ -15,6 +15,7 @@ data class CreateCharacterCommentRequest(
data class CharacterCommentResponse(
val commentId: Long,
val memberId: Long,
val memberProfileImage: String,
val memberNickname: String,
val createdAt: Long,
@@ -30,6 +31,7 @@ data class CharacterCommentResponse(
data class CharacterReplyResponse(
val replyId: Long,
val memberId: Long,
val memberProfileImage: String,
val memberNickname: String,
val createdAt: Long
@@ -41,5 +43,21 @@ data class CharacterReplyResponse(
data class CharacterCommentRepliesResponse(
val original: CharacterCommentResponse,
val replies: List<CharacterReplyResponse>
val replies: List<CharacterReplyResponse>,
val cursor: Long?
)
// 댓글 리스트 조회 Response 컨테이너
// - 전체 댓글 개수(totalCount)
// - 댓글 목록(comments)
data class CharacterCommentListResponse(
val totalCount: Int,
val comments: List<CharacterCommentResponse>,
val cursor: Long?
)
// 신고 Request
data class ReportCharacterCommentRequest(
val content: String
)

View File

@@ -0,0 +1,25 @@
package kr.co.vividnext.sodalive.chat.character.comment
import kr.co.vividnext.sodalive.common.BaseEntity
import kr.co.vividnext.sodalive.member.Member
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.FetchType
import javax.persistence.JoinColumn
import javax.persistence.ManyToOne
import javax.persistence.Table
@Entity
@Table(name = "character_comment_report")
data class CharacterCommentReport(
@Column(columnDefinition = "TEXT", nullable = false)
val content: String
) : BaseEntity() {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "comment_id", nullable = false)
var comment: CharacterComment? = null
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", nullable = false)
var member: Member? = null
}

View File

@@ -0,0 +1,5 @@
package kr.co.vividnext.sodalive.chat.character.comment
import org.springframework.data.jpa.repository.JpaRepository
interface CharacterCommentReportRepository : JpaRepository<CharacterCommentReport, Long>

View File

@@ -9,8 +9,22 @@ interface CharacterCommentRepository : JpaRepository<CharacterComment, Long> {
pageable: Pageable
): List<CharacterComment>
fun findByChatCharacter_IdAndIsActiveTrueAndParentIsNullAndIdLessThanOrderByCreatedAtDesc(
chatCharacterId: Long,
id: Long,
pageable: Pageable
): List<CharacterComment>
fun countByParent_IdAndIsActiveTrue(parentId: Long): Int
fun findByParent_IdAndIsActiveTrueOrderByCreatedAtDesc(parentId: Long, pageable: Pageable): List<CharacterComment>
fun findByParent_IdAndIsActiveTrueAndIdLessThanOrderByCreatedAtDesc(
parentId: Long,
id: Long,
pageable: Pageable
): List<CharacterComment>
fun findFirstByChatCharacter_IdAndIsActiveTrueOrderByCreatedAtDesc(chatCharacterId: Long): CharacterComment?
// 전체(상위+답글) 활성 댓글 총 개수

View File

@@ -11,7 +11,8 @@ import java.time.ZoneId
@Service
class CharacterCommentService(
private val chatCharacterRepository: ChatCharacterRepository,
private val commentRepository: CharacterCommentRepository
private val commentRepository: CharacterCommentRepository,
private val reportRepository: CharacterCommentReportRepository
) {
private fun profileUrl(imageHost: String, profileImage: String?): String {
@@ -34,6 +35,7 @@ class CharacterCommentService(
val member = entity.member ?: throw SodaException("유효하지 않은 댓글입니다.")
return CharacterCommentResponse(
commentId = entity.id!!,
memberId = member.id!!,
memberProfileImage = profileUrl(imageHost, member.profileImage),
memberNickname = member.nickname,
createdAt = toEpochMilli(entity.createdAt),
@@ -46,6 +48,7 @@ class CharacterCommentService(
val member = entity.member ?: throw SodaException("유효하지 않은 댓글입니다.")
return CharacterReplyResponse(
replyId = entity.id!!,
memberId = member.id!!,
memberProfileImage = profileUrl(imageHost, member.profileImage),
memberNickname = member.nickname,
createdAt = toEpochMilli(entity.createdAt)
@@ -83,26 +86,67 @@ class CharacterCommentService(
}
@Transactional(readOnly = true)
fun listComments(imageHost: String, characterId: Long, limit: Int = 20): List<CharacterCommentResponse> {
fun listComments(
imageHost: String,
characterId: Long,
cursor: Long?,
limit: Int = 20
): CharacterCommentListResponse {
val pageable = PageRequest.of(0, limit)
val comments = commentRepository.findByChatCharacter_IdAndIsActiveTrueAndParentIsNullOrderByCreatedAtDesc(
val comments = if (cursor == null) {
commentRepository.findByChatCharacter_IdAndIsActiveTrueAndParentIsNullOrderByCreatedAtDesc(
characterId,
pageable
)
return comments.map { toCommentResponse(imageHost, it) }
} else {
commentRepository.findByChatCharacter_IdAndIsActiveTrueAndParentIsNullAndIdLessThanOrderByCreatedAtDesc(
characterId,
cursor,
pageable
)
}
val items = comments.map { toCommentResponse(imageHost, it) }
val total = getTotalCommentCount(characterId)
val nextCursor = if (items.size == limit) items.lastOrNull()?.commentId else null
return CharacterCommentListResponse(
totalCount = total,
comments = items,
cursor = nextCursor
)
}
@Transactional(readOnly = true)
fun getReplies(imageHost: String, commentId: Long, limit: Int = 20): CharacterCommentRepliesResponse {
val original = commentRepository.findById(commentId).orElseThrow { SodaException("댓글을 찾을 수 없습니다.") }
fun getReplies(
imageHost: String,
commentId: Long,
cursor: Long?,
limit: Int = 20
): CharacterCommentRepliesResponse {
val original = commentRepository.findById(commentId).orElseThrow {
SodaException("댓글을 찾을 수 없습니다.")
}
if (!original.isActive) throw SodaException("비활성화된 댓글입니다.")
val pageable = PageRequest.of(0, limit)
val replies = commentRepository.findByParent_IdAndIsActiveTrueOrderByCreatedAtDesc(commentId, pageable)
val replies = if (cursor == null) {
commentRepository.findByParent_IdAndIsActiveTrueOrderByCreatedAtDesc(commentId, pageable)
} else {
commentRepository.findByParent_IdAndIsActiveTrueAndIdLessThanOrderByCreatedAtDesc(
commentId,
cursor,
pageable
)
}
val items = replies.map { toReplyResponse(imageHost, it) }
val nextCursor = if (items.size == limit) items.lastOrNull()?.replyId else null
return CharacterCommentRepliesResponse(
original = toCommentResponse(imageHost, original, 0),
replies = replies.map { toReplyResponse(imageHost, it) }
replies = items,
cursor = nextCursor
)
}
@@ -116,4 +160,27 @@ class CharacterCommentService(
fun getTotalCommentCount(characterId: Long): Int {
return commentRepository.countByChatCharacter_IdAndIsActiveTrue(characterId)
}
@Transactional
fun deleteComment(characterId: Long, commentId: Long, member: Member) {
val comment = commentRepository.findById(commentId).orElseThrow { SodaException("댓글을 찾을 수 없습니다.") }
if (comment.chatCharacter?.id != characterId) throw SodaException("잘못된 요청입니다.")
if (!comment.isActive) return
val ownerId = comment.member?.id ?: throw SodaException("유효하지 않은 댓글입니다.")
if (ownerId != member.id) throw SodaException("삭제 권한이 없습니다.")
comment.isActive = false
commentRepository.save(comment)
}
@Transactional
fun reportComment(characterId: Long, commentId: Long, member: Member, content: String) {
val comment = commentRepository.findById(commentId).orElseThrow { SodaException("댓글을 찾을 수 없습니다.") }
if (comment.chatCharacter?.id != characterId) throw SodaException("잘못된 요청입니다.")
if (content.isBlank()) throw SodaException("신고 내용을 입력해주세요.")
val report = CharacterCommentReport(content = content)
report.comment = comment
report.member = member
reportRepository.save(report)
}
}