diff --git a/src/main/kotlin/com/depromeet/makers/domain/model/Notification.kt b/src/main/kotlin/com/depromeet/makers/domain/model/Notification.kt index 8d31731..bc04412 100644 --- a/src/main/kotlin/com/depromeet/makers/domain/model/Notification.kt +++ b/src/main/kotlin/com/depromeet/makers/domain/model/Notification.kt @@ -11,7 +11,7 @@ data class Notification( val createdAt: LocalDateTime, val readAt: LocalDateTime?, ) { - fun read() = copy(readAt = LocalDateTime.now()) + fun read(now: LocalDateTime) = copy(readAt = now) companion object { fun newNotification( diff --git a/src/main/kotlin/com/depromeet/makers/domain/usecase/CreateNewSession.kt b/src/main/kotlin/com/depromeet/makers/domain/usecase/CreateNewSession.kt index 7d598bd..c8a0576 100644 --- a/src/main/kotlin/com/depromeet/makers/domain/usecase/CreateNewSession.kt +++ b/src/main/kotlin/com/depromeet/makers/domain/usecase/CreateNewSession.kt @@ -6,7 +6,6 @@ import com.depromeet.makers.domain.gateway.SessionGateway import com.depromeet.makers.domain.model.Place import com.depromeet.makers.domain.model.Session import com.depromeet.makers.domain.model.SessionType -import com.depromeet.makers.util.generateULID import java.time.LocalDateTime class CreateNewSession( @@ -29,17 +28,17 @@ class CreateNewSession( throw SessionAlreadyExistsException() } - val newSession = Session( - sessionId = generateULID(), - generation = input.generation, - week = input.week, - title = input.title, - description = input.description, - startTime = input.startTime, - sessionType = input.sessionType, - place = getNewPlace(input), + return sessionGateWay.save( + Session.newSession( + generation = input.generation, + week = input.week, + title = input.title, + description = input.description, + startTime = input.startTime, + sessionType = input.sessionType, + place = getNewPlace(input), + ) ) - return sessionGateWay.save(newSession) } private fun hasSameGenerationAndWeekSession(generation: Int, week: Int) = diff --git a/src/main/kotlin/com/depromeet/makers/domain/usecase/GetRecentNotification.kt b/src/main/kotlin/com/depromeet/makers/domain/usecase/GetRecentNotification.kt index 0dd5cd5..b12cc5f 100644 --- a/src/main/kotlin/com/depromeet/makers/domain/usecase/GetRecentNotification.kt +++ b/src/main/kotlin/com/depromeet/makers/domain/usecase/GetRecentNotification.kt @@ -1,48 +1,28 @@ package com.depromeet.makers.domain.usecase import com.depromeet.makers.domain.gateway.NotificationGateway +import com.depromeet.makers.domain.model.Notification import com.depromeet.makers.domain.model.NotificationType import java.time.LocalDateTime class GetRecentNotification( private val notificationGateway: NotificationGateway, -) : UseCase { +) : UseCase { data class GetRecentNotificationInput( val memberId: String, ) - data class GetRecentNotificationOutput( - val id: String, - val memberId: String, - val content: String, - val type: NotificationType, - val createdAt: LocalDateTime, - val isRead: Boolean = false, - ) - - override fun execute(input: GetRecentNotificationInput): GetRecentNotificationOutput { - val notification = notificationGateway.findRecentNotificationByMemberId(input.memberId) - - // 조회 알림이 없다면 default 값 - if (notification == null) { - return GetRecentNotificationOutput( + override fun execute(input: GetRecentNotificationInput): Notification { + // 조회 알림이 없다면 default 값으로 반환 + return notificationGateway.findRecentNotificationByMemberId(input.memberId) + ?: return Notification( id = "defaultId", memberId = input.memberId, content = "defaultContent", type = NotificationType.NONE, createdAt = LocalDateTime.now(), - isRead = true, + readAt = LocalDateTime.now(), ) - } - - return GetRecentNotificationOutput( - id = notification.id, - memberId = notification.memberId, - content = notification.content, - type = notification.type, - createdAt = notification.createdAt, - isRead = notification.readAt != null, - ) } } diff --git a/src/main/kotlin/com/depromeet/makers/domain/usecase/UpdateAbsenceMember.kt b/src/main/kotlin/com/depromeet/makers/domain/usecase/UpdateAbsenceMember.kt index 4b4cacf..5874223 100644 --- a/src/main/kotlin/com/depromeet/makers/domain/usecase/UpdateAbsenceMember.kt +++ b/src/main/kotlin/com/depromeet/makers/domain/usecase/UpdateAbsenceMember.kt @@ -3,9 +3,7 @@ package com.depromeet.makers.domain.usecase import com.depromeet.makers.domain.gateway.AttendanceGateway import com.depromeet.makers.domain.gateway.NotificationGateway import com.depromeet.makers.domain.gateway.SessionGateway -import com.depromeet.makers.domain.model.AttendanceStatus -import com.depromeet.makers.domain.model.Notification -import com.depromeet.makers.domain.model.NotificationType +import com.depromeet.makers.domain.model.* import com.depromeet.makers.util.logger import java.time.LocalDateTime @@ -33,16 +31,20 @@ class UpdateAbsenceMember( } .forEach { attendanceGateway.save(it.copy(attendanceStatus = AttendanceStatus.ABSENCE)) - notificationGateway.save( - Notification.newNotification( - memberId = it.member.memberId, - content = "출석 인증 시간이 초과되었습니다.\n" + - "출석 증빙은 담당 운영진에게 문의하세요.", - type = NotificationType.DOCUMENT, - createdAt = input.today, - ) - ) + notificationGateway.save(createAbsentNotification(it.member, input)) + logger.info("memberId: ${it.member.memberId} has been changed to ${AttendanceStatus.ATTENDANCE}") } } + + private fun createAbsentNotification( + member: Member, + input: UpdateAbsenceMemberInput + ) = Notification.newNotification( + memberId = member.memberId, + content = "출석 인증 시간이 초과되었습니다.\n" + + "출석 증빙은 담당 운영진에게 문의하세요.", + type = NotificationType.DOCUMENT, + createdAt = input.today, + ) } diff --git a/src/main/kotlin/com/depromeet/makers/domain/usecase/UpdateReadNotification.kt b/src/main/kotlin/com/depromeet/makers/domain/usecase/UpdateReadNotification.kt index 2a9a2c6..5724a10 100644 --- a/src/main/kotlin/com/depromeet/makers/domain/usecase/UpdateReadNotification.kt +++ b/src/main/kotlin/com/depromeet/makers/domain/usecase/UpdateReadNotification.kt @@ -17,10 +17,6 @@ class UpdateReadNotification( override fun execute(input: UpdateReadNotificationInput): Notification { val notification = notificationGateway.getById(input.notificationId) - return notificationGateway.save( - notification.copy( - readAt = input.now - ) - ) + return notificationGateway.save(notification.read(input.now)) } } diff --git a/src/main/kotlin/com/depromeet/makers/presentation/restapi/dto/response/CheckInStatusResponse.kt b/src/main/kotlin/com/depromeet/makers/presentation/restapi/dto/response/CheckInStatusResponse.kt index c660773..5fe5b24 100644 --- a/src/main/kotlin/com/depromeet/makers/presentation/restapi/dto/response/CheckInStatusResponse.kt +++ b/src/main/kotlin/com/depromeet/makers/presentation/restapi/dto/response/CheckInStatusResponse.kt @@ -19,5 +19,4 @@ data class CheckInStatusResponse( @Schema(name = "expectAttendanceStatus", description = "출석 시 예상하는 상태") val expectAttendanceStatus: AttendanceStatus, -) { -} +) 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 baafe9f..2d0b0af 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 @@ -2,7 +2,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 @Schema(description = "알림 DTO") @@ -24,14 +23,6 @@ data class NotificationResponse( val isRead: Boolean, ) { companion object { - fun fromDomain(output: GetRecentNotification.GetRecentNotificationOutput) = NotificationResponse( - id = output.id, - memberId = output.memberId, - content = output.content, - type = output.type, - isRead = output.isRead, - ) - fun fromDomain(output: Notification): NotificationResponse { return NotificationResponse( id = output.id, diff --git a/src/test/kotlin/com/depromeet/makers/domain/usecase/GetRecentNotificationTest.kt b/src/test/kotlin/com/depromeet/makers/domain/usecase/GetRecentNotificationTest.kt index 8d46e9b..df79887 100644 --- a/src/test/kotlin/com/depromeet/makers/domain/usecase/GetRecentNotificationTest.kt +++ b/src/test/kotlin/com/depromeet/makers/domain/usecase/GetRecentNotificationTest.kt @@ -5,6 +5,7 @@ import com.depromeet.makers.domain.model.Notification import com.depromeet.makers.domain.model.NotificationType import io.kotest.core.spec.style.BehaviorSpec import io.kotest.matchers.shouldBe +import io.kotest.matchers.shouldNotBe import io.mockk.every import io.mockk.mockk import java.time.LocalDateTime @@ -32,7 +33,7 @@ class GetRecentNotificationTest : BehaviorSpec({ ) Then("읽지 않은 알림이 조회된다") { - result.isRead shouldBe false + result.readAt shouldBe null } } } @@ -61,7 +62,7 @@ class GetRecentNotificationTest : BehaviorSpec({ ) Then("읽은 알림이 조회된다") { - result.isRead shouldBe true + result.readAt shouldNotBe null } } }