From 35b2e25b7a0ce7f8786c9546e1beb679abcfc1da Mon Sep 17 00:00:00 2001 From: ChuYong Date: Thu, 27 Jul 2023 14:58:52 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9E=85=EB=A0=A5=20=EA=B2=80=EC=A6=9D?= =?UTF-8?q?=20=EB=B0=8F=20=EC=B9=9C=EA=B5=AC=20=EA=B2=80=EC=A6=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bearus/magcloud/controller/DiaryCommentController.kt | 9 ++++++++- .../magcloud/controller/dto/request/DiaryCreateDTO.kt | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) 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(