diff --git a/src/main/kotlin/co/bearus/magcloud/controller/DiaryCommentController.kt b/src/main/kotlin/co/bearus/magcloud/controller/DiaryCommentController.kt index a0d3b4d..abcfe3a 100644 --- a/src/main/kotlin/co/bearus/magcloud/controller/DiaryCommentController.kt +++ b/src/main/kotlin/co/bearus/magcloud/controller/DiaryCommentController.kt @@ -8,12 +8,15 @@ import co.bearus.magcloud.controller.dto.request.DiaryCommentCreateDTO import co.bearus.magcloud.controller.dto.request.DiaryCommentDTO import co.bearus.magcloud.controller.dto.response.APIResponse import co.bearus.magcloud.domain.entity.diary.DiaryCommentEntity +import co.bearus.magcloud.domain.exception.NotFriendException import co.bearus.magcloud.domain.repository.JPADiaryCommentRepository import co.bearus.magcloud.domain.repository.QUserDiaryRepository import co.bearus.magcloud.domain.service.diary.UserDiaryService +import co.bearus.magcloud.domain.service.friend.FriendService import co.bearus.magcloud.domain.service.notification.NotificationService import co.bearus.magcloud.domain.type.ContextLanguage import co.bearus.magcloud.util.ULIDUtils +import jakarta.validation.Valid import org.springframework.data.repository.findByIdOrNull import org.springframework.transaction.annotation.Transactional import org.springframework.web.bind.annotation.* @@ -25,15 +28,19 @@ class DiaryCommentController( private val diaryService: UserDiaryService, private val qUserDiaryRepository: QUserDiaryRepository, private val notificationService: NotificationService, + private val friendService: FriendService, ) { @Transactional @PostMapping fun createComment( @RequestUser user: WebUser, @PathVariable diaryId: String, - @RequestBody body: DiaryCommentCreateDTO, + @RequestBody @Valid body: DiaryCommentCreateDTO, ): DiaryCommentDTO { val diary = diaryService.getDiaryById(diaryId) + if (diary.userId != user.userId && !friendService.isFriend(diary.userId, user.userId)) + throw NotFriendException() + val comment = DiaryCommentEntity.createNewComment( commentId = ULIDUtils.generate(), diaryId = diary.diaryId, diff --git a/src/main/kotlin/co/bearus/magcloud/controller/dto/request/DiaryCreateDTO.kt b/src/main/kotlin/co/bearus/magcloud/controller/dto/request/DiaryCreateDTO.kt index ea35a38..6b79615 100644 --- a/src/main/kotlin/co/bearus/magcloud/controller/dto/request/DiaryCreateDTO.kt +++ b/src/main/kotlin/co/bearus/magcloud/controller/dto/request/DiaryCreateDTO.kt @@ -12,7 +12,7 @@ data class DiaryCreateDTO( ) data class DiaryCommentCreateDTO( - val content: String, + @field:NotEmpty(message = "내용은 비어있을 수 없습니다") val content: String, ) data class DiaryCommentDTO(