Skip to content

Commit

Permalink
refactor: 코드 정리 (#112)
Browse files Browse the repository at this point in the history
* refactor: 코드 정리

* test: 리팩토링에 따른 테스트 코드 변경
  • Loading branch information
ddingmin authored Jun 23, 2024
1 parent 8cbe7c3 commit a670d5d
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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) =
Expand Down
Original file line number Diff line number Diff line change
@@ -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<GetRecentNotification.GetRecentNotificationInput, GetRecentNotification.GetRecentNotificationOutput> {
) : UseCase<GetRecentNotification.GetRecentNotificationInput, Notification> {

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

Expand Down Expand Up @@ -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,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ data class CheckInStatusResponse(

@Schema(name = "expectAttendanceStatus", description = "출석 시 예상하는 상태")
val expectAttendanceStatus: AttendanceStatus,
) {
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -32,7 +33,7 @@ class GetRecentNotificationTest : BehaviorSpec({
)

Then("읽지 않은 알림이 조회된다") {
result.isRead shouldBe false
result.readAt shouldBe null
}
}
}
Expand Down Expand Up @@ -61,7 +62,7 @@ class GetRecentNotificationTest : BehaviorSpec({
)

Then("읽은 알림이 조회된다") {
result.isRead shouldBe true
result.readAt shouldNotBe null
}
}
}
Expand Down

0 comments on commit a670d5d

Please sign in to comment.