Skip to content

Commit

Permalink
Merge pull request #208 from GSM-MSG/207-update/reservation-user-rela…
Browse files Browse the repository at this point in the history
…tionship

# 207 Team Entity 추가
  • Loading branch information
JuuuuHong authored Mar 17, 2024
2 parents e190401 + 5dc01fe commit 7c0e99e
Show file tree
Hide file tree
Showing 119 changed files with 642 additions and 344 deletions.
2 changes: 0 additions & 2 deletions src/main/kotlin/team/msg/hiv2/aspect/HttpLoggingAspect.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import org.springframework.stereotype.Component
import org.springframework.web.context.request.RequestContextHolder
import org.springframework.web.context.request.ServletRequestAttributes
import java.util.*
import kotlin.collections.HashMap
import kotlin.collections.HashSet


@Aspect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.aspectj.lang.annotation.Pointcut
import org.springframework.stereotype.Component
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 @@ -23,14 +22,6 @@ class ReservationControlAspect(
"&& 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.DeleteReservationUseCase.execute(..))" +
" && args(reservationId) && within(team.msg.hiv2.domain.reservation.application.usecase.DeleteReservationUseCase)")
private fun deleteReservationUseCasePointcut(reservationId: UUID){}

@Pointcut("execution(* team.msg.hiv2.domain.reservation.application.usecase.ExitReservationUseCase.execute(..))" +
" && args(reservationId) && within(team.msg.hiv2.domain.reservation.application.usecase.ExitReservationUseCase)")
private fun exitReservationUseCasePointcut(reservationId: UUID){}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import team.msg.hiv2.domain.auth.presentation.data.response.GAuthLinkResponse
import team.msg.hiv2.domain.auth.presentation.data.response.TokenResponse

interface AuthFacade {

fun gAuthSignIn(request: GAuthSignInRequest): TokenResponse
fun logout(refreshToken: String)
fun reissue(requestToken: String): TokenResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AuthFacadeImpl(
private val logoutUseCase: LogoutUseCase,
private val queryGAuthLoginLinkUseCase: QueryGAuthLoginLinkUseCase,
private val reissueTokenUseCase: ReissueTokenUseCase
) : AuthFacade{
) : AuthFacade {

override fun gAuthSignIn(request: GAuthSignInRequest): TokenResponse =
gAuthSignInUseCase.execute(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package team.msg.hiv2.domain.auth.application.service
import team.msg.hiv2.domain.auth.domain.RefreshToken

interface CommandRefreshTokenService {

fun save(refreshToken: RefreshToken): String
fun delete(refreshToken: RefreshToken)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import team.msg.hiv2.global.annotation.service.DomainService
@DomainService
class CommandRefreshTokenServiceImpl(
private val commandRefreshTokenPort: CommandRefreshTokenPort
) : CommandRefreshTokenService{
) : CommandRefreshTokenService {

override fun save(refreshToken: RefreshToken): String =
commandRefreshTokenPort.save(refreshToken)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package team.msg.hiv2.domain.auth.application.service
import team.msg.hiv2.domain.auth.domain.RefreshToken

interface QueryRefreshTokenService {

fun queryByRefreshToken(refreshToken: String): RefreshToken
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ class QueryRefreshTokenServiceImpl(

override fun queryByRefreshToken(refreshToken: String): RefreshToken =
queryRefreshTokenPort.queryByRefreshToken(refreshToken) ?: throw RefreshTokenNotFoundException()

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import team.msg.hiv2.global.annotation.service.DomainService
class RefreshTokenService(
queryRefreshTokenService: QueryRefreshTokenService,
commandRefreshTokenService: CommandRefreshTokenService
) : CommandRefreshTokenService by commandRefreshTokenService
, QueryRefreshTokenService by queryRefreshTokenService
) : CommandRefreshTokenService by commandRefreshTokenService,
QueryRefreshTokenService by queryRefreshTokenService
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GAuthSignInUseCase(
private val generateJwtPort: GenerateJwtPort
) {

fun execute(request: GAuthSignInRequest): TokenResponse{
fun execute(request: GAuthSignInRequest): TokenResponse {

val gAuthToken = gAuthPort.queryGAuthToken(request.code)

Expand All @@ -35,7 +35,6 @@ class GAuthSignInUseCase(
number = gAuthUserInfo.num,
profileImageUrl = gAuthUserInfo.profileUrl ?: "",
role = role,
reservationId = null,
useStatus = UseStatus.AVAILABLE
),
userService.existsUserByEmail(gAuthUserInfo.email),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ package team.msg.hiv2.domain.auth.exception
import team.msg.hiv2.global.error.ErrorCode
import team.msg.hiv2.global.error.exception.HiException

class InvalidRefreshTokenException : HiException(ErrorCode.INVALID_TOKEN) {
}
class InvalidRefreshTokenException : HiException(ErrorCode.INVALID_TOKEN)
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package team.msg.hiv2.domain.auth.persistence.entity
import org.springframework.data.annotation.Id
import org.springframework.data.redis.core.RedisHash
import org.springframework.data.redis.core.TimeToLive
import team.msg.hiv2.domain.auth.domain.RefreshToken
import java.util.UUID
import java.util.*
import java.util.concurrent.TimeUnit

@RedisHash("refresh_token")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import team.msg.hiv2.domain.auth.persistence.entity.RefreshTokenEntity
import team.msg.hiv2.global.mapper.GenericMapper

@Component
class RefreshTokenMapper() : GenericMapper<RefreshToken, RefreshTokenEntity> {
class RefreshTokenMapper : GenericMapper<RefreshToken, RefreshTokenEntity> {

override fun toDomain(entity: RefreshTokenEntity?): RefreshToken? =
entity?.let {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package team.msg.hiv2.domain.auth.persistence.repository

import org.springframework.data.repository.CrudRepository
import org.springframework.scheduling.support.SimpleTriggerContext
import team.msg.hiv2.domain.auth.persistence.entity.RefreshTokenEntity

interface RefreshTokenRepository : CrudRepository<RefreshTokenEntity, String>
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package team.msg.hiv2.domain.auth.presentation

import javax.validation.Valid
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import team.msg.hiv2.domain.auth.application.facade.AuthFacade
import team.msg.hiv2.domain.auth.application.usecase.GAuthSignInUseCase
import team.msg.hiv2.domain.auth.application.usecase.LogoutUseCase
import team.msg.hiv2.domain.auth.application.usecase.QueryGAuthLoginLinkUseCase
import team.msg.hiv2.domain.auth.application.usecase.ReissueTokenUseCase
import team.msg.hiv2.domain.auth.presentation.data.request.GAuthSignInRequest
import team.msg.hiv2.domain.auth.presentation.data.response.GAuthLinkResponse
import team.msg.hiv2.domain.auth.presentation.data.response.TokenResponse
import team.msg.hiv2.domain.auth.presentation.data.web.GAuthSignInWebRequest
import javax.validation.Valid

@RestController
@RequestMapping("/auth")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import team.msg.hiv2.domain.homebase.presentation.data.request.ReservationHomeBa
import team.msg.hiv2.domain.reservation.presentation.data.response.ReservationResponse

interface HomeBaseFacade {

fun deleteAllReservationByPeriod(period: Int)
fun queryReservationByHomeBase(floor: Int, period: Int): List<ReservationResponse>
fun reserveHomeBase(floor: Int, period: Int, request: ReservationHomeBaseRequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class HomeBaseFacadeImpl(
private val deleteAllReservationByPeriodUseCase: DeleteAllReservationByPeriodUseCase,
private val queryReservationByHomeBaseUseCase: QueryReservationByHomeBaseUseCase,
private val reserveHomeBaseUseCase: ReserveHomeBaseUseCase
) : HomeBaseFacade{
) : HomeBaseFacade {

override fun deleteAllReservationByPeriod(period: Int) =
deleteAllReservationByPeriodUseCase.execute(period)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import team.msg.hiv2.global.annotation.service.DomainService
class QueryHomeBaseServiceImpl(
private val queryHomeBasePort: QueryHomeBasePort
) : QueryHomeBaseService {

override fun queryHomeBaseByFloorAndPeriod(floor: Int, period: Int): HomeBase =
queryHomeBasePort.queryHomeBaseByFloorAndPeriod(floor, period) ?: throw HomeBaseNotFoundException()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@ package team.msg.hiv2.domain.homebase.application.usecase

import team.msg.hiv2.domain.homebase.application.service.HomeBaseService
import team.msg.hiv2.domain.reservation.application.service.ReservationService
import team.msg.hiv2.domain.user.application.service.UserService
import team.msg.hiv2.domain.user.domain.constant.UseStatus
import team.msg.hiv2.domain.team.application.service.TeamService
import team.msg.hiv2.domain.team.persistence.mapper.TeamMapper
import team.msg.hiv2.domain.team.persistence.repository.TeamRepository
import team.msg.hiv2.global.annotation.usecase.UseCase

@UseCase
class DeleteAllReservationByPeriodUseCase(
private val homeBaseService: HomeBaseService,
private val reservationService: ReservationService,
private val userService: UserService
private val teamService: TeamService,
private val teamRepository: TeamRepository,
private val teamMapper: TeamMapper
) {

fun execute(period: Int){
fun execute(period: Int) {

val homeBases = homeBaseService.queryAllHomeBaseByPeriod(period)

val reservations = reservationService.queryAllReservationByHomeBaseIn(homeBases)

val users = userService.queryAllUserByReservationIn(reservations)
val teams = teamService.queryAllTeamByIdIn(reservations.map { it.teamId })

userService.saveAll(users.map { it.copy(useStatus = UseStatus.AVAILABLE, reservationId = null) })
reservationService.deleteAllReservationInBatch(reservations)
teamRepository.deleteAll(teams.map { teamMapper.toEntity(it) })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package team.msg.hiv2.domain.homebase.application.usecase

import team.msg.hiv2.domain.homebase.application.service.QueryHomeBaseService
import team.msg.hiv2.domain.reservation.application.service.ReservationService
import team.msg.hiv2.domain.reservation.presentation.data.response.HomeBaseResponse
import team.msg.hiv2.domain.reservation.presentation.data.response.ReservationResponse
import team.msg.hiv2.domain.team.application.service.TeamService
import team.msg.hiv2.domain.user.application.service.UserService
import team.msg.hiv2.domain.user.presentation.data.response.UserResponse
import team.msg.hiv2.global.annotation.usecase.ReadOnlyUseCase
Expand All @@ -11,18 +13,24 @@ import team.msg.hiv2.global.annotation.usecase.ReadOnlyUseCase
class QueryReservationByHomeBaseUseCase(
private val reservationService: ReservationService,
private val homeBaseService: QueryHomeBaseService,
private val userService: UserService
private val userService: UserService,
private val teamService: TeamService
) {

fun execute(floor: Int, period: Int): List<ReservationResponse>{
fun execute(floor: Int, period: Int): List<ReservationResponse> {

val homeBase = homeBaseService.queryHomeBaseByFloorAndPeriod(floor, period)

val reservations = reservationService.queryAllReservationByHomeBase(homeBase)

return reservations.map {
val users = userService.queryAllUserByReservation(it)
ReservationResponse.of(it, users.map { user
-> UserResponse.of(user) }, homeBase)
val team = teamService.queryTeamById(it.teamId)
val users = userService.queryAllUserById(team.userIds)
ReservationResponse.of(
it,
users.map { user -> UserResponse.of(user) },
HomeBaseResponse(homeBase.id, floor, period)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import team.msg.hiv2.domain.homebase.exception.ForbiddenReserveException
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.domain.Reservation
import team.msg.hiv2.domain.team.application.service.TeamService
import team.msg.hiv2.domain.team.domain.Team
import team.msg.hiv2.domain.user.application.service.UserService
import team.msg.hiv2.domain.user.domain.constant.UseStatus
import team.msg.hiv2.domain.user.exception.UserNotFoundException
import team.msg.hiv2.global.annotation.usecase.UseCase
import java.util.*

@UseCase
class ReserveHomeBaseUseCase(
private val userService: UserService,
private val reservationService: ReservationService,
private val homeBaseService: HomeBaseService
private val homeBaseService: HomeBaseService,
private val teamService: TeamService
) {

fun execute(floor: Int, period: Int, request: ReservationHomeBaseRequest) {
Expand All @@ -24,6 +27,9 @@ class ReserveHomeBaseUseCase(

val users = userService.queryAllUserById(request.users)

if (request.users.size != users.size)
throw UserNotFoundException()

val reservationCount = reservationService.countReservationByHomeBase(homeBase)
when(floor) {
2 -> if(reservationCount > 3) throw ForbiddenReserveException()
Expand All @@ -34,18 +40,22 @@ class ReserveHomeBaseUseCase(
if(reservationService.existsByHomeBaseAndReservationNumber(homeBase, request.reservationNumber))
throw AlreadyExistReservationException()

val reservationId = reservationService.save(
val team = teamService.save(
Team(
id = UUID.randomUUID(),
userIds = users.map { it.id }.toMutableList()
)
)

reservationService.save(
Reservation(
id = UUID.randomUUID(),
reason = request.reason,
homeBaseId = homeBase.id,
teamId = team.id,
checkStatus = false,
reservationNumber = request.reservationNumber
)
).id

userService.saveAll(users.map {
it.copy(reservationId = reservationId, useStatus = UseStatus.UNAVAILABLE)
})
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import team.msg.hiv2.domain.homebase.persistence.entity.HomeBaseJpaEntity
import team.msg.hiv2.global.mapper.GenericMapper

@Component
class HomeBaseMapper : GenericMapper<HomeBase, HomeBaseJpaEntity>{
class HomeBaseMapper : GenericMapper<HomeBase, HomeBaseJpaEntity> {

override fun toDomain(entity: HomeBaseJpaEntity?): HomeBase? =
entity?.let{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package team.msg.hiv2.domain.homebase.persistence.repository

import org.springframework.data.repository.CrudRepository
import team.msg.hiv2.domain.homebase.persistence.entity.HomeBaseJpaEntity
import java.util.UUID

interface HomeBaseRepository : CrudRepository<HomeBaseJpaEntity, Long>{
interface HomeBaseRepository : CrudRepository<HomeBaseJpaEntity, Long> {

fun findByFloorAndPeriod(floor: Int, period: Int): HomeBaseJpaEntity?
fun findAllByPeriod(period: Int): List<HomeBaseJpaEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import team.msg.hiv2.domain.notice.presentation.data.response.NoticeResponse
import java.util.*

interface NoticeFacade {

fun createNotice(request: CreateNoticeRequest)
fun deleteNotice(id: UUID)
fun queryAllNotice(): List<NoticeResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ import team.msg.hiv2.global.annotation.service.DomainService
class NoticeService(
queryNoticeService: QueryNoticeService,
commandNoticeService: CommandNoticeService
) : QueryNoticeService by queryNoticeService, CommandNoticeService by commandNoticeService
) : QueryNoticeService by queryNoticeService,
CommandNoticeService by commandNoticeService
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package team.msg.hiv2.domain.notice.persistence.entity

import team.msg.hiv2.domain.user.persistence.entity.UserJpaEntity
import team.msg.hiv2.global.entity.BaseUuidEntity
import java.time.LocalDateTime
import java.util.*
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.JoinColumn
import javax.persistence.ManyToOne
import javax.persistence.Table
import team.msg.hiv2.domain.user.persistence.entity.UserJpaEntity
import team.msg.hiv2.global.entity.BaseUuidEntity
import java.util.*

@Entity
@Table(name = "notice")
Expand All @@ -23,5 +22,6 @@ class NoticeJpaEntity(

@ManyToOne
@JoinColumn(name = "user_id")
val user: UserJpaEntity,
val user: UserJpaEntity

) : BaseUuidEntity(id)
Loading

0 comments on commit 7c0e99e

Please sign in to comment.