From 09d193491279913f50e41f2adeeccf3443cb395e Mon Sep 17 00:00:00 2001 From: ddingmin Date: Sun, 16 Jun 2024 19:21:14 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Notification=20=EC=9D=BD=EA=B8=B0=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/gateway/NotificationGateway.kt | 1 + .../domain/usecase/UpdateReadNotification.kt | 26 +++++++++++++++++++ .../controller/NotificationController.kt | 22 ++++++++++++++++ .../dto/response/NotificationResponse.kt | 11 ++++++++ 4 files changed, 60 insertions(+) create mode 100644 src/main/kotlin/com/depromeet/makers/domain/usecase/UpdateReadNotification.kt diff --git a/src/main/kotlin/com/depromeet/makers/domain/gateway/NotificationGateway.kt b/src/main/kotlin/com/depromeet/makers/domain/gateway/NotificationGateway.kt index 6b8019f..f1cf5dd 100644 --- a/src/main/kotlin/com/depromeet/makers/domain/gateway/NotificationGateway.kt +++ b/src/main/kotlin/com/depromeet/makers/domain/gateway/NotificationGateway.kt @@ -3,6 +3,7 @@ package com.depromeet.makers.domain.gateway import com.depromeet.makers.domain.model.Notification interface NotificationGateway { + fun getById(notificationId: String): Notification fun save(notification: Notification): Notification fun findRecentNotificationByMemberId(memberId: String): Notification? } diff --git a/src/main/kotlin/com/depromeet/makers/domain/usecase/UpdateReadNotification.kt b/src/main/kotlin/com/depromeet/makers/domain/usecase/UpdateReadNotification.kt new file mode 100644 index 0000000..2a9a2c6 --- /dev/null +++ b/src/main/kotlin/com/depromeet/makers/domain/usecase/UpdateReadNotification.kt @@ -0,0 +1,26 @@ +package com.depromeet.makers.domain.usecase + +import com.depromeet.makers.domain.gateway.NotificationGateway +import com.depromeet.makers.domain.model.Notification +import java.time.LocalDateTime + +class UpdateReadNotification( + private val notificationGateway: NotificationGateway, +) : UseCase { + + data class UpdateReadNotificationInput( + val notificationId: String, + val memberId: String, + val now: LocalDateTime = LocalDateTime.now(), + ) + + override fun execute(input: UpdateReadNotificationInput): Notification { + val notification = notificationGateway.getById(input.notificationId) + + return notificationGateway.save( + notification.copy( + readAt = input.now + ) + ) + } +} diff --git a/src/main/kotlin/com/depromeet/makers/presentation/restapi/controller/NotificationController.kt b/src/main/kotlin/com/depromeet/makers/presentation/restapi/controller/NotificationController.kt index 4ed4a4b..683149b 100644 --- a/src/main/kotlin/com/depromeet/makers/presentation/restapi/controller/NotificationController.kt +++ b/src/main/kotlin/com/depromeet/makers/presentation/restapi/controller/NotificationController.kt @@ -1,19 +1,24 @@ package com.depromeet.makers.presentation.restapi.controller import com.depromeet.makers.domain.usecase.GetRecentNotification +import com.depromeet.makers.domain.usecase.UpdateReadNotification import com.depromeet.makers.presentation.restapi.dto.response.NotificationResponse import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.security.core.Authentication import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController +import java.time.LocalDateTime @Tag(name = "알림 API", description = "알림 관련 API") @RestController @RequestMapping("/v1/notifications") class NotificationController( private val getRecentNotification: GetRecentNotification, + private val updateReadNotification: UpdateReadNotification, ) { @Operation(summary = "최근 알림 조회", description = "로그인한 사용자의 최근 알림을 조회합니다.") @GetMapping @@ -28,4 +33,21 @@ class NotificationController( ) ) } + + @Operation(summary = "알림을 읽음 처리합니다.", description = "알림을 읽음 처리합니다.") + @PostMapping("/{notificationId}/read") + fun readNotification( + authentication: Authentication, + @PathVariable notificationId: String, + ): NotificationResponse { + return NotificationResponse.fromDomain( + updateReadNotification.execute( + UpdateReadNotification.UpdateReadNotificationInput( + memberId = authentication.name, + notificationId = notificationId, + now = LocalDateTime.now(), + ) + ) + ) + } } diff --git a/src/main/kotlin/com/depromeet/makers/presentation/restapi/dto/response/NotificationResponse.kt b/src/main/kotlin/com/depromeet/makers/presentation/restapi/dto/response/NotificationResponse.kt index 1cde610..baafe9f 100644 --- a/src/main/kotlin/com/depromeet/makers/presentation/restapi/dto/response/NotificationResponse.kt +++ b/src/main/kotlin/com/depromeet/makers/presentation/restapi/dto/response/NotificationResponse.kt @@ -1,5 +1,6 @@ package com.depromeet.makers.presentation.restapi.dto.response +import com.depromeet.makers.domain.model.Notification import com.depromeet.makers.domain.model.NotificationType import com.depromeet.makers.domain.usecase.GetRecentNotification import io.swagger.v3.oas.annotations.media.Schema @@ -30,5 +31,15 @@ data class NotificationResponse( type = output.type, isRead = output.isRead, ) + + fun fromDomain(output: Notification): NotificationResponse { + return NotificationResponse( + id = output.id, + memberId = output.memberId, + content = output.content, + type = output.type, + isRead = output.readAt != null, + ) + } } }