Skip to content

Commit

Permalink
feat: Notification 읽기 기능 추가 (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddingmin authored Jun 16, 2024
1 parent 5bb8ebf commit 0fdfcb5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
Original file line number Diff line number Diff line change
@@ -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<UpdateReadNotification.UpdateReadNotificationInput, Notification> {

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
)
)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(),
)
)
)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
)
}
}
}

0 comments on commit 0fdfcb5

Please sign in to comment.