-
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.
Merge branch 'main' into feature/249-check-holiday-creation-period
- Loading branch information
Showing
11 changed files
with
480 additions
and
7 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...ion/src/main/kotlin/team/comit/simtong/domain/holiday/dto/QueryEmployeeHolidayResponse.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,48 @@ | ||
package team.comit.simtong.domain.holiday.dto | ||
|
||
import team.comit.simtong.domain.holiday.model.HolidayType | ||
import java.time.LocalDate | ||
import java.util.UUID | ||
|
||
/** | ||
* | ||
* 지점 직원의 휴무일을 반환하는 QueryEmployeeHolidayResponse | ||
* | ||
* @author kimbeomjin | ||
* @date 2022/12/22 | ||
* @version 1.0.0 | ||
**/ | ||
data class QueryEmployeeHolidayResponse( | ||
val holidays: List<Holiday> | ||
) { | ||
|
||
/** | ||
* | ||
* 지점 직원의 휴무일 정보를 반환하는 Holiday | ||
* | ||
* @author kimbeomjin | ||
* @date 2022/12/22 | ||
* @version 1.0.0 | ||
**/ | ||
data class Holiday( | ||
val date: LocalDate, | ||
val type: HolidayType, | ||
val user: Employee | ||
) { | ||
|
||
/** | ||
* | ||
* 지점 직원 정보를 반환하는 Employee | ||
* | ||
* @author kimbeomjin | ||
* @date 2022/12/22 | ||
* @version 1.0.0 | ||
**/ | ||
data class Employee( | ||
val id: UUID, | ||
val name: String, | ||
val team: String, | ||
val spot: String | ||
) | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
.../src/main/kotlin/team/comit/simtong/domain/holiday/usecase/QueryEmployeeHolidayUseCase.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,74 @@ | ||
package team.comit.simtong.domain.holiday.usecase | ||
|
||
import team.comit.simtong.domain.holiday.dto.QueryEmployeeHolidayResponse | ||
import team.comit.simtong.domain.holiday.model.HolidayQueryType | ||
import team.comit.simtong.domain.holiday.model.HolidayType | ||
import team.comit.simtong.domain.holiday.spi.HolidayQueryUserPort | ||
import team.comit.simtong.domain.holiday.spi.HolidaySecurityPort | ||
import team.comit.simtong.domain.holiday.spi.QueryHolidayPort | ||
import team.comit.simtong.domain.user.exception.UserExceptions | ||
import team.comit.simtong.global.annotation.ReadOnlyUseCase | ||
import java.util.UUID | ||
|
||
/** | ||
* | ||
* 해당하는 지점 직원의 휴무일을 확인하는 QueryEmployeeHolidayUseCase | ||
* | ||
* ALL / HOLIDAY / ANNUAL 로 구분해서 필터링 | ||
* teamId를 이용해 파트별로 구분 가능 (null이면 전체) | ||
* HolidayStatus가 WRITTEN 상태인 것만 조회 | ||
* | ||
* @author kimbeomjin | ||
* @date 2022/12/22 | ||
* @version 1.0.0 | ||
**/ | ||
@ReadOnlyUseCase | ||
class QueryEmployeeHolidayUseCase( | ||
private val queryHolidayPort: QueryHolidayPort, | ||
private val securityPort: HolidaySecurityPort, | ||
private val queryUserPort: HolidayQueryUserPort | ||
) { | ||
|
||
fun execute(year: Int, month: Int, typeName: String, teamId: UUID?): QueryEmployeeHolidayResponse { | ||
val currentUserId = securityPort.getCurrentUserId() | ||
val user = queryUserPort.queryUserById(currentUserId) ?: throw UserExceptions.NotFound() | ||
|
||
val holidays = when (HolidayQueryType.valueOf(typeName)) { | ||
HolidayQueryType.HOLIDAY -> queryHolidayPort.queryHolidaysByYearAndMonthAndTeamId( | ||
year = year, month = month, | ||
type = HolidayType.HOLIDAY, | ||
spotId = user.spotId, | ||
teamId = teamId | ||
) | ||
|
||
HolidayQueryType.ANNUAL -> queryHolidayPort.queryHolidaysByYearAndMonthAndTeamId( | ||
year = year, month = month, | ||
type = HolidayType.ANNUAL, | ||
spotId = user.spotId, | ||
teamId = teamId | ||
) | ||
|
||
HolidayQueryType.ALL -> queryHolidayPort.queryHolidaysByYearAndMonthAndTeamId( | ||
year = year, month = month, | ||
type = null, | ||
spotId = user.spotId, | ||
teamId = teamId | ||
) | ||
} | ||
|
||
val response = holidays.map { | ||
QueryEmployeeHolidayResponse.Holiday( | ||
date = it.date, | ||
type = it.type, | ||
user = QueryEmployeeHolidayResponse.Holiday.Employee( | ||
id = it.userId, | ||
name = it.userName, | ||
team = it.teamName, | ||
spot = it.spotName | ||
) | ||
) | ||
} | ||
|
||
return QueryEmployeeHolidayResponse(response) | ||
} | ||
} |
164 changes: 164 additions & 0 deletions
164
...test/kotlin/team/comit/simtong/domain/holiday/usecase/QueryEmployeeHolidayUseCaseTests.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,164 @@ | ||
package team.comit.simtong.domain.holiday.usecase | ||
|
||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
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.holiday.model.HolidayType | ||
import team.comit.simtong.domain.holiday.spi.HolidayQueryUserPort | ||
import team.comit.simtong.domain.holiday.spi.HolidaySecurityPort | ||
import team.comit.simtong.domain.holiday.spi.QueryHolidayPort | ||
import team.comit.simtong.domain.holiday.spi.vo.EmployeeHoliday | ||
import team.comit.simtong.domain.user.exception.UserExceptions | ||
import team.comit.simtong.domain.user.model.Authority | ||
import team.comit.simtong.domain.user.model.User | ||
import team.comit.simtong.global.annotation.SimtongTest | ||
import java.time.LocalDate | ||
import java.util.UUID | ||
|
||
@SimtongTest | ||
class QueryEmployeeHolidayUseCaseTests { | ||
|
||
@MockBean | ||
private lateinit var queryHolidayPort: QueryHolidayPort | ||
|
||
@MockBean | ||
private lateinit var securityPort: HolidaySecurityPort | ||
|
||
@MockBean | ||
private lateinit var queryUserPort: HolidayQueryUserPort | ||
|
||
private lateinit var queryEmployeeHolidayUseCase: QueryEmployeeHolidayUseCase | ||
|
||
private val userId = UUID.randomUUID() | ||
private val spotId = UUID.randomUUID() | ||
private val year = 2022 | ||
private val month = 12 | ||
private val teamId = UUID.randomUUID() | ||
|
||
private val userStub by lazy { | ||
User( | ||
id = userId, | ||
nickname = "test nickname", | ||
name = "test name", | ||
email = "[email protected]", | ||
password = "test password", | ||
employeeNumber = 1234567890, | ||
authority = Authority.ROLE_COMMON, | ||
spotId = spotId, | ||
teamId = UUID.randomUUID(), | ||
profileImagePath = User.DEFAULT_IMAGE | ||
) | ||
} | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
queryEmployeeHolidayUseCase = QueryEmployeeHolidayUseCase( | ||
queryHolidayPort, securityPort, queryUserPort | ||
) | ||
} | ||
|
||
@Test | ||
fun `지점 직원 휴무일 조회 성공`() { | ||
// given | ||
given(securityPort.getCurrentUserId()) | ||
.willReturn(userId) | ||
|
||
given(queryUserPort.queryUserById(userId)) | ||
.willReturn(userStub) | ||
|
||
given(queryHolidayPort.queryHolidaysByYearAndMonthAndTeamId(year, month, HolidayType.HOLIDAY, spotId, teamId)) | ||
.willReturn( | ||
listOf( | ||
EmployeeHoliday( | ||
date = LocalDate.of(year, month, 1), | ||
userId = userId, | ||
type = HolidayType.HOLIDAY, | ||
userName = "test name", | ||
teamName = "test team", | ||
spotName = "test spot", | ||
) | ||
) | ||
) | ||
|
||
// when & then | ||
assertDoesNotThrow { | ||
queryEmployeeHolidayUseCase.execute(year, month, "HOLIDAY", teamId) | ||
} | ||
} | ||
|
||
@Test | ||
fun `지점 직원 연차 조회 성공`() { | ||
// given | ||
given(securityPort.getCurrentUserId()) | ||
.willReturn(userId) | ||
|
||
given(queryUserPort.queryUserById(userId)) | ||
.willReturn(userStub) | ||
|
||
given(queryHolidayPort.queryHolidaysByYearAndMonthAndTeamId(year, month, HolidayType.ANNUAL, spotId, teamId)) | ||
.willReturn( | ||
listOf( | ||
EmployeeHoliday( | ||
date = LocalDate.of(year, month, 1), | ||
userId = userId, | ||
type = HolidayType.ANNUAL, | ||
userName = "test name", | ||
teamName = "test team", | ||
spotName = "test spot", | ||
) | ||
) | ||
) | ||
|
||
// when & then | ||
assertDoesNotThrow { | ||
queryEmployeeHolidayUseCase.execute(year, month, "ANNUAL", teamId) | ||
} | ||
} | ||
|
||
@Test | ||
fun `지점 직원 휴무일 & 연차 조회 성공`() { | ||
// given | ||
given(securityPort.getCurrentUserId()) | ||
.willReturn(userId) | ||
|
||
given(queryUserPort.queryUserById(userId)) | ||
.willReturn(userStub) | ||
|
||
given(queryHolidayPort.queryHolidaysByYearAndMonthAndTeamId(year, month, null, spotId, teamId)) | ||
.willReturn( | ||
listOf( | ||
EmployeeHoliday( | ||
date = LocalDate.of(year, month, 1), | ||
userId = userId, | ||
type = HolidayType.ANNUAL, | ||
userName = "test name", | ||
teamName = "test team", | ||
spotName = "test spot", | ||
) | ||
) | ||
) | ||
|
||
// when & then | ||
assertDoesNotThrow { | ||
queryEmployeeHolidayUseCase.execute(year, month, "ALL", teamId) | ||
} | ||
} | ||
|
||
@Test | ||
fun `유저를 찾을 수 없음`() { | ||
// given | ||
given(securityPort.getCurrentUserId()) | ||
.willReturn(userId) | ||
|
||
given(queryUserPort.queryUserById(userId)) | ||
.willReturn(null) | ||
|
||
// when & then | ||
assertThrows<UserExceptions.NotFound> { | ||
queryEmployeeHolidayUseCase.execute(2022, 12, "HOLIDAY", null) | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
simtong-domain/src/main/kotlin/team/comit/simtong/domain/holiday/model/HolidayQueryType.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,28 @@ | ||
package team.comit.simtong.domain.holiday.model | ||
|
||
/** | ||
* | ||
* 연차 및 휴무일을 필터링하기 위한 HolidayQueryType | ||
* | ||
* @author kimbeomjin | ||
* @date 2022/12/22 | ||
* @version 1.0.0 | ||
**/ | ||
enum class HolidayQueryType { | ||
|
||
/** | ||
* 휴무일과 연차 | ||
*/ | ||
ALL, | ||
|
||
/** | ||
* 휴무일 | ||
*/ | ||
HOLIDAY, | ||
|
||
/** | ||
* 연차 | ||
*/ | ||
ANNUAL | ||
|
||
} |
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
27 changes: 27 additions & 0 deletions
27
simtong-domain/src/main/kotlin/team/comit/simtong/domain/holiday/spi/vo/EmployeeHoliday.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,27 @@ | ||
package team.comit.simtong.domain.holiday.spi.vo | ||
|
||
import team.comit.simtong.domain.holiday.model.HolidayType | ||
import java.time.LocalDate | ||
import java.util.UUID | ||
|
||
/** | ||
* | ||
* Holiday와 User 정보를 가져오는 EmployeeHoliday | ||
* | ||
* @author kimbeomjin | ||
* @date 2022/12/22 | ||
* @version 1.0.0 | ||
**/ | ||
open class EmployeeHoliday( | ||
val date: LocalDate, | ||
|
||
val type: HolidayType, | ||
|
||
val userId: UUID, | ||
|
||
val userName: String, | ||
|
||
val teamName: String, | ||
|
||
val spotName: String | ||
) |
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.