Skip to content

Commit

Permalink
fix: add pose notification path-variables
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Sep 4, 2024
1 parent 3c0fc33 commit 43cfcde
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ interface PoseNotificationRepository : JpaRepository<PoseNotification, Long> {
fun findByUid(uid: Long): PoseNotification?

fun countByCreatedAtBetween(startAt: LocalDateTime, endAt: LocalDateTime): Long

fun findByIdAndUid(id: Long, uid: Long): PoseNotification?
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit 43cfcde

Please sign in to comment.