-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
338 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/dto/MenuResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package team.comit.simtong.domain.menu.dto | ||
|
||
import java.time.LocalDate | ||
|
||
/** | ||
* | ||
* 메뉴를 반환하는 MenuResponse | ||
* | ||
* @author kimbeomjin | ||
* @date 2022/09/26 | ||
* @version 1.0.0 | ||
**/ | ||
data class MenuResponse( | ||
val menu: List<MenuElement> | ||
) { | ||
data class MenuElement( | ||
val date: LocalDate, | ||
val meal: String | ||
) | ||
} |
Empty file removed
0
simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/spi/.gitkeep
Empty file.
12 changes: 12 additions & 0 deletions
12
simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/spi/MenuPort.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package team.comit.simtong.domain.menu.spi | ||
|
||
/** | ||
* | ||
* Menu에 관한 요청을 하는 MenuPort | ||
* | ||
* @author kimbeomjin | ||
* @date 2022/09/21 | ||
* @version 1.0.0 | ||
**/ | ||
interface MenuPort : QueryMenuPort { | ||
} |
Empty file removed
0
simtong-application/src/main/kotlin/team/comit/simtong/domain/menu/usecase/.gitkeep
Empty file.
36 changes: 36 additions & 0 deletions
36
...ication/src/main/kotlin/team/comit/simtong/domain/menu/usecase/QueryMenuByMonthUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package team.comit.simtong.domain.menu.usecase | ||
|
||
import team.comit.simtong.domain.menu.dto.MenuResponse | ||
import team.comit.simtong.domain.menu.spi.MenuQueryUserPort | ||
import team.comit.simtong.domain.menu.spi.MenuSecurityPort | ||
import team.comit.simtong.domain.menu.spi.QueryMenuPort | ||
import team.comit.simtong.domain.user.exception.UserNotFoundException | ||
import team.comit.simtong.global.annotation.ReadOnlyUseCase | ||
import java.time.LocalDate | ||
|
||
/** | ||
* | ||
* Menu 조회 기능을 담당하는 QueryMenuByMonthUseCase | ||
* | ||
* @author kimbeomjin | ||
* @date 2022/09/21 | ||
* @version 1.0.0 | ||
**/ | ||
@ReadOnlyUseCase | ||
class QueryMenuByMonthUseCase( | ||
private val queryMenuPort: QueryMenuPort, | ||
private val queryUserPort: MenuQueryUserPort, | ||
private val menuSecurityPort: MenuSecurityPort | ||
) { | ||
|
||
fun execute(today: LocalDate): MenuResponse { | ||
val currentUserId = menuSecurityPort.getCurrentUserId() | ||
val user = queryUserPort.queryUserById(currentUserId) ?: throw UserNotFoundException.EXCEPTION | ||
|
||
val menu = queryMenuPort.queryMenuByMonth(today.year, today.monthValue, user.spotId) | ||
val result = menu.map { MenuResponse.MenuElement(it.date, it.meal) } | ||
|
||
return MenuResponse(result) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...on/src/test/kotlin/team/comit/simtong/domain/menu/usecase/QueryMenuByMonthUseCaseTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package team.comit.simtong.domain.menu.usecase | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
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.MenuQueryUserPort | ||
import team.comit.simtong.domain.menu.spi.MenuSecurityPort | ||
import team.comit.simtong.domain.menu.spi.QueryMenuPort | ||
import team.comit.simtong.domain.user.exception.UserNotFoundException | ||
import team.comit.simtong.domain.user.model.Authority | ||
import team.comit.simtong.domain.user.model.User | ||
import java.time.LocalDate | ||
import java.util.* | ||
|
||
@ExtendWith(SpringExtension::class) | ||
class QueryMenuByMonthUseCaseTests { | ||
|
||
@MockBean | ||
private lateinit var queryMenuPort: QueryMenuPort | ||
|
||
@MockBean | ||
private lateinit var queryUserPort: MenuQueryUserPort | ||
|
||
@MockBean | ||
private lateinit var menuSecurityPort: MenuSecurityPort | ||
|
||
private lateinit var queryMenuByMonthUseCase: QueryMenuByMonthUseCase | ||
|
||
private val currentUserId = UUID.randomUUID() | ||
private val spotId = UUID.randomUUID() | ||
private val now = LocalDate.now() | ||
|
||
private val userStub: User by lazy { | ||
User( | ||
id = currentUserId, | ||
name = "test name", | ||
nickname = "test nickname", | ||
email = "test email", | ||
password = "test encode password", | ||
employeeNumber = 1234567891, | ||
authority = Authority.ROLE_COMMON, | ||
spotId = spotId, | ||
teamId = UUID.randomUUID(), | ||
profileImagePath = "test profileImagePath" | ||
) | ||
} | ||
|
||
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() { | ||
queryMenuByMonthUseCase = QueryMenuByMonthUseCase(queryMenuPort, queryUserPort, menuSecurityPort) | ||
} | ||
|
||
@Test | ||
fun `메뉴 조회 성공`() { | ||
// given | ||
given(menuSecurityPort.getCurrentUserId()) | ||
.willReturn(currentUserId) | ||
|
||
given(queryUserPort.queryUserById(currentUserId)) | ||
.willReturn(userStub) | ||
|
||
given(queryMenuPort.queryMenuByMonth(now.year, now.monthValue, userStub.spotId)) | ||
.willReturn( | ||
listOf(menuStub, menuStub2) | ||
) | ||
|
||
// when | ||
val response = queryMenuByMonthUseCase.execute(now) | ||
|
||
// then | ||
assertThat(response).isNotNull | ||
} | ||
|
||
@Test | ||
fun `유저가 존재하지 않음`() { | ||
// given | ||
given(menuSecurityPort.getCurrentUserId()) | ||
.willReturn(currentUserId) | ||
|
||
given(queryUserPort.queryUserById(currentUserId)) | ||
.willReturn(null) | ||
|
||
// when & then | ||
assertThrows<UserNotFoundException> { | ||
queryMenuByMonthUseCase.execute(now) | ||
} | ||
} | ||
|
||
} |
Empty file.
18 changes: 18 additions & 0 deletions
18
simtong-domain/src/main/kotlin/team/comit/simtong/domain/menu/spi/MenuQueryUserPort.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package team.comit.simtong.domain.menu.spi | ||
|
||
import team.comit.simtong.domain.user.model.User | ||
import java.util.* | ||
|
||
/** | ||
* | ||
* Menu에서 User에 관한 Query를 요청하는 MenuQueryUserPort | ||
* | ||
* @author kimbeomjin | ||
* @date 2022/09/26 | ||
* @version 1.0.0 | ||
**/ | ||
interface MenuQueryUserPort { | ||
|
||
fun queryUserById(userId: UUID): User? | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
simtong-domain/src/main/kotlin/team/comit/simtong/domain/menu/spi/MenuSecurityPort.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package team.comit.simtong.domain.menu.spi | ||
|
||
import java.util.* | ||
|
||
/** | ||
* | ||
* Menu에서 보안 처리를 요청하는 MenuSecurityPort | ||
* | ||
* @author kimbeomjin | ||
* @date 2022/09/26 | ||
* @version 1.0.0 | ||
**/ | ||
interface MenuSecurityPort { | ||
|
||
fun getCurrentUserId(): UUID | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
simtong-domain/src/main/kotlin/team/comit/simtong/domain/menu/spi/QueryMenuPort.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package team.comit.simtong.domain.menu.spi | ||
|
||
import team.comit.simtong.domain.menu.model.Menu | ||
import java.util.* | ||
|
||
/** | ||
* | ||
* Menu에 관한 Query룰 요청하는 QueryMenuPort | ||
* | ||
* @author kimbeomjin | ||
* @date 2022/09/21 | ||
* @version 1.0.0 | ||
**/ | ||
interface QueryMenuPort { | ||
|
||
fun queryMenuByMonth(year: Int, month: Int, spotId: UUID): List<Menu> | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
simtong-infrastructure/src/main/kotlin/team/comit/simtong/global/config/QuerydslConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package team.comit.simtong.global.config | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import javax.persistence.EntityManager | ||
|
||
/** | ||
* | ||
* JPAQueryFactory를 Bean 등록하는 QuerydslConfig | ||
* | ||
* @author kimbeomjin | ||
* @date 2022/09/26 | ||
* @version 1.0.0 | ||
**/ | ||
@Configuration | ||
class QuerydslConfig( | ||
private val entityManager: EntityManager | ||
) { | ||
|
||
@Bean | ||
protected fun queryFactory(): JPAQueryFactory = JPAQueryFactory(entityManager) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.