Skip to content

[✨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

Open
wants to merge 3 commits into
base: feat/#54
Choose a base branch
from
Open

Conversation

jsoonworld
Copy link
Member

📄 Work Description

  • 인턴십 공고의 근무 기간을 표현하는 VO InternshipWorkingPeriod를 구현했습니다.
  • 유효성 검증을 통해 0 이하의 개월 수 입력 시 InternshipException을 발생시키도록 했습니다.
  • 기간 정보를 사용자에게 보여주기 위해 toKoreanPeriod 메서드를 제공하여 "N개월" 형식으로 반환합니다.
  • 예외 처리를 위해 InternshipErrorCode.INVALID_WORKING_PERIOD 항목을 새롭게 정의했습니다.

💭 Thoughts

  • 단순히 개월 수를 Int로 관리하면 유효하지 않은 값이 혼입될 가능성이 있어 VO로 추상화했습니다.
  • equals, hashCode, toString을 오버라이드하여 VO 특성을 보장하며, 출력 포맷은 명확히 분리된 메서드로 관리했습니다.
  • 앞으로 기간과 관련된 도메인 규칙(예: 최대 개월 수 제한 등)이 생기더라도 이 VO를 중심으로 확장할 수 있는 구조입니다.

✅ Testing Result

스크린샷 2025-05-19 오후 11 28 37


🗂 Related Issue

- 근무 기간이 1개월 미만인 경우를 처리하는 INVALID_WORKING_PERIOD 코드 추가
- 근무 기간을 월 단위로 표현하는 값 객체 `InternshipWorkingPeriod` 구현
- 1개월 미만일 경우 예외 발생
- 한글 기간 문자열 변환 메서드(toKoreanPeriod) 제공
- equals, hashCode, toString 오버라이드
- from 메서드 테스트: 유효한 개월 수 입력 시 객체 생성 확인
- 잘못된 개월 수 입력(0 이하) 시 예외 발생 여부 검증
- toKoreanPeriod 메서드 테스트: "N개월" 형식의 문자열 반환 검증
Copy link

@Copilot Copilot AI left a 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 and toKoreanPeriod.

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()

Comment on lines +13 to +22
companion object {
fun from(months: Int): InternshipWorkingPeriod {
return InternshipWorkingPeriod(months)
}

private fun validatePositive(months: Int) {
if (months <= 0) {
throw InternshipException(InternshipErrorCode.INVALID_WORKING_PERIOD)
}
}
Copy link
Preview

Copilot AI May 19, 2025

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.

Suggested change
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.

Copy link
Member Author

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 블록)에서 직접 호출할 수 있습니다. 실제로 현재 구조는 잘 동작하고 있으며, 유효성 검증 로직을 생성자 외부로 분리해 책임을 명확히 한 구조입니다.

따라서 해당 함수의 위치를 클래스 레벨로 옮기지 않아도 되고, 변경 없이 유지하는 것이 더 적절하다고 판단했습니다. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant