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

merge :: (#16) 행사일정 수정 api #25

Merged
merged 1 commit into from
Dec 13, 2023
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
@@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,17 @@ data class EventSchedule(
val headcount: Int,
val weeklyEventScheduleId: UUID,
val userId: UUID,
)
) {

fun update(
date: LocalDate,
name: String,
place: String,
headcount: Int,
) = this.copy(
date = date,
name = name,
place = place,
headcount = headcount,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ interface QueryEventSchedulePort {
fun queryEventSchedulesByWeeklyEventScheduleId(weeklyEventScheduleId: UUID, userId: UUID?): List<EventSchedule>
fun queryAllEventScheduleList(): List<WeeklyEventSchedule>
fun queryLatestEventSchedule(): WeeklyEventSchedule?
fun queryEventScheduleById(eventScheduleId: UUID): EventSchedule?
}

interface CommandEventSchedulePort {
fun saveAllEventSchedule(eventSchedule: List<EventSchedule>)
fun saveEventSchedule(eventSchedule: EventSchedule)
}
Original file line number Diff line number Diff line change
@@ -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,
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,30 @@ class EvenSchedulePersistenceAdapter(
override fun queryEventSchedulesByWeeklyEventScheduleId(
weeklyEventScheduleId: UUID,
userId: UUID?
): List<EventSchedule> {
return queryFactory
): List<EventSchedule> =
queryFactory
.selectFrom(eventScheduleEntity)
.join(eventScheduleEntity.weeklyEventScheduleEntity, weeklyEventScheduleEntity)
.where(
weeklyEventScheduleEntity.id.eq(weeklyEventScheduleId),
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<EventSchedule>) {
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? =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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())
}
}
Original file line number Diff line number Diff line change
@@ -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,
)
}
Loading