-
Notifications
You must be signed in to change notification settings - Fork 0
[Refactor/#171] 수동 Enum 매핑 로직을 제거하고 kotlinx.serialization에 위임합니다. #172
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
Conversation
- `RecommendedRoutineType`, `EmotionMarbleType`, `DayOfWeek` Enum 클래스에 `@Serializable` 어노테이션을 추가하여 직렬화를 적용합니다.
Walkthrough수동 문자열→enum 매핑 로직을 제거하고 Kotlinx Serialization( Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In
`@data/src/main/java/com/threegap/bitnagil/data/recommendroutine/model/response/RecommendedRoutineDto.kt`:
- Around line 17-23: 열거형 직렬화 값이 API 계약과 다르므로 RecommendLevel과 RecommendCategory
enum의 각 상수에 `@SerialName을` 추가하거나 해당 enum들에 대해 커스텀 KSerializer를 구현해 서버 응답(예:
"level_1", "personalized" 등)과 매핑되도록 수정하세요; RecommendedRoutineDto의
필드들(recommendedRoutineLevel, recommendedRoutineType)을 변경할 필요는 없고, 문제는
RecommendLevel 및 RecommendCategory 정의에서 각 값마다 정확한 `@SerialName`(또는 serializer 로직)을
선언하여 역직렬화 실패를 방지하는 것입니다.
In `@domain/src/main/java/com/threegap/bitnagil/domain/auth/model/UserRole.kt`:
- Around line 5-12: The UserRole enum currently risks a SerializationException
when the API returns an unknown role string; implement a safe deserialization
strategy for UserRole (e.g., create a custom KSerializer and annotate the enum
with `@Serializable`(with = UserRole.Serializer::class) or add explicit
`@SerialName` mappings) that maps any unrecognized or null role values to
UserRole.UNKNOWN; update the enum (UserRole) to use that serializer and ensure
serialization still writes standard names while deserialization tolerates
unknown values.
In
`@domain/src/main/java/com/threegap/bitnagil/domain/recommendroutine/model/RecommendCategory.kt`:
- Around line 5-15: The RecommendCategory enum defines an UNKNOWN constant but
deserialization won't fallback to it unless Json is configured to coerce values;
update JSON parsing setup to enable coerceInputValues = true (e.g., in the Json
{ ... } configuration) so unknown enum values map to RecommendCategory.UNKNOWN,
or alternatively implement a custom serializer for RecommendCategory that maps
unrecognized strings to UNKNOWN; locate usages around RecommendCategory and your
Json configuration to apply the change.
🧹 Nitpick comments (4)
data/src/main/java/com/threegap/bitnagil/data/routine/model/response/RoutineDto.kt (1)
41-41: 불필요한.map { it }제거
.map { it }은 리스트를 그대로 복사하는 no-op입니다. 직접 할당하거나 새 리스트가 필요한 경우.toList()를 사용하세요.♻️ 제안된 수정
- repeatDays = this.repeatDay.map { it }, + repeatDays = this.repeatDay,data/src/main/java/com/threegap/bitnagil/data/writeroutine/repositoryImpl/WriteRoutineRepositoryImpl.kt (1)
31-31: 불필요한.map { it }제거Line 31과 59에서
.map { it }는 불필요합니다.repeatDay를 직접 전달하세요.♻️ 제안된 수정
val request = RegisterRoutineRequest( routineName = name, - repeatDay = repeatDay.map { it }, + repeatDay = repeatDay, executionTime = startTime.toString(),val request = EditRoutineRequest( routineId = routineId, updateApplyDate = routineUpdateType, routineName = name, - repeatDay = repeatDay.map { it }, + repeatDay = repeatDay, executionTime = startTime.toString(),Also applies to: 59-59
data/src/main/java/com/threegap/bitnagil/data/recommendroutine/model/response/RecommendRoutinesDto.kt (1)
19-21:mapValues사용으로 간결화 가능
.map { ... }.toMap()패턴 대신mapValues를 사용하면 더 간결해집니다.♻️ 제안된 수정
fun RecommendRoutinesDto.toDomain(): RecommendRoutines = RecommendRoutines( - recommendRoutinesByCategory = this.recommendedRoutinesByCategory.map { (category, routines) -> - category to routines.map { it.toDomain() } - }.toMap(), + recommendRoutinesByCategory = this.recommendedRoutinesByCategory.mapValues { (_, routines) -> + routines.map { it.toDomain() } + }, emotionMarbleType = this.emotionMarbleType, )presentation/src/main/java/com/threegap/bitnagil/presentation/common/extension/RecommendCategoryEtx.kt (1)
34-44: 문자열 리소스 사용 권장하드코딩된 한국어 문자열 대신 Android 문자열 리소스(
strings.xml)를 사용하면 i18n 지원이 용이해집니다.♻️ 예시
val RecommendCategory.displayTitle: String `@Composable` get() = when (this) { RecommendCategory.PERSONALIZED -> stringResource(R.string.category_personalized) RecommendCategory.OUTING -> stringResource(R.string.category_outing) // ... }참고:
@Composablegetter로 변경이 필요합니다.
...ain/java/com/threegap/bitnagil/data/recommendroutine/model/response/RecommendedRoutineDto.kt
Show resolved
Hide resolved
domain/src/main/java/com/threegap/bitnagil/domain/auth/model/UserRole.kt
Show resolved
Hide resolved
domain/src/main/java/com/threegap/bitnagil/domain/recommendroutine/model/RecommendCategory.kt
Show resolved
Hide resolved
data/src/main/java/com/threegap/bitnagil/data/routine/model/response/RoutineDto.kt
Outdated
Show resolved
Hide resolved
...in/java/com/threegap/bitnagil/data/writeroutine/repositoryImpl/WriteRoutineRepositoryImpl.kt
Show resolved
Hide resolved
l5x5l
left a comment
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.
고생하셨습니다! 🚀🚀
[ PR Content ]
fromString()과 같이 수동으로 관리하고 있던 매핑로직을 제거하고 kotlin.serialization에게 해당 작업을 위임하도록 했습니다.
저번 리포트 기능 개발에서도 언급했던 내용인데 이번 작업에서 프로젝트 전반에 적용을 했습니다.
원리를 간략하게 설명해보자면 kotlin.serialization은 컴파일 시점에 생성해준 최적화된 매핑로직을 이용하는 방식입니다. -> 수동으로 작성 안해도됨!
Related issue
Screenshot 📸
Work Description
To Reviewers 📢
Summary by CodeRabbit
릴리즈 노트