From 5b5fa46be0aab876401c13046d8baeacd6e814de Mon Sep 17 00:00:00 2001 From: tedsoftj1123 Date: Wed, 10 May 2023 11:40:04 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20(#492)=20=EC=9E=90=EC=8A=B5?= =?UTF-8?q?=EC=8B=A4=20=EC=88=98=EC=A0=95=20web=20request=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../studyroom/dto/UpdateStudyRoomRequest.kt | 69 ------------------- .../domain/studyroom/StudyRoomWebAdapter.kt | 56 +++++++++++---- .../dto/UpdateStudyRoomSeatsWebRequest.kt | 28 ++++++++ .../dto/UpdateStudyRoomTimeSlotWebRequest.kt | 7 ++ .../dto/UpdateStudyRoomWebRequest.kt | 34 +-------- 5 files changed, 81 insertions(+), 113 deletions(-) delete mode 100644 dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomRequest.kt create mode 100644 dms-presentation/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomSeatsWebRequest.kt create mode 100644 dms-presentation/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomTimeSlotWebRequest.kt 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 deleted file mode 100644 index 8428a5a55..000000000 --- a/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomRequest.kt +++ /dev/null @@ -1,69 +0,0 @@ -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, - val name: String, - val totalWidthSize: Int, - val totalHeightSize: Int, - val eastDescription: String, - val westDescription: String, - val southDescription: String, - val northDescription: String, - val availableSex: String, - val availableGrade: Int, - val timeSlotIds: List, - val seats: List -) { - - 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, - westDescription = westDescription, - 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-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 - - ) -} +) From 2a8c06ea662308a2e438d4f77bf23638ad8dea8c Mon Sep 17 00:00:00 2001 From: tedsoftj1123 Date: Wed, 10 May 2023 11:40:36 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20(#492)=20usecase=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../studyroom/dto/UpdateStudyRoomRequest.kt | 32 ++++++++++++++++++ .../dto/UpdateStudyRoomSeatsRequest.kt | 33 +++++++++++++++++++ .../dto/UpdateStudyRoomTimeSlotRequest.kt | 16 +++++++++ .../usecase/CreateStudyRoomUseCase.kt | 2 +- .../usecase/UpdateStudyRoomSeatsUseCase.kt | 27 +++++++++++++++ .../usecase/UpdateStudyRoomTimeSlotUseCase.kt | 21 ++++++++++++ .../usecase/UpdateStudyRoomUseCase.kt | 10 ------ .../aliens/dms/domain/auth/AuthWebAdapter.kt | 8 ++--- 8 files changed, 134 insertions(+), 15 deletions(-) create mode 100644 dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomRequest.kt create mode 100644 dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomSeatsRequest.kt create mode 100644 dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomTimeSlotRequest.kt create mode 100644 dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/UpdateStudyRoomSeatsUseCase.kt create mode 100644 dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/UpdateStudyRoomTimeSlotUseCase.kt 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 new file mode 100644 index 000000000..5df9847a2 --- /dev/null +++ b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/dto/UpdateStudyRoomRequest.kt @@ -0,0 +1,32 @@ +package team.aliens.dms.domain.studyroom.dto + +import team.aliens.dms.domain.student.model.Sex +import team.aliens.dms.domain.studyroom.model.StudyRoom + +data class UpdateStudyRoomRequest( + val floor: Int, + val name: String, + val totalWidthSize: Int, + val totalHeightSize: Int, + val eastDescription: String, + val westDescription: String, + val southDescription: String, + val northDescription: String, + val availableSex: String, + val availableGrade: Int +) { + + fun toStudyRoom(studyRoom: StudyRoom) = + studyRoom.copy( + name = name, + floor = floor, + widthSize = totalWidthSize, + heightSize = totalHeightSize, + availableSex = Sex.valueOf(availableSex), + availableGrade = availableGrade, + eastDescription = eastDescription, + westDescription = westDescription, + southDescription = southDescription, + northDescription = northDescription + ) +} 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")