-
Notifications
You must be signed in to change notification settings - Fork 0
[✨feat] InternshipWorkingPeriod 구현 #57
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
base: feat/#54
Are you sure you want to change the base?
Conversation
- 근무 기간이 1개월 미만인 경우를 처리하는 INVALID_WORKING_PERIOD 코드 추가
- 근무 기간을 월 단위로 표현하는 값 객체 `InternshipWorkingPeriod` 구현 - 1개월 미만일 경우 예외 발생 - 한글 기간 문자열 변환 메서드(toKoreanPeriod) 제공 - equals, hashCode, toString 오버라이드
- from 메서드 테스트: 유효한 개월 수 입력 시 객체 생성 확인 - 잘못된 개월 수 입력(0 이하) 시 예외 발생 여부 검증 - toKoreanPeriod 메서드 테스트: "N개월" 형식의 문자열 반환 검증
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.
Pull Request Overview
This PR introduces a value object for internship working periods, adds validation and formatting logic, and defines a new error code for invalid inputs.
- Implement
InternshipWorkingPeriod
VO with positive-month validation and Korean-format output. - Define
InternshipErrorCode.INVALID_WORKING_PERIOD
for validation failures. - Add unit tests for
from
andtoKoreanPeriod
.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/main/kotlin/com/terning/server/kotlin/domain/internshipAnnouncement/InternshipWorkingPeriod.kt | Introduce VO, validation, formatting, and override equals /hashCode /toString . |
src/main/kotlin/com/terning/server/kotlin/domain/internshipAnnouncement/InternshipErrorCode.kt | Add INVALID_WORKING_PERIOD error code with message. |
src/test/kotlin/com/terning/server/kotlin/domain/internshipAnnouncement/InternshipWorkingPeriodTest.kt | Add tests for valid/invalid creation and toKoreanPeriod . |
Comments suppressed due to low confidence (1)
src/main/kotlin/com/terning/server/kotlin/domain/internshipAnnouncement/InternshipWorkingPeriod.kt:31
- The overridden
toString
method isn’t covered by existing tests; consider adding a unit test to verify that it returns the expected "N개월" string.
override fun toString(): String = toKoreanPeriod()
companion object { | ||
fun from(months: Int): InternshipWorkingPeriod { | ||
return InternshipWorkingPeriod(months) | ||
} | ||
|
||
private fun validatePositive(months: Int) { | ||
if (months <= 0) { | ||
throw InternshipException(InternshipErrorCode.INVALID_WORKING_PERIOD) | ||
} | ||
} |
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.
The validatePositive
function is declared private inside the companion object, making it inaccessible from the init block. Consider moving validation logic into a private class-level function or changing its visibility so the init block can call it directly.
companion object { | |
fun from(months: Int): InternshipWorkingPeriod { | |
return InternshipWorkingPeriod(months) | |
} | |
private fun validatePositive(months: Int) { | |
if (months <= 0) { | |
throw InternshipException(InternshipErrorCode.INVALID_WORKING_PERIOD) | |
} | |
} | |
private fun validatePositive(months: Int) { | |
if (months <= 0) { | |
throw InternshipException(InternshipErrorCode.INVALID_WORKING_PERIOD) | |
} | |
} | |
companion object { | |
fun from(months: Int): InternshipWorkingPeriod { | |
validatePositive(months) | |
return InternshipWorkingPeriod(months) | |
} |
Copilot uses AI. Check for mistakes.
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.
해당 제안은 Kotlin 동작 방식에 대한 오해로 보입니다. 🙌
validatePositive 함수는 companion object 내부에 private으로 선언되어 있지만, Kotlin에서는 클래스 본문(예: init 블록)에서 직접 호출할 수 있습니다. 실제로 현재 구조는 잘 동작하고 있으며, 유효성 검증 로직을 생성자 외부로 분리해 책임을 명확히 한 구조입니다.
따라서 해당 함수의 위치를 클래스 레벨로 옮기지 않아도 되고, 변경 없이 유지하는 것이 더 적절하다고 판단했습니다. 😊
📄 Work Description
InternshipWorkingPeriod
를 구현했습니다.InternshipException
을 발생시키도록 했습니다.toKoreanPeriod
메서드를 제공하여 "N개월" 형식으로 반환합니다.InternshipErrorCode.INVALID_WORKING_PERIOD
항목을 새롭게 정의했습니다.💭 Thoughts
equals
,hashCode
,toString
을 오버라이드하여 VO 특성을 보장하며, 출력 포맷은 명확히 분리된 메서드로 관리했습니다.✅ Testing Result
🗂 Related Issue