-
Notifications
You must be signed in to change notification settings - Fork 0
[✨feat] CompanyCategory 구현 #51
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a037ac1
feat(CompanyCategory) : 기업 구분 Enum 도입
jsoonworld 57d2713
feat(InternshipErrorCode) : 기업 구분 예외 케이스 추가
jsoonworld 1dc38d2
test(CompanyCategory) : categoryId 기반 from 메서드 테스트 구현
jsoonworld 8b7ac56
refactor(CompanyCategory) : categoryId 제거 및 displayName 기반 구조로 개선
jsoonworld b14696b
refactor(InternshipErrorCode) : 기업 유형 예외 메시지를 도메인 용어에 맞게 수정
jsoonworld 38aa92e
chore(InternshipErrorCode) : ktlint format 적용
jsoonworld 0d7f75a
test(CompanyCategory) : displayName 기반 조회 및 검증 테스트로 수정
jsoonworld 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
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/terning/server/kotlin/domain/internshipAnnouncement/CompanyCategory.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,21 @@ | ||
package com.terning.server.kotlin.domain.internshipAnnouncement | ||
|
||
enum class CompanyCategory( | ||
val categoryId: Int, | ||
val description: String, | ||
) { | ||
LARGE_AND_MEDIUM_COMPANIES(0, "대기업/중견기업"), | ||
SMALL_COMPANIES(1, "중소기업"), | ||
PUBLIC_INSTITUTIONS(2, "공공기관/공기업"), | ||
FOREIGN_COMPANIES(3, "외국계기업"), | ||
STARTUPS(4, "스타트업"), | ||
NON_PROFIT_ORGANIZATIONS(5, "비영리단체/재단"), | ||
OTHERS(6, "기타"), | ||
; | ||
|
||
companion object { | ||
fun from(value: Int): CompanyCategory = | ||
entries.firstOrNull { it.categoryId == value } | ||
?: throw InternshipException(InternshipErrorCode.INVALID_COMPANY_CATEGORY) | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
...est/kotlin/com/terning/server/kotlin/domain/internshipAnnouncement/CompanyCategoryTest.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,43 @@ | ||
package com.terning.server.kotlin.domain.internshipAnnouncement | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.assertThrows | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.CsvSource | ||
import org.junit.jupiter.params.provider.ValueSource | ||
|
||
class CompanyCategoryTest { | ||
@DisplayName("유효한 categoryId를 전달하면 해당 CompanyCategory를 반환한다") | ||
@ParameterizedTest(name = "categoryId {0} -> {1}") | ||
@CsvSource( | ||
"0, LARGE_AND_MEDIUM_COMPANIES", | ||
"1, SMALL_COMPANIES", | ||
"2, PUBLIC_INSTITUTIONS", | ||
"3, FOREIGN_COMPANIES", | ||
"4, STARTUPS", | ||
"5, NON_PROFIT_ORGANIZATIONS", | ||
"6, OTHERS", | ||
) | ||
fun `return correct CompanyCategory for valid categoryId`( | ||
categoryId: Int, | ||
expectedEnumName: String, | ||
) { | ||
// when | ||
val result = CompanyCategory.from(categoryId) | ||
// then | ||
assertThat(result.name).isEqualTo(expectedEnumName) | ||
} | ||
|
||
@DisplayName("유효하지 않은 categoryId를 전달하면 InternshipException을 던진다") | ||
@ParameterizedTest(name = "categoryId {0} -> exception") | ||
@ValueSource(ints = [-1, 7, 100, 999]) | ||
fun `throw exception when categoryId is invalid`(invalidCategoryId: Int) { | ||
// when & then | ||
val exception = | ||
assertThrows<InternshipException> { | ||
CompanyCategory.from(invalidCategoryId) | ||
} | ||
assertThat(exception.errorCode).isEqualTo(InternshipErrorCode.INVALID_COMPANY_CATEGORY) | ||
} | ||
} |
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.
해당 부분은 제가 알기로 공고상세페이지 화면에서 기업의 종류를 나타내는 부분인 것 같아요!
이는 공고 더미를 쌓을 때 적용되는 부분이에요..!
그래서 클라이언트 통신과는 상관이 없는 걸로 알고 있는데 맞을까요..?! (다른 서버통신은 문자열로 하도록 바뀐 걸로 압니당)
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.
따라서
categoryId
는 서버 안에서만 사용될 것으로 보이는데 정수로 기업을 구분하는 것이 위험하다고 판단이 된다면description
으로 분류하는 것도 괜찮을 것 같다는 생각입니다..!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.
레거시 코드를 확인해보니, 말씀해주신 것처럼 이 categoryId는 생성자 메서드에서 검증 없이 바로 사용되고 있고,
그에 따라 key로서의 역할도 명확하게 정의되지 않은 상태더라구요.
처음에는 기존 로직을 최대한 그대로 가져오는 방향으로 진행하고 있었는데,
지금 말씀 주신 내용을 보면서 마이그레이션 단계에서 이 부분을 함께 개선하는 게 더 좋겠다는 판단이 들었습니다!
특히 지금처럼 정수 값으로 기업 유형을 구분하는 구조는 이후 유지보수나 확장성 측면에서도 리스크가 클 수 있기 때문에,
내부에서만 사용하는 값이라면 말씀해주신 것처럼 description 기반으로 분류를 전환하는 것도 충분히 고려해볼 수 있을 것 같아요.
이 부분은 마이그레이션 정리 단계에서 구조적으로 정비해보겠습니다!
좋은 논의 포인트 짚어주셔서 감사합니다 🙏