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: (#492) 자습실 수정 API분리 #497

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
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
@@ -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,
Expand All @@ -17,53 +13,20 @@ data class UpdateStudyRoomRequest(
val southDescription: String,
val northDescription: String,
val availableSex: String,
val availableGrade: Int,
val timeSlotIds: List<UUID>,
val seats: List<SeatRequest>
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,
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)
)
}
}
Original file line number Diff line number Diff line change
@@ -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<SeatRequest>
) {
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)
)
}
}
Original file line number Diff line number Diff line change
@@ -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<UUID>
) {
fun toStudyRoomTimeSlots(studyRoomId: UUID) =
timeSlotIds.map {
StudyRoomTimeSlot(
studyRoomId = studyRoomId,
timeSlotId = it
)
}
}
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
)
}
}
Original file line number Diff line number Diff line change
@@ -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)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SeatWebRequest>
) {
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
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package team.aliens.dms.domain.studyroom.dto

import java.util.UUID

data class UpdateStudyRoomTimeSlotWebRequest(
val timeSlotIds: List<UUID>
)
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<UUID>,

@field:Valid
val seats: List<SeatRequest>

) {

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

)
}
)