diff --git a/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomRequest.kt b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomRequest.kt index 8428a5a55..5df9847a2 100644 --- a/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomRequest.kt +++ b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomRequest.kt @@ -1,11 +1,7 @@ package team.aliens.dms.domain.studyroom.dto import team.aliens.dms.domain.student.model.Sex -import team.aliens.dms.domain.studyroom.model.Seat -import team.aliens.dms.domain.studyroom.model.SeatStatus import team.aliens.dms.domain.studyroom.model.StudyRoom -import team.aliens.dms.domain.studyroom.model.StudyRoomTimeSlot -import java.util.UUID data class UpdateStudyRoomRequest( val floor: Int, @@ -17,28 +13,15 @@ data class UpdateStudyRoomRequest( val southDescription: String, val northDescription: String, val availableSex: String, - val availableGrade: Int, - val timeSlotIds: List, - val seats: List + val availableGrade: Int ) { - data class SeatRequest( - val widthLocation: Int, - val heightLocation: Int, - val number: Int?, - val typeId: UUID?, - val status: String - ) - fun toStudyRoom(studyRoom: StudyRoom) = studyRoom.copy( name = name, floor = floor, widthSize = totalWidthSize, heightSize = totalHeightSize, - availableHeadcount = seats.count { - SeatStatus.AVAILABLE == SeatStatus.valueOf(it.status) - }, availableSex = Sex.valueOf(availableSex), availableGrade = availableGrade, eastDescription = eastDescription, @@ -46,24 +29,4 @@ data class UpdateStudyRoomRequest( southDescription = southDescription, northDescription = northDescription ) - - fun toStudyRoomTimeSlots(studyRoomId: UUID) = - timeSlotIds.map { - StudyRoomTimeSlot( - studyRoomId = studyRoomId, - timeSlotId = it - ) - } - - fun toSeats(studyRoomId: UUID) = - seats.map { - Seat( - studyRoomId = studyRoomId, - typeId = it.typeId, - widthLocation = it.widthLocation, - heightLocation = it.heightLocation, - number = it.number, - status = SeatStatus.valueOf(it.status) - ) - } } diff --git a/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomSeatsRequest.kt b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomSeatsRequest.kt new file mode 100644 index 000000000..a8fcf974a --- /dev/null +++ b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomSeatsRequest.kt @@ -0,0 +1,33 @@ +package team.aliens.dms.domain.studyroom.dto + +import team.aliens.dms.domain.studyroom.model.Seat +import team.aliens.dms.domain.studyroom.model.SeatStatus +import java.util.UUID + +data class UpdateStudyRoomSeatsRequest( + val seats: List +) { + val availableHeadCount: Int = seats.count { + SeatStatus.AVAILABLE == SeatStatus.valueOf(it.status) + } + + data class SeatRequest( + val widthLocation: Int, + val heightLocation: Int, + val number: Int?, + val typeId: UUID?, + val status: String + ) + + fun toSeats(studyRoomId: UUID) = + seats.map { + Seat( + studyRoomId = studyRoomId, + typeId = it.typeId, + widthLocation = it.widthLocation, + heightLocation = it.heightLocation, + number = it.number, + status = SeatStatus.valueOf(it.status) + ) + } +} diff --git a/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomTimeSlotRequest.kt b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomTimeSlotRequest.kt new file mode 100644 index 000000000..306522ba8 --- /dev/null +++ b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomTimeSlotRequest.kt @@ -0,0 +1,16 @@ +package team.aliens.dms.domain.studyroom.dto + +import team.aliens.dms.domain.studyroom.model.StudyRoomTimeSlot +import java.util.UUID + +data class UpdateStudyRoomTimeSlotRequest( + val timeSlotIds: List +) { + fun toStudyRoomTimeSlots(studyRoomId: UUID) = + timeSlotIds.map { + StudyRoomTimeSlot( + studyRoomId = studyRoomId, + timeSlotId = it + ) + } +} diff --git a/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/CreateStudyRoomUseCase.kt b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/CreateStudyRoomUseCase.kt index 31e907e6b..5e5bccabb 100644 --- a/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/CreateStudyRoomUseCase.kt +++ b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/CreateStudyRoomUseCase.kt @@ -1,10 +1,10 @@ package team.aliens.dms.domain.studyroom.usecase -import java.util.UUID import team.aliens.dms.common.annotation.UseCase import team.aliens.dms.domain.studyroom.dto.CreateStudyRoomRequest import team.aliens.dms.domain.studyroom.service.StudyRoomService import team.aliens.dms.domain.user.service.UserService +import java.util.UUID @UseCase class CreateStudyRoomUseCase( diff --git a/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/UpdateStudyRoomSeatsUseCase.kt b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/UpdateStudyRoomSeatsUseCase.kt new file mode 100644 index 000000000..8d58d2ca4 --- /dev/null +++ b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/UpdateStudyRoomSeatsUseCase.kt @@ -0,0 +1,27 @@ +package team.aliens.dms.domain.studyroom.usecase + +import team.aliens.dms.common.annotation.UseCase +import team.aliens.dms.domain.studyroom.dto.UpdateStudyRoomSeatsRequest +import team.aliens.dms.domain.studyroom.service.StudyRoomService +import java.util.UUID + +@UseCase +class UpdateStudyRoomSeatsUseCase( + private val studyRoomService: StudyRoomService +) { + + fun execute(request: UpdateStudyRoomSeatsRequest, studyRoomId: UUID) { + val studyRoom = studyRoomService.getStudyRoom(studyRoomId) + + studyRoomService.saveStudyRoom( + studyRoom.copy( + availableHeadcount = request.availableHeadCount + ) + ) + + studyRoomService.updateSeatsByStudyRoom( + studyRoomId = studyRoom.id, + seats = request.toSeats(studyRoom.id) + ) + } +} diff --git a/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/UpdateStudyRoomTimeSlotUseCase.kt b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/UpdateStudyRoomTimeSlotUseCase.kt new file mode 100644 index 000000000..559d2f3db --- /dev/null +++ b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/UpdateStudyRoomTimeSlotUseCase.kt @@ -0,0 +1,21 @@ +package team.aliens.dms.domain.studyroom.usecase + +import team.aliens.dms.common.annotation.UseCase +import team.aliens.dms.domain.studyroom.dto.UpdateStudyRoomTimeSlotRequest +import team.aliens.dms.domain.studyroom.service.StudyRoomService +import java.util.UUID + +@UseCase +class UpdateStudyRoomTimeSlotUseCase( + private val studyRoomService: StudyRoomService +) { + + fun execute(request: UpdateStudyRoomTimeSlotRequest, studyRoomId: UUID) { + val studyRoom = studyRoomService.getStudyRoom(studyRoomId) + + studyRoomService.updateTimeSlotsByStudyRoom( + studyRoomId = studyRoomId, + studyRoomTimeSlots = request.toStudyRoomTimeSlots(studyRoom.id) + ) + } +} diff --git a/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/UpdateStudyRoomUseCase.kt b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/UpdateStudyRoomUseCase.kt index 7d57a7c0d..d53127904 100644 --- a/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/UpdateStudyRoomUseCase.kt +++ b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/UpdateStudyRoomUseCase.kt @@ -23,15 +23,5 @@ class UpdateStudyRoomUseCase( studyRoomService.saveStudyRoom( request.toStudyRoom(studyRoom) ) - - studyRoomService.updateTimeSlotsByStudyRoom( - studyRoomId = studyRoom.id, - studyRoomTimeSlots = request.toStudyRoomTimeSlots(studyRoom.id) - ) - - studyRoomService.updateSeatsByStudyRoom( - studyRoomId = studyRoom.id, - seats = request.toSeats(studyRoom.id) - ) } } diff --git a/dms-presentation/src/main/kotlin/team/aliens/dms/domain/auth/AuthWebAdapter.kt b/dms-presentation/src/main/kotlin/team/aliens/dms/domain/auth/AuthWebAdapter.kt index 97695f211..cbd49908a 100644 --- a/dms-presentation/src/main/kotlin/team/aliens/dms/domain/auth/AuthWebAdapter.kt +++ b/dms-presentation/src/main/kotlin/team/aliens/dms/domain/auth/AuthWebAdapter.kt @@ -1,9 +1,5 @@ package team.aliens.dms.domain.auth -import javax.validation.Valid -import javax.validation.constraints.Email -import javax.validation.constraints.NotBlank -import javax.validation.constraints.NotNull import org.hibernate.validator.constraints.Length import org.springframework.validation.annotation.Validated import org.springframework.web.bind.annotation.GetMapping @@ -29,6 +25,10 @@ import team.aliens.dms.domain.auth.usecase.CheckAccountIdExistenceUseCase import team.aliens.dms.domain.auth.usecase.ReissueTokenUseCase import team.aliens.dms.domain.auth.usecase.SendEmailCodeUseCase import team.aliens.dms.domain.auth.usecase.SignInUseCase +import javax.validation.Valid +import javax.validation.constraints.Email +import javax.validation.constraints.NotBlank +import javax.validation.constraints.NotNull @Validated @RequestMapping("/auth") diff --git a/dms-presentation/src/main/kotlin/team/aliens/dms/domain/studyroom/StudyRoomWebAdapter.kt b/dms-presentation/src/main/kotlin/team/aliens/dms/domain/studyroom/StudyRoomWebAdapter.kt index ac25ff2ea..0019b096c 100644 --- a/dms-presentation/src/main/kotlin/team/aliens/dms/domain/studyroom/StudyRoomWebAdapter.kt +++ b/dms-presentation/src/main/kotlin/team/aliens/dms/domain/studyroom/StudyRoomWebAdapter.kt @@ -33,6 +33,10 @@ import team.aliens.dms.domain.studyroom.dto.StudentQueryStudyRoomResponse import team.aliens.dms.domain.studyroom.dto.StudentQueryStudyRoomsResponse import team.aliens.dms.domain.studyroom.dto.UpdateAvailableTimeWebRequest import team.aliens.dms.domain.studyroom.dto.UpdateStudyRoomRequest +import team.aliens.dms.domain.studyroom.dto.UpdateStudyRoomSeatsRequest +import team.aliens.dms.domain.studyroom.dto.UpdateStudyRoomSeatsWebRequest +import team.aliens.dms.domain.studyroom.dto.UpdateStudyRoomTimeSlotRequest +import team.aliens.dms.domain.studyroom.dto.UpdateStudyRoomTimeSlotWebRequest import team.aliens.dms.domain.studyroom.dto.UpdateStudyRoomWebRequest import team.aliens.dms.domain.studyroom.dto.UpdateTimeSlotWebRequest import team.aliens.dms.domain.studyroom.usecase.ApplySeatUseCase @@ -53,6 +57,8 @@ import team.aliens.dms.domain.studyroom.usecase.StudentQueryStudyRoomUseCase import team.aliens.dms.domain.studyroom.usecase.StudentQueryStudyRoomsUseCase import team.aliens.dms.domain.studyroom.usecase.UnApplySeatUseCase import team.aliens.dms.domain.studyroom.usecase.UpdateAvailableTimeUseCase +import team.aliens.dms.domain.studyroom.usecase.UpdateStudyRoomSeatsUseCase +import team.aliens.dms.domain.studyroom.usecase.UpdateStudyRoomTimeSlotUseCase import team.aliens.dms.domain.studyroom.usecase.UpdateStudyRoomUseCase import team.aliens.dms.domain.studyroom.usecase.UpdateTimeSlotUseCase import java.util.UUID @@ -83,7 +89,9 @@ class StudyRoomWebAdapter( private val queryTimeSlotsUseCase: QueryTimeSlotsUseCase, private val createTimeSlotUseCase: CreateTimeSlotUseCase, private val updateTimeSlotUseCase: UpdateTimeSlotUseCase, - private val removeTimeSlotUseCase: RemoveTimeSlotUseCase + private val removeTimeSlotUseCase: RemoveTimeSlotUseCase, + private val updateStudyRoomSeatsUseCase: UpdateStudyRoomSeatsUseCase, + private val updateStudyRoomTimeSlotUseCase: UpdateStudyRoomTimeSlotUseCase ) { @GetMapping("/available-time") @@ -187,22 +195,46 @@ class StudyRoomWebAdapter( southDescription = southDescription, northDescription = northDescription, availableSex = availableSex.name, - availableGrade = availableGrade, - timeSlotIds = timeSlotIds, - seats = seats.map { - UpdateStudyRoomRequest.SeatRequest( - widthLocation = it.widthLocation, - heightLocation = it.heightLocation, - number = it.number, - typeId = it.typeId, - status = it.status.name - ) - } + availableGrade = availableGrade ) } ) } + @ResponseStatus(HttpStatus.NO_CONTENT) + @PatchMapping("/{study-room-id}/seats") + fun updateStudyRoomSeats( + @PathVariable("study-room-id") @NotNull studyRoomId: UUID, + @RequestBody @Valid webRequest: UpdateStudyRoomSeatsWebRequest + ) { + updateStudyRoomSeatsUseCase.execute( + request = UpdateStudyRoomSeatsRequest( + webRequest.seats.map { + UpdateStudyRoomSeatsRequest.SeatRequest( + widthLocation = it.widthLocation, + heightLocation = it.heightLocation, + number = it.number, + typeId = it.typeId, + status = it.status.name + ) + } + ), + studyRoomId = studyRoomId + ) + } + + @ResponseStatus(HttpStatus.NO_CONTENT) + @PatchMapping("/{study-room-id}/time-slot") + fun updateStudyRoomTimeSlot( + @PathVariable("study-room-id") @NotNull studyRoomId: UUID, + @RequestBody @Valid webRequest: UpdateStudyRoomTimeSlotWebRequest + ) { + updateStudyRoomTimeSlotUseCase.execute( + request = UpdateStudyRoomTimeSlotRequest(webRequest.timeSlotIds), + studyRoomId = studyRoomId + ) + } + @GetMapping("/{study-room-id}/students") fun studentGetStudyRoom( @PathVariable("study-room-id") @NotNull studyRoomId: UUID, diff --git a/dms-presentation/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomSeatsWebRequest.kt b/dms-presentation/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomSeatsWebRequest.kt new file mode 100644 index 000000000..4bfba3b3b --- /dev/null +++ b/dms-presentation/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomSeatsWebRequest.kt @@ -0,0 +1,28 @@ +package team.aliens.dms.domain.studyroom.dto + +import java.util.UUID +import javax.validation.Valid +import javax.validation.constraints.Min +import javax.validation.constraints.NotNull + +data class UpdateStudyRoomSeatsWebRequest( + @field:Valid + val seats: List +) { + data class SeatWebRequest( + @field:NotNull + @field:Min(0) + val widthLocation: Int, + + @field:NotNull + @field:Min(0) + val heightLocation: Int, + + val number: Int?, + + val typeId: UUID?, + + @field:NotNull + val status: WebSeatStatus + ) +} diff --git a/dms-presentation/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomTimeSlotWebRequest.kt b/dms-presentation/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomTimeSlotWebRequest.kt new file mode 100644 index 000000000..deab5b037 --- /dev/null +++ b/dms-presentation/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomTimeSlotWebRequest.kt @@ -0,0 +1,7 @@ +package team.aliens.dms.domain.studyroom.dto + +import java.util.UUID + +data class UpdateStudyRoomTimeSlotWebRequest( + val timeSlotIds: List +) diff --git a/dms-presentation/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomWebRequest.kt b/dms-presentation/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomWebRequest.kt index 6e06cefd2..c868e48eb 100644 --- a/dms-presentation/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomWebRequest.kt +++ b/dms-presentation/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomWebRequest.kt @@ -1,8 +1,5 @@ package team.aliens.dms.domain.studyroom.dto -import team.aliens.dms.common.validator.NotNullElements -import java.util.UUID -import javax.validation.Valid import javax.validation.constraints.Min import javax.validation.constraints.NotBlank import javax.validation.constraints.NotNull @@ -47,33 +44,6 @@ data class UpdateStudyRoomWebRequest( @field:NotNull @field:Min(0) - val availableGrade: Int, + val availableGrade: Int - @field:Size(min = 1) - @field:NotNullElements - val timeSlotIds: List, - - @field:Valid - val seats: List - -) { - - data class SeatRequest( - - @field:NotNull - @field:Min(0) - val widthLocation: Int, - - @field:NotNull - @field:Min(0) - val heightLocation: Int, - - val number: Int?, - - val typeId: UUID?, - - @field:NotNull - val status: WebSeatStatus - - ) -} +)