From 43cfcdedaddd228a2f6bb1cc395be94dc8d2379f Mon Sep 17 00:00:00 2001 From: DongGeon0908 Date: Wed, 4 Sep 2024 20:39:55 +0900 Subject: [PATCH] fix: add pose notification path-variables --- .../application/PoseNotificationService.kt | 14 ++++++++++++-- .../infrastructure/PoseNotificationRepository.kt | 2 ++ .../resource/PoseNotificationResource.kt | 7 ++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/hero/alignlab/domain/notification/application/PoseNotificationService.kt b/src/main/kotlin/com/hero/alignlab/domain/notification/application/PoseNotificationService.kt index 68cf17f..eb7b8b5 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/notification/application/PoseNotificationService.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/notification/application/PoseNotificationService.kt @@ -52,12 +52,22 @@ class PoseNotificationService( } } + suspend fun findByIdAndUidOrThrow(id: Long, uid: Long): PoseNotification { + return findByIdAndUidOrNull(id, uid) ?: throw NotFoundException(ErrorCode.NOT_FOUND_POSE_NOTIFICATION_ERROR) + } + + suspend fun findByIdAndUidOrNull(id: Long, uid: Long): PoseNotification? { + return withContext(Dispatchers.IO) { + poseNotificationRepository.findByIdAndUid(id, uid) + } + } + suspend fun findByUidOrThrow(uid: Long): PoseNotification { return findByUidOrNull(uid) ?: throw NotFoundException(ErrorCode.NOT_FOUND_POSE_NOTIFICATION_ERROR) } - suspend fun patch(user: AuthUser, request: PatchPoseNotificationRequest): PatchPoseNotificationResponse { - val poseNotification = findByUidOrThrow(user.uid) + suspend fun patch(user: AuthUser, id: Long, request: PatchPoseNotificationRequest): PatchPoseNotificationResponse { + val poseNotification = findByIdAndUidOrThrow(id, user.uid) val updatedPoseNotification = txTemplates.writer.executes { poseNotification.apply { diff --git a/src/main/kotlin/com/hero/alignlab/domain/notification/infrastructure/PoseNotificationRepository.kt b/src/main/kotlin/com/hero/alignlab/domain/notification/infrastructure/PoseNotificationRepository.kt index 4a47b73..ef58e1d 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/notification/infrastructure/PoseNotificationRepository.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/notification/infrastructure/PoseNotificationRepository.kt @@ -12,4 +12,6 @@ interface PoseNotificationRepository : JpaRepository { fun findByUid(uid: Long): PoseNotification? fun countByCreatedAtBetween(startAt: LocalDateTime, endAt: LocalDateTime): Long + + fun findByIdAndUid(id: Long, uid: Long): PoseNotification? } diff --git a/src/main/kotlin/com/hero/alignlab/domain/notification/resource/PoseNotificationResource.kt b/src/main/kotlin/com/hero/alignlab/domain/notification/resource/PoseNotificationResource.kt index c8dac17..02ad6a0 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/notification/resource/PoseNotificationResource.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/notification/resource/PoseNotificationResource.kt @@ -45,6 +45,11 @@ class PoseNotificationResource( @PatchMapping(path = ["/api/v1/pose-notifications/{id}"]) suspend fun patchPoseNotification( user: AuthUser, + @PathVariable id: Long, @RequestBody request: PatchPoseNotificationRequest, - ) = poseNotificationService.patch(user, request).wrapOk() + ) = poseNotificationService.patch( + user = user, + id = id, + request = request + ).wrapOk() }