Skip to content

Commit

Permalink
feat: 입력 검증 및 친구 검증
Browse files Browse the repository at this point in the history
  • Loading branch information
CChuYong committed Jul 27, 2023
1 parent d15af8a commit 35b2e25
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data class DiaryCreateDTO(
)

data class DiaryCommentCreateDTO(
val content: String,
@field:NotEmpty(message = "내용은 비어있을 수 없습니다") val content: String,
)

data class DiaryCommentDTO(
Expand Down

0 comments on commit 35b2e25

Please sign in to comment.