-
Notifications
You must be signed in to change notification settings - Fork 0
[개발자 비상근무] 리나 미션 제출합니다. #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
1jeongg
wants to merge
6
commits into
leena-main
Choose a base branch
from
leena/oncall
base: leena-main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dbea53a
docs: add feature requirements and how-to-solve
1jeongg 5c94a11
feat: getInput (month, week, workers)
1jeongg 50377c6
test: input's validation, converter test
1jeongg ae17551
refactor: make dto's week enum class
1jeongg dd90f0a
feat: manage work order and print result
1jeongg 4be7b1b
test: for work order and week test
1jeongg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,21 @@ | ||
|
|
||
| ## 기능 요구사항 | ||
| - [x] 입력 | ||
| - 비상 근무를 배정할 월과 시작 요일 | ||
| `"${month},${day}"` 형식여야 함 | ||
| month는 1~12, day는 월~일 | ||
| - 평일 비상 근무 순번대로 사원 닉네임 | ||
| `"${people1},${people2},${people3}"` 형식여야 함 | ||
| 중복된 이름 있으면 안됨 | ||
| 최대 5자 | ||
| 인원수: 5명~35명 | ||
| - 휴일 비상 근무 순번대로 사원 닉네임 | ||
| `"${people1},${people2},${people3}"` 형식여야 함 | ||
| 중복된 이름 있으면 안됨 | ||
| 평일 비상 근무 순번에 있는 사람들이 다 들어있어야함 | ||
| - [x] 비상 근무 순서 배정 | ||
| - 평일, 휴일 순번에 따라 인원을 배정한다. | ||
| - 순번상 특정 근무자가 연속 2일 근무하게 되는 상황에는, 다음 근무자와 순서를 바꿔 편성한다. | ||
| - [x] 출력 | ||
| - `"5월 1일 월 준팍"` 형식으로 출력 | ||
| - 평일이면서 법정공휴일의 경우에만 요일 뒤에 (휴일) 표기를 해야 한다. |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package oncall | ||
|
|
||
| fun main() { | ||
| TODO("프로그램 구현") | ||
| val oncallController = OncallController() | ||
| oncallController.execute() | ||
| } |
This file contains hidden or 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 oncall | ||
|
|
||
| import oncall.util.InputManager | ||
| import oncall.util.OutputManager | ||
|
|
||
| class OncallController( | ||
| private val inputManager: InputManager = InputManager(), | ||
| private val outputManager: OutputManager = OutputManager(), | ||
| ){ | ||
|
|
||
| fun execute() { | ||
| val oncallInformationDTO = inputManager.getInput() | ||
|
|
||
| val workOrderService = WorkOrderService(oncallInformationDTO) | ||
| val workerList = workOrderService.getWorkerList() | ||
| outputManager.printWorkerOrder(oncallInformationDTO, workerList) | ||
| } | ||
| } |
This file contains hidden or 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,32 @@ | ||
| package oncall | ||
|
|
||
| import oncall.data.Holiday | ||
| import oncall.data.OncallInformationDTO | ||
| import oncall.data.Week.Companion.isHoliday | ||
| import oncall.data.getEndDateOfMonth | ||
|
|
||
| class WorkOrderService( | ||
| private val oncallInformationDTO: OncallInformationDTO | ||
| ) { | ||
| private val month = oncallInformationDTO.month | ||
| private val endDate = getEndDateOfMonth(month) | ||
|
|
||
| private val size = oncallInformationDTO.holidayWorkerList.size | ||
| private val holidayWorker = MutableList(endDate) { i -> oncallInformationDTO.holidayWorkerList[i%size] } | ||
| private val weekdayWorker = MutableList(endDate) { i -> oncallInformationDTO.weekdayWorkerList[i%size] } | ||
|
|
||
| fun getWorkerList(): List<String> { | ||
| val workerList = mutableListOf<String>() | ||
| for (date in 1..endDate) { | ||
| val workers = getWorkerList(date) | ||
| val workerIndex = workers.indexOfFirst { workerList.isEmpty() || it != workerList.last() } | ||
| workerList.add(workers[workerIndex]) | ||
| workers.removeAt(workerIndex) | ||
| } | ||
| return workerList.toList() | ||
| } | ||
|
|
||
| private fun getWorkerList(date: Int) = if (isHoliday(date)) holidayWorker else weekdayWorker | ||
|
|
||
| private fun isHoliday(date: Int) = Holiday.isHoliday(month, date) || oncallInformationDTO.startWeek.isHoliday(date) | ||
| } |
This file contains hidden or 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,61 @@ | ||
| package oncall.data | ||
|
|
||
| enum class Week( | ||
| val korean: String | ||
| ) { | ||
| MONDAY("월"), | ||
| TUESDAY("화"), | ||
| WEDNESDAY("수"), | ||
| THURSDAY("목"), | ||
| FRIDAY("금"), | ||
| SATURDAY("토"), | ||
| SUNDAY("일"), | ||
| ; | ||
|
|
||
| companion object { | ||
| fun get(value: String): Week? { | ||
| return entries.firstOrNull { it.korean == value } | ||
| } | ||
| fun Week.isHoliday(date: Int): Boolean { | ||
| val holidayOrdinal = (this.ordinal + date - 1)%7 | ||
| return holidayOrdinal >= SATURDAY.ordinal | ||
| } | ||
| fun Week.getWeek(month: Int, date: Int): String { | ||
| val result = entries.first { it.ordinal == (this.ordinal + date - 1)%7 }.korean | ||
| val isHoliday = if (Holiday.isHoliday(month, date)) "(휴일)" else "" | ||
| return result + isHoliday | ||
| } | ||
| } | ||
| } | ||
|
|
||
| enum class Holiday( | ||
| val month: Int, | ||
| val date: Int, | ||
| val korean: String | ||
| ) { | ||
| NEW_YEARS_DAY(1, 1, "신정"), | ||
| INDEPENDENCE_MOVEMENT_DAY(3, 1, "삼일절"), | ||
| CHILDREN_S_DAY(5, 5, "어린이날"), | ||
| MEMORIAL_DAY(6, 6, "현충일"), | ||
| LIBERATION_DAY(8, 15, "광복절"), | ||
| NATIONAL_FOUNDATION_DAY(10, 3, "개천절"), | ||
| HANGUL_DAY(10, 9, "한글날"), | ||
| CHRISTMAS(12, 25, "성탄절"), | ||
| ; | ||
|
|
||
| companion object { | ||
| fun isHoliday(month: Int, date: Int): Boolean { | ||
| return entries.any { holiday -> | ||
| holiday.month == month && holiday.date == date | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun getEndDateOfMonth(month: Int): Int { | ||
| if (month !in 1..12) { | ||
| throw IllegalArgumentException() | ||
| } | ||
| val daysOfMonth = listOf(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) | ||
| return daysOfMonth[month-1] | ||
| } | ||
|
Comment on lines
+55
to
+61
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
8 changes: 8 additions & 0 deletions
8
kotlin-oncall/src/main/kotlin/oncall/data/OncallInformationDTO.kt
This file contains hidden or 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,8 @@ | ||
| package oncall.data | ||
|
|
||
| data class OncallInformationDTO( | ||
| val month: Int, | ||
| val startWeek: Week, | ||
| val weekdayWorkerList: List<String>, | ||
| val holidayWorkerList: List<String> | ||
| ) |
34 changes: 34 additions & 0 deletions
34
kotlin-oncall/src/main/kotlin/oncall/util/DataConverter.kt
This file contains hidden or 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,34 @@ | ||
| package oncall.util | ||
|
|
||
| import oncall.data.Week | ||
|
|
||
|
|
||
| class DataConverter( | ||
| private val validationChecker: ValidationChecker = ValidationChecker() | ||
| ) { | ||
|
|
||
| fun convertDate(input: String): Pair<Int, Week> { | ||
| val split = input.split(',') | ||
| val month = split[0].toIntWithoutNull() | ||
| val week = Week.get(split[1]) | ||
|
|
||
| validationChecker.checkDate(split.size, month, week) | ||
| return Pair(month, week!!) | ||
| } | ||
|
|
||
| fun convertWeekdayWorker(input: String): List<String> { | ||
| val weekdayWorker = input.split(',') | ||
| validationChecker.checkWeekdayWorker(weekdayWorker) | ||
| return weekdayWorker | ||
| } | ||
|
|
||
| fun convertHolidayWorker(input: String, weekdayWorker: List<String>): List<String> { | ||
| val holidayWorker = input.split(',') | ||
| validationChecker.checkHolidayWorker(weekdayWorker, holidayWorker) | ||
| return holidayWorker | ||
| } | ||
|
|
||
| private fun String.toIntWithoutNull(): Int { | ||
| return this.toIntOrNull() ?: throw IllegalArgumentException() | ||
| } | ||
| } |
This file contains hidden or 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,53 @@ | ||
| package oncall.util | ||
|
|
||
| import camp.nextstep.edu.missionutils.Console | ||
| import oncall.data.OncallInformationDTO | ||
| import oncall.data.Week | ||
|
|
||
| class InputManager( | ||
| private val dataConverter: DataConverter = DataConverter(), | ||
| private val outputManager: OutputManager = OutputManager() | ||
| ) { | ||
|
|
||
| fun getInput(): OncallInformationDTO { | ||
| val (month, startWeek) = getDate() | ||
| val weekdayWorker = getWeekdayWorker() | ||
| val holidayWorker = getHolidayWorker(weekdayWorker) | ||
|
|
||
| return OncallInformationDTO(month, startWeek, weekdayWorker, holidayWorker) | ||
| } | ||
|
|
||
| private fun getDate(): Pair<Int, Week> { | ||
| return getUserInput { | ||
| outputManager.printGetDateMessage() | ||
| val input = Console.readLine() ?: "" | ||
| dataConverter.convertDate(input) | ||
| } | ||
| } | ||
|
|
||
| private fun getWeekdayWorker(): List<String> { | ||
| return getUserInput { | ||
| outputManager.printGetWeekdayWorkerMessage() | ||
| val input = Console.readLine() ?: "" | ||
| dataConverter.convertWeekdayWorker(input) | ||
| } | ||
| } | ||
|
|
||
| private fun getHolidayWorker(weekdayWorker: List<String>): List<String> { | ||
| return getUserInput { | ||
| outputManager.printGetHolidayWorkerMessage() | ||
| val input = Console.readLine() ?: "" | ||
| dataConverter.convertHolidayWorker(input, weekdayWorker) | ||
| } | ||
| } | ||
|
|
||
| private fun <T> getUserInput(inputFunction: () -> T): T { | ||
| while (true) { | ||
| try { | ||
| return inputFunction() | ||
| } catch (_: IllegalArgumentException) { | ||
| outputManager.printExceptionMessage() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍👍 |
||
| } | ||
| } | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
kotlin-oncall/src/main/kotlin/oncall/util/OutputManager.kt
This file contains hidden or 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,29 @@ | ||
| package oncall.util | ||
|
|
||
| import oncall.data.OncallInformationDTO | ||
| import oncall.data.Week.Companion.getWeek | ||
| import oncall.data.getEndDateOfMonth | ||
|
|
||
| class OutputManager { | ||
|
|
||
| fun printExceptionMessage() = println("$ERROR_PREFIX 유효하지 않은 입력 값입니다. 다시 입력해 주세요.") | ||
|
|
||
| fun printGetDateMessage() = print("비상 근무를 배정할 월과 시작 요일을 입력하세요> ") | ||
|
|
||
| fun printGetWeekdayWorkerMessage() = print("평일 비상 근무 순번대로 사원 닉네임을 입력하세요> ") | ||
|
|
||
| fun printGetHolidayWorkerMessage() = print("휴일 비상 근무 순번대로 사원 닉네임을 입력하세요> ") | ||
|
|
||
| fun printWorkerOrder(oncallInformationDTO: OncallInformationDTO, workerList: List<String>) { | ||
| val month = oncallInformationDTO.month | ||
| val endDate = getEndDateOfMonth(month) | ||
| for (date in 1..endDate) { | ||
| val week = oncallInformationDTO.startWeek.getWeek(month, date) | ||
| print("${month}월 ${date}일 $week ${workerList[date-1]}\n") | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| private const val ERROR_PREFIX = "[ERROR]" | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
kotlin-oncall/src/main/kotlin/oncall/util/ValidationChecker.kt
This file contains hidden or 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,33 @@ | ||
| package oncall.util | ||
|
|
||
| import oncall.data.Week | ||
|
|
||
| class ValidationChecker { | ||
|
|
||
| fun checkDate(size: Int, month: Int, week: Week?) { | ||
| require(size == 2) | ||
| require(month in MONTH_RANGE) | ||
| require(week != null) | ||
| } | ||
|
|
||
| fun checkWeekdayWorker(worker: List<String>) { | ||
| checkWorker(worker) | ||
| } | ||
|
|
||
| fun checkHolidayWorker(weekdayWorker: List<String>, holidayWorker: List<String>) { | ||
| checkWorker(holidayWorker) | ||
| require(weekdayWorker.sorted() == holidayWorker.sorted()) | ||
| } | ||
|
|
||
| private fun checkWorker(worker: List<String>) { | ||
| require(worker.distinct().size == worker.size) | ||
| require(worker.all { it.length in NICKNAME_RANGE }) | ||
| require(worker.size in WORKER_RANGE) | ||
| } | ||
|
|
||
| companion object { | ||
| private val MONTH_RANGE = 1..12 | ||
| private val NICKNAME_RANGE = 1..5 | ||
| private val WORKER_RANGE = 5..35 | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
kotlin-oncall/src/test/kotlin/oncall/WorkOrderServiceTest.kt
This file contains hidden or 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,24 @@ | ||
| package oncall | ||
|
|
||
| import oncall.data.OncallInformationDTO | ||
| import oncall.data.Week | ||
| import org.junit.jupiter.api.Assertions.assertEquals | ||
| import org.junit.jupiter.api.Test | ||
|
|
||
| class WorkOrderServiceTest { | ||
|
|
||
| @Test | ||
| fun `근무자 순서 정하기` () { | ||
| val weekdayWorker = listOf("준팍","도밥","고니","수아","루루","글로","솔로스타","우코","슬링키","참새","도리") | ||
| val holidayWorker = listOf("수아","루루","글로","솔로스타","우코","슬링키","참새","도리","준팍","도밥","고니") | ||
|
|
||
| val oncallInformationDTO = OncallInformationDTO(5, Week.MONDAY, weekdayWorker, holidayWorker) | ||
| val result = WorkOrderService(oncallInformationDTO).getWorkerList() | ||
| val expected = listOf("준팍", "도밥", "고니", "수아", "루루", "수아", "글로", "루루", "글로") | ||
|
|
||
| for (index in expected.indices) { | ||
| assertEquals(expected[index], result[index]) | ||
| } | ||
| } | ||
|
|
||
| } |
45 changes: 45 additions & 0 deletions
45
kotlin-oncall/src/test/kotlin/oncall/util/DataConverterTest.kt
This file contains hidden or 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,45 @@ | ||
| package oncall.util | ||
|
|
||
| import org.junit.jupiter.api.Assertions.assertEquals | ||
| import org.junit.jupiter.api.Test | ||
| import org.junit.jupiter.api.assertThrows | ||
|
|
||
| class DataConverterTest { | ||
|
|
||
| private val dataConverter = DataConverter() | ||
|
|
||
| @Test | ||
| fun `배정 월, 시작요일 입력 성공`() { | ||
| val input = "1,월" | ||
| val (month, week) = dataConverter.convertDate(input) | ||
|
|
||
| assertEquals(1, month) | ||
| assertEquals("월", week) | ||
| } | ||
|
|
||
| @Test | ||
| fun `배정 월, 시작요일 입력 실패`() { | ||
| assertThrows<IllegalArgumentException> { | ||
| val input = "asdf,월" | ||
| val (month, week) = dataConverter.convertDate(input) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun `평일 근무자 입력 성공`() { | ||
| val input = "a,b,c,d,e" | ||
| val worker = dataConverter.convertWeekdayWorker(input) | ||
|
|
||
| assertEquals(worker, listOf("a", "b", "c", "d", "e")) | ||
| } | ||
|
|
||
| @Test | ||
| fun `휴일 근무자 입력 성공`() { | ||
| val weekdayWorker = listOf("가","나","다","라","마","바") | ||
| val holidayWorker = "바,마,라,다,나,가" | ||
| val worker = dataConverter.convertHolidayWorker(holidayWorker, weekdayWorker) | ||
|
|
||
| assertEquals(worker, listOf("바", "마", "라", "다", "나", "가")) | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
korean좋네요 👍