Skip to content

Commit

Permalink
Merge pull request #206 from GSM-MSG/205-update/combine-api
Browse files Browse the repository at this point in the history
# 205 대표자 삭제
  • Loading branch information
JuuuuHong authored Mar 12, 2024
2 parents 743350e + 5643060 commit e190401
Show file tree
Hide file tree
Showing 28 changed files with 37 additions and 87 deletions.
16 changes: 0 additions & 16 deletions src/main/kotlin/team/msg/hiv2/aspect/ReservationControlAspect.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,6 @@ class ReservationControlAspect(
userValidator.checkUsersUseStatus(userService.queryAllUserById(request.users))
}

@Before("updateReservationUseCasePointcut(reservationId, request)")
private fun checkAuthorizationUpdateReservation(reservationId: UUID, request: UpdateReservationRequest) {
val currentUser = userService.queryCurrentUser()
val reservation = reservationService.queryReservationById(reservationId)

userValidator.checkRepresentative(currentUser, reservation)
}

@Before("deleteReservationUseCasePointcut(reservationId)")
private fun checkAuthorizationDeleteReservation(reservationId: UUID) {
val currentUser = userService.queryCurrentUser()
val reservation = reservationService.queryReservationById(reservationId)

userValidator.checkRepresentative(currentUser, reservation)
}

@Before("exitReservationUseCasePointcut(reservationId)")
private fun checkAuthorizationExitReservation(reservationId: UUID) {
val currentUser = userService.queryCurrentUser()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class GAuthSignInUseCase(
) {

fun execute(request: GAuthSignInRequest): TokenResponse{

val gAuthToken = gAuthPort.queryGAuthToken(request.code)

val gAuthUserInfo = gAuthPort.queryGAuthUserInfo(gAuthToken.accessToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class ReserveHomeBaseUseCase(

fun execute(floor: Int, period: Int, request: ReservationHomeBaseRequest) {

val currentUser = userService.queryCurrentUser()

val homeBase = homeBaseService.queryHomeBaseByFloorAndPeriod(floor, period)

val users = userService.queryAllUserById(request.users)
Expand All @@ -40,7 +38,6 @@ class ReserveHomeBaseUseCase(
Reservation(
id = UUID.randomUUID(),
reason = request.reason,
representativeId = currentUser.id,
homeBaseId = homeBase.id,
checkStatus = false,
reservationNumber = request.reservationNumber
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package team.msg.hiv2.domain.homebase.domain

import team.msg.hiv2.global.annotation.Aggregate
import java.time.LocalDateTime
import java.util.*

@Aggregate
data class HomeBase(
val id: Long,
val floor: Int,
val period: Int,
val period: Int
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package team.msg.hiv2.domain.homebase.persistence.entity

import javax.persistence.Column
import team.msg.hiv2.global.entity.BaseIdEntity
import javax.persistence.Entity
import javax.persistence.Table
Expand All @@ -10,8 +11,10 @@ class HomeBaseJpaEntity(

override val id: Long,

@Column(name = "floor", nullable = false)
val floor: Int,

@Column(name = "period", nullable = false)
val period: Int

) : BaseIdEntity(id)
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ class DeleteReservationUseCase(

val users = userService.queryAllUserByReservation(reservation)

val updatedUsers = users.map {
if (it.id == reservation.representativeId) {
it.copy(useStatus = UseStatus.UNAVAILABLE, reservationId = null)
} else {
it.copy(useStatus = UseStatus.AVAILABLE, reservationId = null)
}
}
val updatedUsers = users.map { it.copy(useStatus = UseStatus.UNAVAILABLE, reservationId = null) }

userService.saveAll(updatedUsers)
reservationService.delete(reservation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ import java.util.UUID
@UseCase
class ExitReservationUseCase(
private val userService: UserService,
private val reservationService: ReservationService,
private val reservationService: ReservationService
) {

fun execute(reservationId: UUID){
val reservation = reservationService.queryReservationById(reservationId)

val currentUser = userService.queryCurrentUser()

if(reservation.representativeId == currentUser.id)
// count 로 바꾸기
val users = userService.queryAllUserByReservation(reservation)

if(users.size < 3)
throw ForbiddenExitReservationException()

userService.save(currentUser.copy(reservationId = null, useStatus = UseStatus.AVAILABLE))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import java.util.*
@Aggregate
data class Reservation(
val id: UUID,
val representativeId: UUID,
val homeBaseId: Long,
val reason: String,
val checkStatus: Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package team.msg.hiv2.domain.reservation.persistence.entity

import team.msg.hiv2.domain.homebase.persistence.entity.HomeBaseJpaEntity
import team.msg.hiv2.domain.user.persistence.entity.UserJpaEntity
import team.msg.hiv2.global.entity.BaseUuidEntity
import java.util.*
import javax.persistence.*
Expand All @@ -16,10 +15,6 @@ class ReservationJpaEntity(
@JoinColumn(name = "home_base_id")
val homeBase: HomeBaseJpaEntity,

@OneToOne
@JoinColumn(name = "representative_id")
val user: UserJpaEntity,

@Column(nullable = false)
val reason: String,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@ import team.msg.hiv2.domain.homebase.exception.HomeBaseNotFoundException
import team.msg.hiv2.domain.homebase.persistence.repository.HomeBaseRepository
import team.msg.hiv2.domain.reservation.domain.Reservation
import team.msg.hiv2.domain.reservation.persistence.entity.ReservationJpaEntity
import team.msg.hiv2.domain.user.exception.UserNotFoundException
import team.msg.hiv2.domain.user.persistence.repository.UserRepository
import team.msg.hiv2.global.mapper.GenericMapper

@Component
class ReservationMapper(
private val userRepository: UserRepository,
private val homeBaseRepository: HomeBaseRepository
) : GenericMapper<Reservation, ReservationJpaEntity> {

override fun toDomain(entity: ReservationJpaEntity?): Reservation? =
entity?.let {
Reservation(
id = it.id,
representativeId = it.user.id,
homeBaseId = it.homeBase.id,
reason = it.reason,
checkStatus = it.checkStatus,
Expand All @@ -29,14 +25,11 @@ class ReservationMapper(
}

override fun toEntity(domain: Reservation): ReservationJpaEntity {
val user = userRepository.findByIdOrNull(domain.representativeId)
?: throw UserNotFoundException()
val homeBase = homeBaseRepository.findByIdOrNull(domain.homeBaseId)
?: throw HomeBaseNotFoundException()
return domain.let {
ReservationJpaEntity(
id = it.id,
user = user,
homeBase = homeBase,
reason = it.reason,
checkStatus = it.checkStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ data class ReservationDetailResponse(
val users: List<UserResponse>,
val reason: String,
val checkStatus: Boolean,
val reservationNumber: Int,
val representativeId: UUID
val reservationNumber: Int
) {
companion object {
fun of(reservation: Reservation, users: List<UserResponse>) = ReservationDetailResponse(
reservationId = reservation.id,
users = users,
reason = reservation.reason,
checkStatus = reservation.checkStatus,
reservationNumber = reservation.reservationNumber,
representativeId = reservation.representativeId
reservationNumber = reservation.reservationNumber
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import java.util.*
data class ReservationResponse(
val reservationId: UUID,
val users: List<UserResponse>,
val representativeId: UUID,
val reservationNumber: Int,
val homeBaseId: Long,
val floor: Int,
Expand All @@ -19,7 +18,6 @@ data class ReservationResponse(
fun of(reservation: Reservation, users: List<UserResponse>, homeBase: HomeBase) = ReservationResponse(
reservationId = reservation.id,
users = users,
representativeId = reservation.representativeId,
reservationNumber = reservation.reservationNumber,
homeBaseId = homeBase.id,
floor = homeBase.floor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface QueryUserService {
fun queryAllUserByReservationIsNotNull(): List<User>
fun queryAllUsersOrderByEmail(): List<User>
fun queryAllUserByRoleContaining(role: UserRole): List<User>
fun queryAllUserByRoleContainingOrderByEmail(role: UserRole): List<User>
fun queryAllUserByNameContainingAndRoleContainingOrderByEmail(keyword: String, role: UserRole): List<User>
fun queryAllUserByRoleOrderByEmail(role: UserRole): List<User>
fun queryAllUserByNameContainingAndRoleOrderByEmail(keyword: String, role: UserRole): List<User>
fun queryAllUserByReservationIn(reservations: List<Reservation>): List<User>
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class QueryUserServiceImpl(
override fun queryAllUserByRoleContaining(role: UserRole): List<User> =
queryUserPort.queryAllUserByRoleContaining(role)

override fun queryAllUserByRoleContainingOrderByEmail(role: UserRole): List<User> =
queryUserPort.queryAllUserByRoleContainingOrderByEmail(role)
override fun queryAllUserByRoleOrderByEmail(role: UserRole): List<User> =
queryUserPort.queryAllUserByRoleOrderByEmail(role)

override fun queryAllUserByNameContainingAndRoleContainingOrderByEmail(keyword: String,role: UserRole) =
queryUserPort.queryAllUserByNameContainingAndRoleContainingOrderByEmail(keyword, role)
override fun queryAllUserByNameContainingAndRoleOrderByEmail(keyword: String, role: UserRole) =
queryUserPort.queryAllUserByNameContainingAndRoleOrderByEmail(keyword, role)

override fun queryAllUserByReservationIn(reservations: List<Reservation>): List<User> =
queryUserPort.queryAllUserByReservationIn(reservations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface QueryUserPort {
fun queryAllUserByReservationIsNotNull(): List<User>
fun queryAllUsersOrderByEmail(): List<User>
fun queryAllUserByRoleContaining(role: UserRole): List<User>
fun queryAllUserByRoleContainingOrderByEmail(role: UserRole): List<User>
fun queryAllUserByNameContainingAndRoleContainingOrderByEmail(keyword: String,role: UserRole): List<User>
fun queryAllUserByRoleOrderByEmail(role: UserRole): List<User>
fun queryAllUserByNameContainingAndRoleOrderByEmail(keyword: String, role: UserRole): List<User>
fun queryAllUserByReservationIn(reservations: List<Reservation>): List<User>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class QueryAllUsersByUserRoleUseCase(
) {

fun execute(userRole: UserRole): AllUsersResponse {
val users = userService.queryAllUserByRoleContainingOrderByEmail(userRole)
val users = userService.queryAllUserByRoleOrderByEmail(userRole)

return AllUsersResponse(
users.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SearchStudentByNameKeywordUseCase(
) {

fun execute(request: SearchUserKeywordRequest): List<StudentResponse> {
val users = userService.queryAllUserByNameContainingAndRoleContainingOrderByEmail(request.keyword, UserRole.ROLE_STUDENT)
val users = userService.queryAllUserByNameContainingAndRoleOrderByEmail(request.keyword, UserRole.ROLE_STUDENT)
return users.map { StudentResponse.of(it) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ interface UserValidator {

fun checkUserUseStatus(user: User)
fun checkUsersUseStatus(users: List<User>)
fun checkRepresentative(user: User, reservation: Reservation)
fun checkUserAndReservation(user: User, reservation: Reservation)
fun checkUserAndWriter(userId: UUID, noticeWriterId: UUID)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ class UserValidatorImpl : UserValidator {
users.forEach { checkUserUseStatus(it) }
}

override fun checkRepresentative(user: User, reservation: Reservation) {
if(user.id != reservation.representativeId) {
log.warn("User {} is not authorized to update Reservation {}", user.id, reservation.id)
throw ForbiddenCommandReservationException()
}
}

override fun checkUserAndReservation(user: User, reservation: Reservation) {
if(user.reservationId != reservation.id) {
log.warn("User {} is not contained in a reservation {}", user.id, reservation.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ class UserPersistenceAdapter(
override fun queryAllUserByRoleContaining(role: UserRole): List<User> =
userRepository.findAllByRoleContaining(role).map { userMapper.toDomain(it)!! }

override fun queryAllUserByRoleContainingOrderByEmail(role: UserRole): List<User> =
userRepository.findAllByRoleContainingOrderByEmail(role).map { userMapper.toDomain(it)!! }
override fun queryAllUserByRoleOrderByEmail(role: UserRole): List<User> =
userRepository.findAllByRoleOrderByEmail(role).map { userMapper.toDomain(it)!! }

override fun queryAllUserByNameContainingAndRoleContainingOrderByEmail(keyword: String,role: UserRole): List<User> =
userRepository.findAllByNameContainingAndRoleContainingOrderByEmail(keyword, role).map { userMapper.toDomain(it)!! }
override fun queryAllUserByNameContainingAndRoleOrderByEmail(keyword: String, role: UserRole): List<User> =
userRepository.findAllByNameContainingAndRoleOrderByEmail(keyword, role).map { userMapper.toDomain(it)!! }

override fun queryAllUserByReservationIn(reservations: List<Reservation>): List<User> =
userRepository.findAllByReservationIn(reservations.map { reservationMapper.toEntity(it) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ interface UserRepository : CrudRepository<UserJpaEntity, UUID> {
fun findAllByReservationIsNotNull(): List<UserJpaEntity>
fun findAllByRoleContaining(role: UserRole): List<UserJpaEntity>
fun findAllByOrderByEmail(): List<UserJpaEntity>
fun findAllByRoleContainingOrderByEmail(role: UserRole): List<UserJpaEntity>
fun findAllByNameContainingAndRoleContainingOrderByEmail(keyword: String,role: UserRole): List<UserJpaEntity>
fun findAllByRoleOrderByEmail(role: UserRole): List<UserJpaEntity>
fun findAllByNameContainingAndRoleOrderByEmail(keyword: String, role: UserRole): List<UserJpaEntity>
@EntityGraph(attributePaths = ["reservation"])
fun findAllByReservationIn(reservations: List<ReservationJpaEntity>): List<UserJpaEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class QueryReservationByHomeBaseUseCaseTest {
private val reservationStub by lazy {
Reservation(
id = reservationId1,
representativeId = representativeId1,
homeBaseId = homeBaseId,
reason = reason,
checkStatus = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ internal class ReserveHomeBaseUseCaseTest {

private val userId = UUID.randomUUID()
private val userId2 = UUID.randomUUID()
private val reservationCount = 3

private val requestStub by lazy {
ReservationHomeBaseRequest(
Expand All @@ -60,7 +61,6 @@ internal class ReserveHomeBaseUseCaseTest {
Reservation(
id = UUID.randomUUID(),
homeBaseId = homeBaseStub.id,
representativeId = userId,
reason = reason,
checkStatus = false,
reservationNumber = reservationNumber
Expand Down Expand Up @@ -104,12 +104,12 @@ internal class ReserveHomeBaseUseCaseTest {
useStatus = UseStatus.AVAILABLE
)

given(userService.queryCurrentUser()).willReturn(userStub)

given(homeBaseService.queryHomeBaseByFloorAndPeriod(floor, period)).willReturn(homeBaseStub)

given(userService.queryAllUserById(requestStub.users)).willReturn(listOf(userStub, userStub2))

given(reservationService.countReservationByHomeBase(homeBaseStub)).willReturn(reservationCount)

given(reservationService.save(any())).willReturn(reservationStub)

assertDoesNotThrow {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class DeleteReservationUseCaseTest {
private val reservationStub by lazy {
Reservation(
id = UUID.randomUUID(),
representativeId = representativeId,
reason = reason,
homeBaseId = homeBaseStub.id,
checkStatus = false,
Expand Down
Loading

0 comments on commit e190401

Please sign in to comment.