Skip to content

[✨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 7 commits into from
May 26, 2025
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, "기타"),
;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 부분은 제가 알기로 공고상세페이지 화면에서 기업의 종류를 나타내는 부분인 것 같아요!
이는 공고 더미를 쌓을 때 적용되는 부분이에요..!
그래서 클라이언트 통신과는 상관이 없는 걸로 알고 있는데 맞을까요..?! (다른 서버통신은 문자열로 하도록 바뀐 걸로 압니당)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

따라서 categoryId는 서버 안에서만 사용될 것으로 보이는데 정수로 기업을 구분하는 것이 위험하다고 판단이 된다면 description으로 분류하는 것도 괜찮을 것 같다는 생각입니다..!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

레거시 코드를 확인해보니, 말씀해주신 것처럼 이 categoryId는 생성자 메서드에서 검증 없이 바로 사용되고 있고,
그에 따라 key로서의 역할도 명확하게 정의되지 않은 상태더라구요.

처음에는 기존 로직을 최대한 그대로 가져오는 방향으로 진행하고 있었는데,
지금 말씀 주신 내용을 보면서 마이그레이션 단계에서 이 부분을 함께 개선하는 게 더 좋겠다는 판단이 들었습니다!

특히 지금처럼 정수 값으로 기업 유형을 구분하는 구조는 이후 유지보수나 확장성 측면에서도 리스크가 클 수 있기 때문에,
내부에서만 사용하는 값이라면 말씀해주신 것처럼 description 기반으로 분류를 전환하는 것도 충분히 고려해볼 수 있을 것 같아요.

이 부분은 마이그레이션 정리 단계에서 구조적으로 정비해보겠습니다!
좋은 논의 포인트 짚어주셔서 감사합니다 🙏


companion object {
fun from(value: Int): CompanyCategory =
entries.firstOrNull { it.categoryId == value }
?: throw InternshipException(InternshipErrorCode.INVALID_COMPANY_CATEGORY)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ enum class InternshipErrorCode(
INVALID_SCRAP_COUNT(HttpStatus.BAD_REQUEST, "스크랩 수는 음수일 수 없습니다."),
SCRAP_COUNT_CANNOT_BE_DECREASED_BELOW_ZERO(HttpStatus.BAD_REQUEST, "스크랩 수는 0보다 작아질 수 없습니다."),
INVALID_VIEW_COUNT(HttpStatus.BAD_REQUEST, "조회수는 음수일 수 없습니다."),
INVALID_COMPANY_CATEGORY(HttpStatus.BAD_REQUEST, "올바르지 않은 기업 구분 값입니다."),
}
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)
}
}
Loading