Skip to content

Commit

Permalink
merge: (#84) 로그인 안된 상태에서 메뉴 조회 (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
softpeanut authored Oct 11, 2022
2 parents f07a5d8 + fbdd449 commit 59b8b3c
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class QueryMenuByMonthUseCase(
val currentUserId = menuSecurityPort.getCurrentUserId()
val user = queryUserPort.queryUserById(currentUserId) ?: throw UserNotFoundException.EXCEPTION

val menu = queryMenuPort.queryMenuByMonth(today.year, today.monthValue, user.spotId)
val menu = queryMenuPort.queryMenuBySpotId(today.year, today.monthValue, user.spotId)
val result = menu.map { MenuResponse.MenuElement(it.date, it.meal) }

return MenuResponse(result)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package team.comit.simtong.domain.menu.usecase

import team.comit.simtong.domain.menu.dto.MenuResponse
import team.comit.simtong.domain.menu.spi.QueryMenuPort
import team.comit.simtong.global.annotation.ReadOnlyUseCase
import java.time.LocalDate

/**
*
* 공개된 Menu를 조회하는 QueryPublicMenuUseCase
*
* @author kimbeomjin
* @date 2022/10/11
* @version 1.0.0
**/
@ReadOnlyUseCase
class QueryPublicMenuUseCase(
private val queryMenuPort: QueryMenuPort,
) {

fun execute(today: LocalDate): MenuResponse {
val menu = queryMenuPort.queryMenuBySpotName(today.year, today.monthValue, HEAD_SHOP)
val result = menu.map { MenuResponse.MenuElement(it.date, it.meal) }

return MenuResponse(result)
}

companion object {
private const val HEAD_SHOP = "은행동 본점"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class QueryMenuByMonthUseCaseTests {
given(queryUserPort.queryUserById(currentUserId))
.willReturn(userStub)

given(queryMenuPort.queryMenuByMonth(now.year, now.monthValue, userStub.spotId))
given(queryMenuPort.queryMenuBySpotId(now.year, now.monthValue, userStub.spotId))
.willReturn(
listOf(menuStub, menuStub2)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package team.comit.simtong.domain.menu.usecase

import org.assertj.core.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.BDDMockito.given
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.test.context.junit.jupiter.SpringExtension
import team.comit.simtong.domain.menu.model.Menu
import team.comit.simtong.domain.menu.spi.QueryMenuPort
import java.time.LocalDate
import java.util.*

@ExtendWith(SpringExtension::class)
class QueryPublicMenuUseCaseTests {

@MockBean
private lateinit var queryMenuPort: QueryMenuPort

private lateinit var queryPublicMenuUseCase: QueryPublicMenuUseCase

private val menuStub: Menu by lazy {
Menu(
date = LocalDate.of(2022, 9, 1),
meal = "오늘 아침은 아침밥",
spotId = UUID.randomUUID()
)
}

private val menuStub2: Menu by lazy {
Menu(
date = LocalDate.of(2022, 9, 30),
meal = "오늘 점심은 점심밥",
spotId = UUID.randomUUID()
)
}

@BeforeEach
fun setUp() {
queryPublicMenuUseCase = QueryPublicMenuUseCase(queryMenuPort)
}

@Test
fun `메뉴 조회 성공`() {
// given
val now = LocalDate.now()
given(queryMenuPort.queryMenuBySpotName(now.year, now.monthValue, "은행동 본점"))
.willReturn(
listOf(menuStub, menuStub2)
)

// when
val response = queryPublicMenuUseCase.execute(now)

// then
Assertions.assertThat(response).isNotNull
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import java.util.*
**/
interface QueryMenuPort {

fun queryMenuByMonth(year: Int, month: Int, spotId: UUID): List<Menu>
fun queryMenuBySpotId(year: Int, month: Int, spotId: UUID): List<Menu>

fun queryMenuBySpotName(year: Int, month: Int, spotName: String): List<Menu>

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class SecurityConfig(
.antMatchers(HttpMethod.POST, "/emails/code").permitAll()

// menu
.antMatchers(HttpMethod.GET, "/menu").permitAll()
.antMatchers(HttpMethod.GET, "/menu/public").permitAll()

// files
.antMatchers(HttpMethod.POST, "/files").permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MenuPersistenceAdapter(
private val queryFactory: JPAQueryFactory
) : MenuPort {

override fun queryMenuByMonth(year: Int, month: Int, spotId: UUID): List<Menu> {
override fun queryMenuBySpotId(year: Int, month: Int, spotId: UUID): List<Menu> {
return queryFactory
.selectFrom(menuJpaEntity)
.leftJoin(menuJpaEntity.spot, spotJpaEntity)
Expand All @@ -38,6 +38,21 @@ class MenuPersistenceAdapter(
}
}

override fun queryMenuBySpotName(year: Int, month: Int, spotName: String): List<Menu> {
return queryFactory
.selectFrom(menuJpaEntity)
.leftJoin(menuJpaEntity.spot, spotJpaEntity)
.where(
yearEq(year),
monthEq(month),
spotJpaEntity.name.eq(spotName)
)
.fetch()
.map {
menuMapper.toDomain(it)!!
}
}

private fun yearEq(year: Int) = menuJpaEntity.date.year().eq(year)

private fun monthEq(month: Int) = menuJpaEntity.date.month().eq(month)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package team.comit.simtong.menu

import org.springframework.format.annotation.DateTimeFormat
import org.springframework.format.annotation.DateTimeFormat.ISO
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
Expand All @@ -24,7 +26,14 @@ class WebMenuAdapter(

@GetMapping
fun getMenu(
@RequestParam date: LocalDate
@RequestParam @DateTimeFormat(iso = ISO.DATE) date: LocalDate
): MenuResponse {
return queryMenuByMonthUseCase.execute(date)
}

@GetMapping("/public")
fun getPublicMenu(
@RequestParam @DateTimeFormat(iso = ISO.DATE) date: LocalDate
): MenuResponse {
return queryMenuByMonthUseCase.execute(date)
}
Expand Down

0 comments on commit 59b8b3c

Please sign in to comment.