diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/dto/request/UpdateEventScheduleRequest.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/dto/request/UpdateEventScheduleRequest.kt new file mode 100644 index 0000000..9507a87 --- /dev/null +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/dto/request/UpdateEventScheduleRequest.kt @@ -0,0 +1,10 @@ +package com.kodomo.juganbbojjak.domain.event_schedule.dto.request + +import java.time.LocalDate + +data class UpdateEventScheduleRequest( + val date: LocalDate, + val name: String, + val place: String, + val headcount: Int, +) \ No newline at end of file diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/model/EventSchedule.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/model/EventSchedule.kt index bf78825..31a82a3 100644 --- a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/model/EventSchedule.kt +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/model/EventSchedule.kt @@ -13,4 +13,17 @@ data class EventSchedule( val headcount: Int, val weeklyEventScheduleId: UUID, val userId: UUID, -) \ No newline at end of file +) { + + fun update( + date: LocalDate, + name: String, + place: String, + headcount: Int, + ) = this.copy( + date = date, + name = name, + place = place, + headcount = headcount, + ) +} \ 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 d745c17..2f876e1 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 @@ -13,8 +13,10 @@ interface QueryEventSchedulePort { fun queryEventSchedulesByWeeklyEventScheduleId(weeklyEventScheduleId: UUID, userId: UUID?): List fun queryAllEventScheduleList(): List fun queryLatestEventSchedule(): WeeklyEventSchedule? + fun queryEventScheduleById(eventScheduleId: UUID): EventSchedule? } interface CommandEventSchedulePort { fun saveAllEventSchedule(eventSchedule: List) + fun saveEventSchedule(eventSchedule: EventSchedule) } \ No newline at end of file diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/usecase/UpdateEventScheduleUseCase.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/usecase/UpdateEventScheduleUseCase.kt new file mode 100644 index 0000000..fafc5c3 --- /dev/null +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/usecase/UpdateEventScheduleUseCase.kt @@ -0,0 +1,29 @@ +package com.kodomo.juganbbojjak.domain.event_schedule.usecase + +import com.kodomo.juganbbojjak.common.annotation.UseCase +import com.kodomo.juganbbojjak.domain.event_schedule.dto.request.UpdateEventScheduleRequest +import com.kodomo.juganbbojjak.domain.event_schedule.exception.EventScheduleNotFoundException +import com.kodomo.juganbbojjak.domain.event_schedule.spi.CommandEventSchedulePort +import com.kodomo.juganbbojjak.domain.event_schedule.spi.QueryEventSchedulePort +import java.util.UUID + +@UseCase +class UpdateEventScheduleUseCase( + private val queryEventSchedulePort: QueryEventSchedulePort, + private val commandEventSchedulePort: CommandEventSchedulePort, +) { + + fun execute(eventScheduleId: UUID, request: UpdateEventScheduleRequest) { + val eventSchedule = queryEventSchedulePort.queryEventScheduleById(eventScheduleId) + ?: throw EventScheduleNotFoundException + + commandEventSchedulePort.saveEventSchedule( + eventSchedule.update( + date = request.date, + name = request.name, + place = request.place, + headcount = request.headcount, + ) + ) + } +} \ 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 096ab93..66c9496 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 @@ -32,8 +32,8 @@ class EvenSchedulePersistenceAdapter( override fun queryEventSchedulesByWeeklyEventScheduleId( weeklyEventScheduleId: UUID, userId: UUID? - ): List { - return queryFactory + ): List = + queryFactory .selectFrom(eventScheduleEntity) .join(eventScheduleEntity.weeklyEventScheduleEntity, weeklyEventScheduleEntity) .where( @@ -41,15 +41,21 @@ class EvenSchedulePersistenceAdapter( eqUserId(userId) ) .orderBy(eventScheduleEntity.date.asc()) - .fetch().stream() + .fetch() .map { eventScheduleMapper.toDomain(it)!! } - .toList() - } + + override fun queryEventScheduleById(eventScheduleId: UUID): EventSchedule? = eventScheduleMapper.toDomain( + eventScheduleJpaRepository.findByIdOrNull(eventScheduleId) + ) override fun saveAllEventSchedule(eventSchedule: List) { eventScheduleJpaRepository.saveAll(eventSchedule.stream().map { eventScheduleMapper.toEntity(it) }.toList()) } + override fun saveEventSchedule(eventSchedule: EventSchedule) { + eventScheduleJpaRepository.save(eventScheduleMapper.toEntity(eventSchedule)) + } + //==condition==// private fun eqUserId(userId: UUID?): BooleanExpression? = 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 9e85ac2..e0a53a7 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,13 +2,16 @@ 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.UpdateEventScheduleWebRequest import com.kodomo.juganbbojjak.domain.event_schedule.usecase.CreateEvenScheduleUseCase import com.kodomo.juganbbojjak.domain.event_schedule.usecase.QueryEventScheduleDetailUseCase +import com.kodomo.juganbbojjak.domain.event_schedule.usecase.UpdateEventScheduleUseCase import jakarta.validation.Valid import org.springframework.http.HttpStatus 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.PutMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.ResponseStatus @@ -19,7 +22,8 @@ import java.util.UUID @RestController class EventScheduleWebAdapter( private val createEvenScheduleUseCase: CreateEvenScheduleUseCase, - private val queryEventScheduleDetailUseCase: QueryEventScheduleDetailUseCase + private val queryEventScheduleDetailUseCase: QueryEventScheduleDetailUseCase, + private val updateEventScheduleUseCase: UpdateEventScheduleUseCase, ) { @ResponseStatus(HttpStatus.CREATED) @@ -35,4 +39,13 @@ class EventScheduleWebAdapter( fun queryEventSchedules( @PathVariable("weekly-event-schedule-id") weeklyEventScheduleId: UUID ): QueryEventScheduleDetailResponse = queryEventScheduleDetailUseCase.execute(weeklyEventScheduleId) + + @ResponseStatus(HttpStatus.NO_CONTENT) + @PutMapping("/{event-schedule-id}") + fun updateEventSchedule( + @PathVariable("event-schedule-id") eventScheduleId: UUID, + @RequestBody @Valid request: UpdateEventScheduleWebRequest, + ) { + updateEventScheduleUseCase.execute(eventScheduleId, request.toDomainRequest()) + } } \ No newline at end of file diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/presentation/dto/UpdateEventScheduleWebRequest.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/presentation/dto/UpdateEventScheduleWebRequest.kt new file mode 100644 index 0000000..b8d82c2 --- /dev/null +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/presentation/dto/UpdateEventScheduleWebRequest.kt @@ -0,0 +1,29 @@ +package com.kodomo.juganbbojjak.domain.event_schedule.presentation.dto + +import com.kodomo.juganbbojjak.domain.event_schedule.dto.request.UpdateEventScheduleRequest +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.NotNull +import java.time.LocalDate + +data class UpdateEventScheduleWebRequest( + + @field:NotNull + val date: LocalDate, + + @field:NotBlank + val name: String, + + @field:NotBlank + val place: String, + + @field:NotNull + val headcount: Int, +) { + + fun toDomainRequest() = UpdateEventScheduleRequest( + date = date, + name = name, + place = place, + headcount = headcount, + ) +}