Skip to content

Commit

Permalink
Merge pull request #204 from GSM-MSG/update/03-05-meeting
Browse files Browse the repository at this point in the history
# 202 3/5 회의 내용 적용
  • Loading branch information
JuuuuHong authored Mar 11, 2024
2 parents 44ad1fe + 9ae8d3e commit 743350e
Show file tree
Hide file tree
Showing 61 changed files with 161 additions and 329 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package team.msg.hiv2.aspect

import org.aspectj.lang.JoinPoint
import org.aspectj.lang.annotation.Around
import org.aspectj.lang.annotation.Aspect
import org.aspectj.lang.annotation.Before
import org.aspectj.lang.annotation.Pointcut
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
Expand All @@ -17,11 +16,11 @@ class HomeBaseReservationInfoAspect(

private val log by lazy { LoggerFactory.getLogger(this.javaClass.simpleName) }

@Pointcut("execution(* team.msg.hiv2.domain.reservation.application.usecase.UpdateReservationUseCase.execute(..)) " +
@Pointcut("execution(* team.msg.hiv2.domain.homebase.application.usecase.ReserveHomeBaseUseCase.execute(..)) " +
"&& args(floor, period, request) && within(team.msg.hiv2.domain.homebase.application.usecase.ReserveHomeBaseUseCase)")
fun reserveHomeBaseUseCasePointcut(floor: Int, period: Int, request: ReservationHomeBaseRequest) {}
private fun reserveHomeBaseUseCasePointcut(floor: Int, period: Int, request: ReservationHomeBaseRequest) {}

@Around(
@Before(
"reserveHomeBaseUseCasePointcut(floor, period, request)"
)
private fun loggingReservationInfo(floor: Int, period: Int, request: ReservationHomeBaseRequest) {
Expand Down
19 changes: 17 additions & 2 deletions src/main/kotlin/team/msg/hiv2/aspect/NoticeVerifyWriterAspect.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,27 @@ class NoticeVerifyWriterAspect(
"&& args(id, updateNoticeRequest) && within(team.msg.hiv2.domain.notice.application.usecase.UpdateNoticeUseCase)")
private fun updateNoticeUseCasePointcut(id: UUID, updateNoticeRequest: UpdateNoticeRequest) {}

@Pointcut("execution(* team.msg.hiv2.domain.notice.application.usecase.DeleteNoticeUseCase.execute(..))" +
"&& args(id) && within(team.msg.hiv2.domain.notice.application.usecase.DeleteNoticeUseCase)")
private fun deleteNoticeUseCasePointcut(id: UUID) {}

@Before("updateNoticeUseCasePointcut(id, updateNoticeRequest)")
private fun checkWriter(id: UUID, updateNoticeRequest: UpdateNoticeRequest) {
val user = userService.queryCurrentUser()
val notice = noticeService.queryNoticeById(id)

if (user.roles.firstOrNull() == UserRole.ROLE_TEACHER)
if (user.role == UserRole.ROLE_TEACHER || user.role == UserRole.ROLE_ADMIN) {
val notice = noticeService.queryNoticeById(id)
userValidator.checkUserAndWriter(user.id, notice.userId)
}
}

@Before("deleteNoticeUseCasePointcut(id)")
private fun checkWriter(id: UUID) {
val user = userService.queryCurrentUser()

if (user.role == UserRole.ROLE_TEACHER || user.role == UserRole.ROLE_ADMIN) {
val notice = noticeService.queryNoticeById(id)
userValidator.checkUserAndWriter(user.id, notice.userId)
}
}
}
19 changes: 2 additions & 17 deletions src/main/kotlin/team/msg/hiv2/aspect/ReservationControlAspect.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package team.msg.hiv2.aspect
import org.aspectj.lang.annotation.Aspect
import org.aspectj.lang.annotation.Before
import org.aspectj.lang.annotation.Pointcut
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import team.msg.hiv2.domain.user.application.service.UserService
import team.msg.hiv2.domain.homebase.presentation.data.request.ReservationHomeBaseRequest
import team.msg.hiv2.domain.reservation.application.service.ReservationService
import team.msg.hiv2.domain.reservation.presentation.data.request.UpdateReservationRequest
import team.msg.hiv2.domain.user.application.service.UserService
import team.msg.hiv2.domain.user.application.validator.UserValidator
import java.util.*

Expand All @@ -20,20 +19,14 @@ class ReservationControlAspect(
private val userValidator: UserValidator
) {

private val log by lazy { LoggerFactory.getLogger(this.javaClass.simpleName) }

@Pointcut("execution(* team.msg.hiv2.domain.reservation.application.usecase.UpdateReservationUseCase.execute(..)) " +
@Pointcut("execution(* team.msg.hiv2.domain.homebase.application.usecase.ReserveHomeBaseUseCase.execute(..)) " +
"&& args(floor, period, request) && within(team.msg.hiv2.domain.homebase.application.usecase.ReserveHomeBaseUseCase)")
private fun reserveHomeBaseUseCasePointcut(floor: Int, period: Int, request: ReservationHomeBaseRequest) {}

@Pointcut("execution(* team.msg.hiv2.domain.reservation.application.usecase.UpdateReservationUseCase.execute(..))" +
" && args(reservationId, request) && within(team.msg.hiv2.domain.reservation.application.usecase.UpdateReservationUseCase)")
private fun updateReservationUseCasePointcut(reservationId: UUID, request: UpdateReservationRequest) {}

@Pointcut("execution(* team.msg.hiv2.domain.reservation.application.usecase.DelegateRepresentativeUseCase.execute(..)) " +
"&& args(reservationId, userId) && within(team.msg.hiv2.domain.reservation.application.usecase.DelegateRepresentativeUseCase)")
private fun delegateRepresentativeUseCasePointcut(reservationId: UUID, userId: UUID){}

@Pointcut("execution(* team.msg.hiv2.domain.reservation.application.usecase.DeleteReservationUseCase.execute(..))" +
" && args(reservationId) && within(team.msg.hiv2.domain.reservation.application.usecase.DeleteReservationUseCase)")
private fun deleteReservationUseCasePointcut(reservationId: UUID){}
Expand All @@ -58,14 +51,6 @@ class ReservationControlAspect(
userValidator.checkRepresentative(currentUser, reservation)
}

@Before("delegateRepresentativeUseCasePointcut(reservationId, userId)")
private fun checkAuthorizationDelegateRepresentative(reservationId: UUID, userId: UUID) {
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class GAuthSignInUseCase(
classNum = gAuthUserInfo.classNum,
number = gAuthUserInfo.num,
profileImageUrl = gAuthUserInfo.profileUrl ?: "",
roles = mutableListOf(role),
role = role,
reservationId = null,
useStatus = UseStatus.AVAILABLE
),
userService.existsUserByEmail(gAuthUserInfo.email),
)

return generateJwtPort.generate(user.id, user.roles)
return generateJwtPort.generate(user.id, user.role)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ class ReissueTokenUseCase(

val user = userService.queryUserById(token.userId)

return generateJwtPort.generate(user.id, user.roles)
return generateJwtPort.generate(user.id, user.role)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import team.msg.hiv2.domain.homebase.presentation.data.request.ReservationHomeBa
import team.msg.hiv2.domain.reservation.application.service.ReservationService
import team.msg.hiv2.domain.reservation.domain.Reservation
import team.msg.hiv2.domain.user.application.service.UserService
import team.msg.hiv2.domain.user.application.validator.UserValidator
import team.msg.hiv2.domain.user.domain.constant.UseStatus
import team.msg.hiv2.global.annotation.usecase.UseCase
import java.util.*
Expand All @@ -19,16 +18,20 @@ class ReserveHomeBaseUseCase(
private val homeBaseService: HomeBaseService
) {

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

val currentUser = userService.queryCurrentUser()

val homeBase = homeBaseService.queryHomeBaseByFloorAndPeriod(floor, period)

val users = userService.queryAllUserById(request.users)

if(reservationService.countReservationByHomeBase(homeBase) >= 5)
throw ForbiddenReserveException()
val reservationCount = reservationService.countReservationByHomeBase(homeBase)
when(floor) {
2 -> if(reservationCount > 3) throw ForbiddenReserveException()
3 -> if(reservationCount > 5) throw ForbiddenReserveException()
4 -> if(reservationCount > 5) throw ForbiddenReserveException()
}

if(reservationService.existsByHomeBaseAndReservationNumber(homeBase, request.reservationNumber))
throw AlreadyExistReservationException()
Expand All @@ -45,8 +48,7 @@ class ReserveHomeBaseUseCase(
).id

userService.saveAll(users.map {
it.copy(reservationId = reservationId, useStatus = UseStatus.UNAVAILABLE)
}
)
it.copy(reservationId = reservationId, useStatus = UseStatus.UNAVAILABLE)
})
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package team.msg.hiv2.domain.homebase.presentation

import javax.validation.Valid
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.DeleteMapping
Expand All @@ -10,13 +11,9 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import team.msg.hiv2.domain.homebase.application.facade.HomeBaseFacade
import team.msg.hiv2.domain.homebase.application.usecase.DeleteAllReservationByPeriodUseCase
import team.msg.hiv2.domain.homebase.application.usecase.QueryReservationByHomeBaseUseCase
import team.msg.hiv2.domain.homebase.application.usecase.ReserveHomeBaseUseCase
import team.msg.hiv2.domain.homebase.presentation.data.request.ReservationHomeBaseRequest
import team.msg.hiv2.domain.homebase.presentation.data.web.ReservationHomeBaseWebRequest
import team.msg.hiv2.domain.reservation.presentation.data.response.ReservationResponse
import javax.validation.Valid

@RestController
@RequestMapping("/homebase")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
package team.msg.hiv2.domain.notice.application.usecase

import team.msg.hiv2.domain.notice.application.service.NoticeService
import team.msg.hiv2.domain.user.application.service.UserService
import team.msg.hiv2.domain.user.application.validator.UserValidator
import team.msg.hiv2.domain.user.domain.constant.UserRole
import team.msg.hiv2.global.annotation.usecase.UseCase
import team.msg.hiv2.global.error.exception.InvalidRoleException
import java.util.UUID
import java.util.*

@UseCase
class DeleteNoticeUseCase(
private val noticeService: NoticeService,
private val userService: UserService,
private val userValidator: UserValidator
private val noticeService: NoticeService
) {
fun execute(id: UUID) {
val user = userService.queryCurrentUser()
val notice = noticeService.queryNoticeById(id)
val role = user.roles.firstOrNull() ?: throw InvalidRoleException()

if(role == UserRole.ROLE_TEACHER)
userValidator.checkUserAndWriter(user.id, notice.userId)

noticeService.delete(notice)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import java.util.UUID

interface ReservationFacade {
fun checkAndRestrictReservation(id: UUID)
fun delegateRepresentative(reservationId: UUID, userId: UUID)
fun deleteAllReservation()
fun deleteReservation(id: UUID)
fun exitReservation(id: UUID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import java.util.*
@Component
class ReservationFacadeImpl(
private val checkAndRestrictReservationUserUseCase: CheckAndRestrictReservationUserUseCase,
private val delegateRepresentativeUseCase: DelegateRepresentativeUseCase,
private val deleteAllReservationUseCase: DeleteAllReservationUseCase,
private val deleteReservationUseCase: DeleteReservationUseCase,
private val exitReservationUseCase: ExitReservationUseCase,
Expand All @@ -22,9 +21,6 @@ class ReservationFacadeImpl(
override fun checkAndRestrictReservation(id: UUID) =
checkAndRestrictReservationUserUseCase.execute(id)

override fun delegateRepresentative(reservationId: UUID, userId: UUID) =
delegateRepresentativeUseCase.execute(reservationId, userId)

override fun deleteAllReservation() =
deleteAllReservationUseCase.execute()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,38 @@ package team.msg.hiv2.domain.reservation.application.scheduler

import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component
import team.msg.hiv2.domain.homebase.application.service.HomeBaseService
import team.msg.hiv2.domain.homebase.application.usecase.DeleteAllReservationByPeriodUseCase
import team.msg.hiv2.domain.reservation.application.service.ReservationService
import team.msg.hiv2.domain.reservation.application.usecase.CheckAndRestrictReservationUserUseCase
import team.msg.hiv2.domain.user.application.service.UserService
import team.msg.hiv2.domain.user.domain.constant.UseStatus

@Component
class ReservationScheduler(
private val deleteAllReservationByPeriodUseCase: DeleteAllReservationByPeriodUseCase,
private val checkAndRestrictReservationUserUseCase: CheckAndRestrictReservationUserUseCase,
private val reservationService: ReservationService,
private val homeBaseService: HomeBaseService
private val userService: UserService
) {

/**
* 매일 5시 30분에 8교시 예약 테이블 삭제와 유저 정지 여부 검증
* 매일 08시 30분에 전체 예약 테이블 삭제와 유저 정지 여부 검증
*/
@Scheduled(cron = "0 30 17 * * *", zone = "Asia/Seoul")
fun resetAll8PeriodReservation() = checkAndDelete(8)
@Scheduled(cron = "0 30 8 ? * MON-FRI", zone = "Asia/Seoul")
fun resetAllReservation() = checkAndDelete()

private fun checkAndDelete(){

/**
* 매일 6시 30분에 8교시 예약 테이블 삭제와 유저 정지 여부 검증
*/
@Scheduled(cron = "0 30 18 * * *", zone = "Asia/Seoul")
fun resetAll9PeriodReservation() = checkAndDelete(9)
val reservations = reservationService.queryAllReservation()

/**
* 매일 8시 20분에 8교시 예약 테이블 삭제와 유저 정지 여부 검증
*/
@Scheduled(cron = "0 20 20 * * *", zone = "Asia/Seoul")
fun resetAll10PeriodReservation() = checkAndDelete(10)
val users = userService.queryAllUserByReservationIn(reservations)

/**
* 매일 9시 20분에 8교시 예약 테이블 삭제와 유저 정지 여부 검증
*/
@Scheduled(cron = "0 20 21 * * *", zone = "Asia/Seoul")
fun resetAll11PeriodReservation() = checkAndDelete(11)

private fun checkAndDelete(period: Int){

val homeBases = homeBaseService.queryAllHomeBaseByPeriod(period)

val reservations = reservationService.queryAllReservationByHomeBaseIn(homeBases)

reservations.forEach {
checkAndRestrictReservationUserUseCase.execute(it.id)
val updatedUsers = users.map {
val reservation = reservationService.queryReservationById(it.reservationId!!)
when(reservation.checkStatus) {
true -> it.copy(useStatus = UseStatus.AVAILABLE, reservationId = null)
false -> it.copy(useStatus = UseStatus.UNAVAILABLE, reservationId = null)
}
}

deleteAllReservationByPeriodUseCase.execute(period)
userService.saveAll(updatedUsers)

reservationService.deleteAllReservationInBatch(reservations)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface QueryReservationService {
fun queryReservationById(id: UUID): Reservation
fun queryAllReservationByHomeBase(homeBase: HomeBase): List<Reservation>
fun queryAllReservationByHomeBaseIn(homeBases: List<HomeBase>): List<Reservation>
fun queryAllReservation(): List<Reservation>
fun countReservationByHomeBase(homeBase: HomeBase): Int
fun existsByHomeBaseAndReservationNumber(homeBase: HomeBase, reservationNumber: Int): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ class QueryReservationServiceImpl(
override fun queryAllReservationByHomeBaseIn(homeBases: List<HomeBase>): List<Reservation> =
queryReservationPort.queryAllReservationByHomeBaseIn(homeBases)

override fun queryAllReservation(): List<Reservation> =
queryReservationPort.queryAllReservations()

override fun countReservationByHomeBase(homeBase: HomeBase): Int =
queryReservationPort.countReservationByHomeBase(homeBase)

override fun existsByHomeBaseAndReservationNumber(homeBase: HomeBase,reservationNumber: Int): Boolean =
queryReservationPort.existsByHomeBaseAndReservationNumber(homeBase, reservationNumber)


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface QueryReservationPort {
fun queryReservationById(id: UUID): Reservation?
fun queryAllReservationByHomeBase(homeBase: HomeBase): List<Reservation>
fun queryAllReservationByHomeBaseIn(homeBases: List<HomeBase>): List<Reservation>
fun queryAllReservations(): List<Reservation>
fun countReservationByHomeBase(homeBase: HomeBase): Int
fun existsByHomeBaseAndReservationNumber(homeBase: HomeBase, reservationNumber: Int): Boolean
}

This file was deleted.

Loading

0 comments on commit 743350e

Please sign in to comment.