From 4567412a180203434c3812ab0705445a4d443b5f Mon Sep 17 00:00:00 2001 From: gilgeunwoo Date: Thu, 21 Dec 2023 22:21:49 +0900 Subject: [PATCH] =?UTF-8?q?feat=20::=20=EC=A3=BC=EA=B0=84=20=ED=96=89?= =?UTF-8?q?=EC=82=AC=20=EC=9D=BC=EC=A0=95=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/CreateWeeklyEventScheduleRequest.kt | 8 +++++++ .../model/WeeklyEventSchedule.kt | 2 +- .../event_schedule/spi/EventSchedulePort.kt | 1 + .../CreateWeeklyEventScheduleUseCase.kt | 21 +++++++++++++++++++ .../EvenSchedulePersistenceAdapter.kt | 5 +++++ .../presentation/EventScheduleWebAdapter.kt | 11 ++++++++++ .../CreateWeeklyEventScheduleWebRequest.kt | 20 ++++++++++++++++++ 7 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/dto/CreateWeeklyEventScheduleRequest.kt create mode 100644 JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/usecase/CreateWeeklyEventScheduleUseCase.kt create mode 100644 JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/presentation/dto/CreateWeeklyEventScheduleWebRequest.kt diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/dto/CreateWeeklyEventScheduleRequest.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/dto/CreateWeeklyEventScheduleRequest.kt new file mode 100644 index 0000000..a6feffc --- /dev/null +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/dto/CreateWeeklyEventScheduleRequest.kt @@ -0,0 +1,8 @@ +package com.kodomo.juganbbojjak.domain.event_schedule.dto + +import java.time.LocalDate + +data class CreateWeeklyEventScheduleRequest( + val startDate: LocalDate, + val endDate: LocalDate, +) diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/model/WeeklyEventSchedule.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/model/WeeklyEventSchedule.kt index efe4283..0f32e0b 100644 --- a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/model/WeeklyEventSchedule.kt +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/model/WeeklyEventSchedule.kt @@ -6,7 +6,7 @@ import java.util.UUID @Aggregate data class WeeklyEventSchedule( - val id: UUID, + val id: UUID = UUID.randomUUID(), val startDate: LocalDate, val endDate: LocalDate, ) \ No newline at end of file diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/spi/EventSchedulePort.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/spi/EventSchedulePort.kt index 2f876e1..e08d6dc 100644 --- a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/spi/EventSchedulePort.kt +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/spi/EventSchedulePort.kt @@ -19,4 +19,5 @@ interface QueryEventSchedulePort { interface CommandEventSchedulePort { fun saveAllEventSchedule(eventSchedule: List) fun saveEventSchedule(eventSchedule: EventSchedule) + fun saveWeeklyEventSchedule(weeklyEventSchedule: WeeklyEventSchedule): WeeklyEventSchedule } \ No newline at end of file diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/usecase/CreateWeeklyEventScheduleUseCase.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/usecase/CreateWeeklyEventScheduleUseCase.kt new file mode 100644 index 0000000..7825de5 --- /dev/null +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/usecase/CreateWeeklyEventScheduleUseCase.kt @@ -0,0 +1,21 @@ +package com.kodomo.juganbbojjak.domain.event_schedule.usecase + +import com.kodomo.juganbbojjak.common.annotation.UseCase +import com.kodomo.juganbbojjak.domain.event_schedule.dto.CreateWeeklyEventScheduleRequest +import com.kodomo.juganbbojjak.domain.event_schedule.model.WeeklyEventSchedule +import com.kodomo.juganbbojjak.domain.event_schedule.spi.CommandEventSchedulePort + +@UseCase +class CreateWeeklyEventScheduleUseCase( + private val commandEventSchedulePort: CommandEventSchedulePort, +) { + + fun execute(request: CreateWeeklyEventScheduleRequest) { + commandEventSchedulePort.saveWeeklyEventSchedule( + WeeklyEventSchedule( + startDate = request.startDate, + endDate = request.endDate, + ) + ) + } +} \ No newline at end of file diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/persistence/EvenSchedulePersistenceAdapter.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/persistence/EvenSchedulePersistenceAdapter.kt index 66c9496..e542871 100644 --- a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/persistence/EvenSchedulePersistenceAdapter.kt +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/persistence/EvenSchedulePersistenceAdapter.kt @@ -56,12 +56,17 @@ class EvenSchedulePersistenceAdapter( eventScheduleJpaRepository.save(eventScheduleMapper.toEntity(eventSchedule)) } + override fun saveWeeklyEventSchedule(weeklyEventSchedule: WeeklyEventSchedule): WeeklyEventSchedule = weeklyEventScheduleMapper.toDomain( + weeklyEventScheduleJpaRepository.save(weeklyEventScheduleMapper.toEntity(weeklyEventSchedule)) + )!! + //==condition==// private fun eqUserId(userId: UUID?): BooleanExpression? = if (userId != null) eventScheduleEntity.userEntity.id.eq(userId) else null + override fun queryAllEventScheduleList(): List { val weeklyEventScheduleEntity = weeklyEventScheduleJpaRepository.findAllByOrderByEndDateDesc() diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/presentation/EventScheduleWebAdapter.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/presentation/EventScheduleWebAdapter.kt index e0a53a7..9d7e4a5 100644 --- a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/presentation/EventScheduleWebAdapter.kt +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/presentation/EventScheduleWebAdapter.kt @@ -2,8 +2,10 @@ package com.kodomo.juganbbojjak.domain.event_schedule.presentation import com.kodomo.juganbbojjak.domain.event_schedule.dto.response.QueryEventScheduleDetailResponse import com.kodomo.juganbbojjak.domain.event_schedule.presentation.dto.CreateEvenScheduleWebRequest +import com.kodomo.juganbbojjak.domain.event_schedule.presentation.dto.CreateWeeklyEventScheduleWebRequest import com.kodomo.juganbbojjak.domain.event_schedule.presentation.dto.UpdateEventScheduleWebRequest import com.kodomo.juganbbojjak.domain.event_schedule.usecase.CreateEvenScheduleUseCase +import com.kodomo.juganbbojjak.domain.event_schedule.usecase.CreateWeeklyEventScheduleUseCase import com.kodomo.juganbbojjak.domain.event_schedule.usecase.QueryEventScheduleDetailUseCase import com.kodomo.juganbbojjak.domain.event_schedule.usecase.UpdateEventScheduleUseCase import jakarta.validation.Valid @@ -24,6 +26,7 @@ class EventScheduleWebAdapter( private val createEvenScheduleUseCase: CreateEvenScheduleUseCase, private val queryEventScheduleDetailUseCase: QueryEventScheduleDetailUseCase, private val updateEventScheduleUseCase: UpdateEventScheduleUseCase, + private val createWeeklyEventScheduleUseCase: CreateWeeklyEventScheduleUseCase, ) { @ResponseStatus(HttpStatus.CREATED) @@ -48,4 +51,12 @@ class EventScheduleWebAdapter( ) { updateEventScheduleUseCase.execute(eventScheduleId, request.toDomainRequest()) } + + @ResponseStatus(HttpStatus.CREATED) + @PostMapping + fun createWeeklyEventSchedule( + @RequestBody @Valid request: CreateWeeklyEventScheduleWebRequest, + ) { + createWeeklyEventScheduleUseCase.execute(request.toDomainRequest()) + } } \ No newline at end of file diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/presentation/dto/CreateWeeklyEventScheduleWebRequest.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/presentation/dto/CreateWeeklyEventScheduleWebRequest.kt new file mode 100644 index 0000000..e238c60 --- /dev/null +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/presentation/dto/CreateWeeklyEventScheduleWebRequest.kt @@ -0,0 +1,20 @@ +package com.kodomo.juganbbojjak.domain.event_schedule.presentation.dto + +import com.kodomo.juganbbojjak.domain.event_schedule.dto.CreateWeeklyEventScheduleRequest +import org.jetbrains.annotations.NotNull +import java.time.LocalDate + +data class CreateWeeklyEventScheduleWebRequest( + + @field:NotNull + val startDate: LocalDate, + + @field:NotNull + val endDate: LocalDate, +) { + + fun toDomainRequest() = CreateWeeklyEventScheduleRequest( + startDate = startDate, + endDate = endDate, + ) +}