diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/dto/SaveMenuRequest.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/dto/SaveMenuRequest.kt new file mode 100644 index 00000000..dd72ac57 --- /dev/null +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/dto/SaveMenuRequest.kt @@ -0,0 +1,22 @@ +package team.comit.simtong.domain.menu.dto + +import java.io.File +import java.util.UUID + +/** + * + * 메뉴 저장 요청 정보를 전달하는 SaveMenuRequest + * + * @author Chokyunghyeon + * @date 2022/12/17 + * @version 1.0.0 + **/ +data class SaveMenuRequest( + val file: File, + + val year: Int, + + val month: Int, + + val spotId: UUID +) \ No newline at end of file diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/usecase/QueryMenuByMonthUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/usecase/QueryMenuByMonthUseCase.kt index 9968ed24..26e3592b 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/usecase/QueryMenuByMonthUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/usecase/QueryMenuByMonthUseCase.kt @@ -23,11 +23,11 @@ class QueryMenuByMonthUseCase( private val menuSecurityPort: MenuSecurityPort ) { - fun execute(date: LocalDate): MenuResponse { + fun execute(startAt: LocalDate, endAt: LocalDate): MenuResponse { val currentUserId = menuSecurityPort.getCurrentUserId() val user = queryUserPort.queryUserById(currentUserId) ?: throw UserExceptions.NotFound() - val menu = queryMenuPort.queryMenusByMonthAndSpotId(date, user.spotId) + val menu = queryMenuPort.queryMenusByPeriodAndSpotId(startAt, endAt, user.spotId) val result = menu.map { MenuResponse.MenuElement(it.date, it.meal) } return MenuResponse(result) diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/usecase/QueryPublicMenuUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/usecase/QueryPublicMenuUseCase.kt index 9f6ed746..b66aebd1 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/usecase/QueryPublicMenuUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/usecase/QueryPublicMenuUseCase.kt @@ -19,8 +19,8 @@ class QueryPublicMenuUseCase( private val queryMenuPort: QueryMenuPort, ) { - fun execute(date: LocalDate): MenuResponse { - val menu = queryMenuPort.queryMenusByMonthAndSpotName(date, Spot.HEAD_SHOP) + fun execute(startAt: LocalDate, endAt: LocalDate): MenuResponse { + val menu = queryMenuPort.queryMenusByPeriodAndSpotName(startAt, endAt, Spot.HEAD_SHOP) val result = menu.map { MenuResponse.MenuElement(it.date, it.meal) } return MenuResponse(result) diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/usecase/SaveMenuUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/usecase/SaveMenuUseCase.kt index f895a1c7..515a4679 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/usecase/SaveMenuUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/usecase/SaveMenuUseCase.kt @@ -1,13 +1,12 @@ package team.comit.simtong.domain.menu.usecase +import team.comit.simtong.domain.menu.dto.SaveMenuRequest import team.comit.simtong.domain.menu.exception.MenuExceptions import team.comit.simtong.domain.menu.spi.CommandMenuPort import team.comit.simtong.domain.menu.spi.ParseMenuFilePort import team.comit.simtong.domain.menu.spi.QueryMenuPort import team.comit.simtong.global.annotation.UseCase -import java.io.File import java.time.LocalDate -import java.util.UUID /** * @@ -24,10 +23,12 @@ class SaveMenuUseCase( private val commandMenuPort: CommandMenuPort ) { - fun execute(file: File, year: Int, month: Int, spotId: UUID) { + fun execute(request: SaveMenuRequest) { + val (file, year, month, spotId) = request + val menu = parseMenuFilePort.importMenu(file, year, month, spotId) - if (queryMenuPort.queryMenusByMonthAndSpotId(LocalDate.of(year, month, 1), spotId).isNotEmpty()) { + if (queryMenuPort.existsMenuByMonthAndSpotId(LocalDate.of(year, month, 1), spotId)) { throw MenuExceptions.AlreadyExistsSameMonth("${year}년 ${month}월 메뉴가 이미 존재합니다.") } diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/QueryEntireSpotScheduleUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/QueryEntireSpotScheduleUseCase.kt index 8ad811ac..d87e4148 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/QueryEntireSpotScheduleUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/QueryEntireSpotScheduleUseCase.kt @@ -20,8 +20,8 @@ class QueryEntireSpotScheduleUseCase( private val querySchedulePort: QuerySchedulePort ) { - fun execute(date: LocalDate): QueryEntireSpotScheduleResponse { - val list = querySchedulePort.querySpotSchedulesByMonthAndScope(date, Scope.ENTIRE) + fun execute(startAt: LocalDate, endAt: LocalDate): QueryEntireSpotScheduleResponse { + val list = querySchedulePort.querySpotSchedulesByPeriodAndScope(startAt, endAt, Scope.ENTIRE) val response = list.map { SpotScheduleResponse( diff --git a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/QueryIndividualSpotScheduleUseCase.kt b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/QueryIndividualSpotScheduleUseCase.kt index 5987e211..8a1feb0c 100644 --- a/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/QueryIndividualSpotScheduleUseCase.kt +++ b/simtong-application/src/main/kotlin/team/comit/simtong/domain/schedule/usecase/QueryIndividualSpotScheduleUseCase.kt @@ -25,16 +25,16 @@ class QueryIndividualSpotScheduleUseCase( private val securityPort: ScheduleSecurityPort ) { - fun execute(date: LocalDate): QueryIndividualSpotScheduleResponse { + fun execute(startAt: LocalDate, endAt: LocalDate): QueryIndividualSpotScheduleResponse { val user = queryUserPort.queryUserById(securityPort.getCurrentUserId()) ?: throw UserExceptions.NotFound() - val individualSchedules = querySchedulePort.querySchedulesByMonthAndUserIdAndScope( - date, user.id, Scope.INDIVIDUAL + val individualSchedules = querySchedulePort.querySchedulesByPeriodAndUserIdAndScope( + startAt, endAt, user.id, Scope.INDIVIDUAL ) - val ownSpotSchedules = querySchedulePort.querySchedulesByMonthAndSpotIdAndScope( - date, user.spotId, Scope.ENTIRE + val ownSpotSchedules = querySchedulePort.querySchedulesByPeriodAndSpotIdAndScope( + startAt, endAt, user.spotId, Scope.ENTIRE ) val schedules = (ownSpotSchedules + individualSchedules) // 개인 일정과 소속 지점 일정 합치기 diff --git a/simtong-application/src/test/kotlin/team/comit/simtong/domain/holiday/usecase/QueryIndividualHolidayUseCaseTests.kt b/simtong-application/src/test/kotlin/team/comit/simtong/domain/holiday/usecase/QueryIndividualHolidayUseCaseTests.kt index 2c3afe38..fa6001ac 100644 --- a/simtong-application/src/test/kotlin/team/comit/simtong/domain/holiday/usecase/QueryIndividualHolidayUseCaseTests.kt +++ b/simtong-application/src/test/kotlin/team/comit/simtong/domain/holiday/usecase/QueryIndividualHolidayUseCaseTests.kt @@ -28,7 +28,7 @@ class QueryIndividualHolidayUseCaseTests { private val userId: UUID = UUID.randomUUID() - private val dateStub: LocalDate = LocalDate.now() + private val date: LocalDate = LocalDate.now() private val holidaysStub: List by lazy { listOf( @@ -66,11 +66,11 @@ class QueryIndividualHolidayUseCaseTests { given(securityPort.getCurrentUserId()) .willReturn(userId) - given(queryHolidayPort.queryHolidaysByPeriodAndUserId(dateStub, dateStub, userId)) + given(queryHolidayPort.queryHolidaysByPeriodAndUserId(date, date, userId)) .willReturn(holidaysStub) // when - val response = queryIndividualHolidayUseCase.execute(dateStub, dateStub) + val response = queryIndividualHolidayUseCase.execute(date, date) // then assertEquals(response, responseStub) diff --git a/simtong-application/src/test/kotlin/team/comit/simtong/domain/menu/usecase/QueryMenuByMonthUseCaseTests.kt b/simtong-application/src/test/kotlin/team/comit/simtong/domain/menu/usecase/QueryMenuByMonthUseCaseTests.kt index 13e49f16..1e53fdca 100644 --- a/simtong-application/src/test/kotlin/team/comit/simtong/domain/menu/usecase/QueryMenuByMonthUseCaseTests.kt +++ b/simtong-application/src/test/kotlin/team/comit/simtong/domain/menu/usecase/QueryMenuByMonthUseCaseTests.kt @@ -80,13 +80,13 @@ class QueryMenuByMonthUseCaseTests { given(queryUserPort.queryUserById(currentUserId)) .willReturn(userStub) - given(queryMenuPort.queryMenusByMonthAndSpotId(now, userStub.spotId)) + given(queryMenuPort.queryMenusByPeriodAndSpotId(now, now, userStub.spotId)) .willReturn( listOf(menuStub, menuStub2) ) // when - val response = queryMenuByMonthUseCase.execute(now) + val response = queryMenuByMonthUseCase.execute(now, now) // then assertThat(response).isNotNull @@ -103,7 +103,7 @@ class QueryMenuByMonthUseCaseTests { // when & then assertThrows { - queryMenuByMonthUseCase.execute(now) + queryMenuByMonthUseCase.execute(now, now) } } diff --git a/simtong-application/src/test/kotlin/team/comit/simtong/domain/menu/usecase/QueryPublicMenuUseCaseTests.kt b/simtong-application/src/test/kotlin/team/comit/simtong/domain/menu/usecase/QueryPublicMenuUseCaseTests.kt index cda0d71a..f334d3a4 100644 --- a/simtong-application/src/test/kotlin/team/comit/simtong/domain/menu/usecase/QueryPublicMenuUseCaseTests.kt +++ b/simtong-application/src/test/kotlin/team/comit/simtong/domain/menu/usecase/QueryPublicMenuUseCaseTests.kt @@ -45,13 +45,13 @@ class QueryPublicMenuUseCaseTests { fun `메뉴 조회 성공`() { // given val now = LocalDate.now() - given(queryMenuPort.queryMenusByMonthAndSpotName(now, Spot.HEAD_SHOP)) + given(queryMenuPort.queryMenusByPeriodAndSpotName(now, now, Spot.HEAD_SHOP)) .willReturn( listOf(menuStub, menuStub2) ) // when - val response = queryPublicMenuUseCase.execute(now) + val response = queryPublicMenuUseCase.execute(now, now) // then Assertions.assertThat(response).isNotNull diff --git a/simtong-application/src/test/kotlin/team/comit/simtong/domain/menu/usecase/SaveMenuUseCaseTests.kt b/simtong-application/src/test/kotlin/team/comit/simtong/domain/menu/usecase/SaveMenuUseCaseTests.kt index 65f3c8d4..992a9674 100644 --- a/simtong-application/src/test/kotlin/team/comit/simtong/domain/menu/usecase/SaveMenuUseCaseTests.kt +++ b/simtong-application/src/test/kotlin/team/comit/simtong/domain/menu/usecase/SaveMenuUseCaseTests.kt @@ -6,6 +6,7 @@ import org.junit.jupiter.api.assertDoesNotThrow import org.junit.jupiter.api.assertThrows import org.mockito.kotlin.given import org.springframework.boot.test.mock.mockito.MockBean +import team.comit.simtong.domain.menu.dto.SaveMenuRequest import team.comit.simtong.domain.menu.exception.MenuExceptions import team.comit.simtong.domain.menu.model.Menu import team.comit.simtong.domain.menu.spi.CommandMenuPort @@ -43,6 +44,15 @@ class SaveMenuUseCaseTests { ) } + private val requestStub: SaveMenuRequest by lazy { + SaveMenuRequest( + file = fileStub, + year = year, + month = month, + spotId = spotId + ) + } + @BeforeEach fun setUp() { saveMenuUseCase = SaveMenuUseCase( @@ -58,12 +68,12 @@ class SaveMenuUseCaseTests { given(parseMenuFilePort.importMenu(fileStub, year, month, spotId)) .willReturn(listOf(menuStub)) - given(queryMenuPort.queryMenusByMonthAndSpotId(LocalDate.of(year, month, 1), spotId)) - .willReturn(emptyList()) + given(queryMenuPort.existsMenuByMonthAndSpotId(LocalDate.of(year, month, 1), spotId)) + .willReturn(false) // when & then assertDoesNotThrow { - saveMenuUseCase.execute(fileStub, year, month, spotId) + saveMenuUseCase.execute(requestStub) } } @@ -73,12 +83,12 @@ class SaveMenuUseCaseTests { given(parseMenuFilePort.importMenu(fileStub, year, month, spotId)) .willReturn(listOf(menuStub)) - given(queryMenuPort.queryMenusByMonthAndSpotId(LocalDate.of(year, month, 1), spotId)) - .willReturn(listOf(menuStub)) + given(queryMenuPort.existsMenuByMonthAndSpotId(LocalDate.of(year, month, 1), spotId)) + .willReturn(true) // when & then assertThrows { - saveMenuUseCase.execute(fileStub, year, month, spotId) + saveMenuUseCase.execute(requestStub) } } diff --git a/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/QueryEntireSpotScheduleUseCaseTests.kt b/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/QueryEntireSpotScheduleUseCaseTests.kt index 8f686091..42344f11 100644 --- a/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/QueryEntireSpotScheduleUseCaseTests.kt +++ b/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/QueryEntireSpotScheduleUseCaseTests.kt @@ -62,11 +62,11 @@ class QueryEntireSpotScheduleUseCaseTests { @Test fun `전체 지점 일정 조회 성공`() { // given - given(querySchedulePort.querySpotSchedulesByMonthAndScope(date, Scope.ENTIRE)) + given(querySchedulePort.querySpotSchedulesByPeriodAndScope(date, date, Scope.ENTIRE)) .willReturn(spotScheduleListStub) // when - val response = queryEntireSpotScheduleUseCase.execute(date) + val response = queryEntireSpotScheduleUseCase.execute(date, date) // then assertEquals(response, responseStub) diff --git a/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/QueryIndividualSpotScheduleUseCaseTests.kt b/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/QueryIndividualSpotScheduleUseCaseTests.kt index 7bd9fcf2..0d41932f 100644 --- a/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/QueryIndividualSpotScheduleUseCaseTests.kt +++ b/simtong-application/src/test/kotlin/team/comit/simtong/domain/schedule/usecase/QueryIndividualSpotScheduleUseCaseTests.kt @@ -124,18 +124,18 @@ class QueryIndividualSpotScheduleUseCaseTests { given(queryUserPort.queryUserById(userId)) .willReturn(userStub) - given(querySchedulePort.querySchedulesByMonthAndUserIdAndScope(date, userStub.id, Scope.INDIVIDUAL)) + given(querySchedulePort.querySchedulesByPeriodAndUserIdAndScope(date, date, userStub.id, Scope.INDIVIDUAL)) .willReturn( listOf(individualScheduleStub) ) - given(querySchedulePort.querySchedulesByMonthAndSpotIdAndScope(date, userStub.spotId, Scope.ENTIRE)) + given(querySchedulePort.querySchedulesByPeriodAndSpotIdAndScope(date, date, userStub.spotId, Scope.ENTIRE)) .willReturn( listOf(entireScheduleStub) ) // when - val response = queryIndividualSpotScheduleUseCase.execute(date) + val response = queryIndividualSpotScheduleUseCase.execute(date, date) // then assertThat(response).isEqualTo(responseStub) @@ -152,7 +152,7 @@ class QueryIndividualSpotScheduleUseCaseTests { // when & then assertThrows { - queryIndividualSpotScheduleUseCase.execute(date) + queryIndividualSpotScheduleUseCase.execute(date, date) } } diff --git a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/menu/spi/QueryMenuPort.kt b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/menu/spi/QueryMenuPort.kt index 61c67123..ed3516c0 100644 --- a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/menu/spi/QueryMenuPort.kt +++ b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/menu/spi/QueryMenuPort.kt @@ -15,8 +15,10 @@ import java.util.UUID **/ interface QueryMenuPort { - fun queryMenusByMonthAndSpotId(date: LocalDate, spotId: UUID): List + fun existsMenuByMonthAndSpotId(date: LocalDate, spotId: UUID): Boolean - fun queryMenusByMonthAndSpotName(date: LocalDate, spotName: String): List + fun queryMenusByPeriodAndSpotId(startAt: LocalDate, endAt: LocalDate, spotId: UUID): List + + fun queryMenusByPeriodAndSpotName(startAt: LocalDate, endAt: LocalDate, spotName: String): List } \ No newline at end of file diff --git a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/schedule/spi/QuerySchedulePort.kt b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/schedule/spi/QuerySchedulePort.kt index cdce75f3..d405b8f9 100644 --- a/simtong-domain/src/main/kotlin/team/comit/simtong/domain/schedule/spi/QuerySchedulePort.kt +++ b/simtong-domain/src/main/kotlin/team/comit/simtong/domain/schedule/spi/QuerySchedulePort.kt @@ -18,10 +18,10 @@ interface QuerySchedulePort { fun queryScheduleById(id: UUID): Schedule? - fun querySpotSchedulesByMonthAndScope(date: LocalDate, scope: Scope): List + fun querySpotSchedulesByPeriodAndScope(startAt: LocalDate, endAt: LocalDate, scope: Scope): List - fun querySchedulesByMonthAndSpotIdAndScope(date: LocalDate, spotId: UUID, scope: Scope): List + fun querySchedulesByPeriodAndSpotIdAndScope(startAt: LocalDate, endAt: LocalDate, spotId: UUID, scope: Scope): List - fun querySchedulesByMonthAndUserIdAndScope(date: LocalDate, userId: UUID, scope: Scope): List + fun querySchedulesByPeriodAndUserIdAndScope(startAt: LocalDate, endAt: LocalDate, userId: UUID, scope: Scope): List } \ No newline at end of file diff --git a/simtong-infrastructure/src/main/kotlin/team/comit/simtong/global/security/SecurityConfig.kt b/simtong-infrastructure/src/main/kotlin/team/comit/simtong/global/security/SecurityConfig.kt index e9cef524..d0342f04 100644 --- a/simtong-infrastructure/src/main/kotlin/team/comit/simtong/global/security/SecurityConfig.kt +++ b/simtong-infrastructure/src/main/kotlin/team/comit/simtong/global/security/SecurityConfig.kt @@ -73,7 +73,7 @@ class SecurityConfig( // menu .antMatchers(HttpMethod.GET, "/menu/public").permitAll() - .antMatchers(HttpMethod.POST, "/menu").permitAll() + .antMatchers(HttpMethod.POST, "/menu/{spot-id}").permitAll() // files .antMatchers(HttpMethod.POST, "/files").permitAll() diff --git a/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/menu/MenuPersistenceAdapter.kt b/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/menu/MenuPersistenceAdapter.kt index 453495df..bfce9239 100644 --- a/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/menu/MenuPersistenceAdapter.kt +++ b/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/menu/MenuPersistenceAdapter.kt @@ -1,15 +1,13 @@ package team.comit.simtong.persistence.menu -import com.querydsl.core.types.dsl.BooleanExpression +import team.comit.simtong.persistence.menu.entity.QMenuJpaEntity.menuJpaEntity as menu import com.querydsl.jpa.impl.JPAQueryFactory import org.springframework.stereotype.Component import team.comit.simtong.domain.menu.model.Menu import team.comit.simtong.domain.menu.spi.MenuPort import team.comit.simtong.persistence.QuerydslExtensionUtils.sameMonthFilter -import team.comit.simtong.persistence.menu.entity.QMenuJpaEntity.menuJpaEntity import team.comit.simtong.persistence.menu.mapper.MenuMapper import team.comit.simtong.persistence.menu.repository.MenuJpaRepository -import team.comit.simtong.persistence.spot.entity.QSpotJpaEntity.spotJpaEntity import java.time.LocalDate import java.util.UUID @@ -29,28 +27,36 @@ class MenuPersistenceAdapter( private val queryFactory: JPAQueryFactory ) : MenuPort { - override fun queryMenusByMonthAndSpotId(date: LocalDate, spotId: UUID): List { + override fun existsMenuByMonthAndSpotId(date: LocalDate, spotId: UUID): Boolean { return queryFactory - .selectFrom(menuJpaEntity) - .join(menuJpaEntity.spot, spotJpaEntity) - .on(spotJpaEntity.id.eq(spotId)) + .selectFrom(menu) .where( - sameMonthMenuFilter(date) + menu.menuId.spotId.eq(spotId), + menu.menuId.date.sameMonthFilter(date) ) - .orderBy(menuJpaEntity.menuId.date.asc()) + .fetchOne() != null + } + + override fun queryMenusByPeriodAndSpotId(startAt: LocalDate, endAt: LocalDate, spotId: UUID): List { + return queryFactory + .selectFrom(menu) + .where( + menu.menuId.spotId.eq(spotId), + menu.menuId.date.between(startAt, endAt) + ) + .orderBy(menu.menuId.date.asc()) .fetch() .map { menuMapper.toDomain(it)!! } } - override fun queryMenusByMonthAndSpotName(date: LocalDate, spotName: String): List { + override fun queryMenusByPeriodAndSpotName(startAt: LocalDate, endAt: LocalDate, spotName: String): List { return queryFactory - .selectFrom(menuJpaEntity) - .join(menuJpaEntity.spot, spotJpaEntity) - .on(spotJpaEntity.name.eq(spotName)) + .selectFrom(menu) .where( - sameMonthMenuFilter(date) + menu.spot.name.eq(spotName), + menu.menuId.date.between(startAt, endAt) ) - .orderBy(menuJpaEntity.menuId.date.asc()) + .orderBy(menu.menuId.date.asc()) .fetch() .map { menuMapper.toDomain(it)!! } } @@ -61,8 +67,4 @@ class MenuPersistenceAdapter( ) } - private fun sameMonthMenuFilter(date: LocalDate) : BooleanExpression { - return menuJpaEntity.menuId.date.sameMonthFilter(date) - } - } \ No newline at end of file diff --git a/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/schedule/SchedulePersistenceAdapter.kt b/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/schedule/SchedulePersistenceAdapter.kt index fa4541ca..5a5ac2d4 100644 --- a/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/schedule/SchedulePersistenceAdapter.kt +++ b/simtong-infrastructure/src/main/kotlin/team/comit/simtong/persistence/schedule/SchedulePersistenceAdapter.kt @@ -10,7 +10,6 @@ import team.comit.simtong.domain.schedule.model.Schedule import team.comit.simtong.domain.schedule.model.Scope import team.comit.simtong.domain.schedule.spi.SchedulePort import team.comit.simtong.domain.schedule.vo.SpotSchedule -import team.comit.simtong.persistence.QuerydslExtensionUtils.sameMonthFilter import team.comit.simtong.persistence.schedule.mapper.ScheduleMapper import team.comit.simtong.persistence.schedule.vo.QSpotScheduleVo import java.time.LocalDate @@ -48,7 +47,7 @@ class SchedulePersistenceAdapter( .let(scheduleMapper::toDomain) } - override fun querySpotSchedulesByMonthAndScope(date: LocalDate, scope: Scope): List { + override fun querySpotSchedulesByPeriodAndScope(startAt: LocalDate, endAt: LocalDate, scope: Scope): List { return queryFactory .select( QSpotScheduleVo( @@ -65,40 +64,40 @@ class SchedulePersistenceAdapter( .on(schedule.spot.eq(spot)) .where( schedule.scope.eq(scope), - sameMonthScheduleFilter(date) + inPeriodScheduleFilter(startAt, endAt) ) .orderBy(schedule.startAt.asc()) .fetch() } - override fun querySchedulesByMonthAndSpotIdAndScope(date: LocalDate, spotId: UUID, scope: Scope): List { + override fun querySchedulesByPeriodAndSpotIdAndScope(startAt: LocalDate, endAt: LocalDate, spotId: UUID, scope: Scope): List { return queryFactory .selectFrom(schedule) .where( schedule.scope.eq(scope), schedule.spot.id.eq(spotId), - sameMonthScheduleFilter(date) + inPeriodScheduleFilter(startAt, endAt) ) .orderBy(schedule.startAt.asc()) .fetch() .map { scheduleMapper.toDomain(it)!! } } - override fun querySchedulesByMonthAndUserIdAndScope(date: LocalDate, userId: UUID, scope: Scope): List { + override fun querySchedulesByPeriodAndUserIdAndScope(startAt: LocalDate, endAt: LocalDate, userId: UUID, scope: Scope): List { return queryFactory .selectFrom(schedule) .where( schedule.user.id.eq(userId), schedule.scope.eq(scope), - sameMonthScheduleFilter(date) + inPeriodScheduleFilter(startAt, endAt) ) .orderBy(schedule.startAt.asc()) .fetch() .map { scheduleMapper.toDomain(it)!! } } - private fun sameMonthScheduleFilter(date: LocalDate) : BooleanExpression { - return schedule.startAt.sameMonthFilter(date) - .or(schedule.endAt.sameMonthFilter(date)) + private fun inPeriodScheduleFilter(startAt: LocalDate, endAt: LocalDate) : BooleanExpression { + return schedule.startAt.between(startAt, endAt) + .or(schedule.endAt.between(startAt, endAt)) } } \ No newline at end of file diff --git a/simtong-presentation/src/main/kotlin/team/comit/simtong/domain/holiday/WebHolidayAdapter.kt b/simtong-presentation/src/main/kotlin/team/comit/simtong/domain/holiday/WebHolidayAdapter.kt index 64230a18..05d7030c 100644 --- a/simtong-presentation/src/main/kotlin/team/comit/simtong/domain/holiday/WebHolidayAdapter.kt +++ b/simtong-presentation/src/main/kotlin/team/comit/simtong/domain/holiday/WebHolidayAdapter.kt @@ -47,8 +47,8 @@ class WebHolidayAdapter( @GetMapping fun queryIndividualHolidays( - @RequestParam startAt: LocalDate, - @RequestParam endAt: LocalDate + @RequestParam("start_at") startAt: LocalDate, + @RequestParam("end_at") endAt: LocalDate ) : QueryIndividualHolidaysResponse { return queryIndividualHolidayUseCase.execute(startAt, endAt) } diff --git a/simtong-presentation/src/main/kotlin/team/comit/simtong/domain/menu/WebMenuAdapter.kt b/simtong-presentation/src/main/kotlin/team/comit/simtong/domain/menu/WebMenuAdapter.kt index ee69ea4f..d518e126 100644 --- a/simtong-presentation/src/main/kotlin/team/comit/simtong/domain/menu/WebMenuAdapter.kt +++ b/simtong-presentation/src/main/kotlin/team/comit/simtong/domain/menu/WebMenuAdapter.kt @@ -1,18 +1,22 @@ package team.comit.simtong.domain.menu import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.ModelAttribute +import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController -import org.springframework.web.multipart.MultipartFile import team.comit.simtong.domain.file.converter.ExcelFileConverter import team.comit.simtong.domain.menu.dto.MenuResponse +import team.comit.simtong.domain.menu.dto.SaveMenuRequest +import team.comit.simtong.domain.menu.dto.request.SaveMenuWebRequest import team.comit.simtong.domain.menu.usecase.QueryMenuByMonthUseCase import team.comit.simtong.domain.menu.usecase.QueryPublicMenuUseCase import team.comit.simtong.domain.menu.usecase.SaveMenuUseCase import java.time.LocalDate import java.util.UUID +import javax.validation.Valid /** * @@ -33,30 +37,32 @@ class WebMenuAdapter( @GetMapping fun getMenu( - @RequestParam date: LocalDate + @RequestParam("start_at") startAt: LocalDate, + @RequestParam("end_at") endAt: LocalDate ): MenuResponse { - return queryMenuByMonthUseCase.execute(date) + return queryMenuByMonthUseCase.execute(startAt, endAt) } @GetMapping("/public") fun getPublicMenu( - @RequestParam date: LocalDate + @RequestParam("start_at") startAt: LocalDate, + @RequestParam("end_at") endAt: LocalDate ): MenuResponse { - return queryPublicMenuUseCase.execute(date) + return queryPublicMenuUseCase.execute(startAt, endAt) } - @PostMapping + @PostMapping("/{spot-id}") fun saveMenu( - file: MultipartFile, - @RequestParam year: Int, - @RequestParam month: Int, - @RequestParam spotId: UUID, + @PathVariable("spot-id") spotId: UUID, + @Valid @ModelAttribute request: SaveMenuWebRequest ) { saveMenuUseCase.execute( - file = file.let(ExcelFileConverter::transferTo), - year = year, - month = month, - spotId = spotId + SaveMenuRequest( + file = request.file.let(ExcelFileConverter::transferTo), + year = request.year, + month = request.month, + spotId = spotId + ) ) } } \ No newline at end of file diff --git a/simtong-presentation/src/main/kotlin/team/comit/simtong/domain/menu/dto/request/.gitkeep b/simtong-presentation/src/main/kotlin/team/comit/simtong/domain/menu/dto/request/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/simtong-presentation/src/main/kotlin/team/comit/simtong/domain/menu/dto/request/SaveMenuWebRequest.kt b/simtong-presentation/src/main/kotlin/team/comit/simtong/domain/menu/dto/request/SaveMenuWebRequest.kt new file mode 100644 index 00000000..73b925fa --- /dev/null +++ b/simtong-presentation/src/main/kotlin/team/comit/simtong/domain/menu/dto/request/SaveMenuWebRequest.kt @@ -0,0 +1,22 @@ +package team.comit.simtong.domain.menu.dto.request + +import org.springframework.web.multipart.MultipartFile +import javax.validation.constraints.NotNull + +/** + * + * 메뉴를 저장 요청하는 SaveMenuWebRequest + * + * @author Chokyunghyeon + * @date 2022/12/17 + * @version 1.0.0 + **/ +data class SaveMenuWebRequest( + val file: MultipartFile, + + @field:NotNull + val year: Int, + + @field:NotNull + val month: Int +) \ No newline at end of file diff --git a/simtong-presentation/src/main/kotlin/team/comit/simtong/domain/schedule/WebScheduleAdapter.kt b/simtong-presentation/src/main/kotlin/team/comit/simtong/domain/schedule/WebScheduleAdapter.kt index e21e3f9b..02062241 100644 --- a/simtong-presentation/src/main/kotlin/team/comit/simtong/domain/schedule/WebScheduleAdapter.kt +++ b/simtong-presentation/src/main/kotlin/team/comit/simtong/domain/schedule/WebScheduleAdapter.kt @@ -85,13 +85,19 @@ class WebScheduleAdapter( } @GetMapping - fun queryIndividualSpotSchedule(@RequestParam date: LocalDate): QueryIndividualSpotScheduleResponse { - return queryIndividualSpotScheduleUseCase.execute(date) + fun queryIndividualSpotSchedule( + @RequestParam("start_at") startAt: LocalDate, + @RequestParam("end_at") endAt: LocalDate + ): QueryIndividualSpotScheduleResponse { + return queryIndividualSpotScheduleUseCase.execute(startAt, endAt) } @GetMapping("/spots") - fun queryEntireSpotSchedule(@RequestParam date: LocalDate): QueryEntireSpotScheduleResponse { - return queryEntireSpotScheduleUseCase.execute(date) + fun queryEntireSpotSchedule( + @RequestParam("start_at") startAt: LocalDate, + @RequestParam("end_at") endAt: LocalDate + ): QueryEntireSpotScheduleResponse { + return queryEntireSpotScheduleUseCase.execute(startAt, endAt) } @PostMapping("/spots/{spot-id}")