Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Notification 읽기 기능 추가 #109

Merged
merged 1 commit into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)
}
}
}