Skip to content

Commit 1c81161

Browse files
Ji-soo708chock-cho
authored andcommitted
[YS-533] refactor: ExperimentPostKeywordMapper 키워드 매핑 로직 리팩터링 (#163)
* refactor: simplify keyword mapping logic with safe enum parsing * feat: handle unknown keyword enums as null for robustness
1 parent c2831fc commit 1c81161

File tree

2 files changed

+16
-45
lines changed

2 files changed

+16
-45
lines changed

infrastructure/src/main/kotlin/com/dobby/external/prompt/ExperimentPostKeywordMapper.kt

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package com.dobby.external.prompt
33
import com.dobby.enums.MatchType
44
import com.dobby.enums.experiment.TimeSlot
55
import com.dobby.enums.member.GenderType
6-
import com.dobby.external.prompt.dto.ApplyMethodDto
76
import com.dobby.external.prompt.dto.ExperimentPostKeywordDto
8-
import com.dobby.external.prompt.dto.TargetGroupDto
97
import com.dobby.model.experiment.keyword.ApplyMethodKeyword
108
import com.dobby.model.experiment.keyword.ExperimentPostKeywords
119
import com.dobby.model.experiment.keyword.TargetGroupKeyword
@@ -18,37 +16,36 @@ class ExperimentPostKeywordMapper {
1816
return ExperimentPostKeywords(
1917
targetGroup = dto.targetGroup?.let { targetGroupDto ->
2018
TargetGroupKeyword(
21-
startAge = targetGroupDto.startAge ?: 0,
22-
endAge = targetGroupDto.endAge ?: 0,
23-
genderType = targetGroupDto.genderType?.let { genderStr ->
24-
when (genderStr) {
25-
"MALE" -> GenderType.MALE
26-
"FEMALE" -> GenderType.FEMALE
27-
"ALL" -> GenderType.ALL
28-
else -> GenderType.ALL
19+
startAge = targetGroupDto.startAge,
20+
endAge = targetGroupDto.endAge,
21+
genderType = targetGroupDto.genderType?.let {
22+
try {
23+
GenderType.valueOf(it)
24+
} catch (e: IllegalArgumentException) {
25+
null
2926
}
30-
} ?: GenderType.ALL,
27+
},
3128
otherCondition = targetGroupDto.otherCondition
3229
)
3330
},
3431
applyMethod = dto.applyMethod?.let { applyMethodDto ->
3532
ApplyMethodKeyword(
36-
content = applyMethodDto.content ?: "",
33+
content = applyMethodDto.content,
3734
isFormUrl = applyMethodDto.isFormUrl,
38-
formUrl = applyMethodDto.formUrl ?: "",
35+
formUrl = applyMethodDto.formUrl,
3936
isPhoneNum = applyMethodDto.isPhoneNum,
40-
phoneNum = applyMethodDto.phoneNum ?: ""
37+
phoneNum = applyMethodDto.phoneNum
4138
)
4239
},
4340
matchType = dto.matchType?.let { matchTypeStr ->
4441
try {
4542
MatchType.valueOf(matchTypeStr)
4643
} catch (e: IllegalArgumentException) {
47-
MatchType.ALL
44+
null
4845
}
49-
} ?: MatchType.ALL,
50-
reward = dto.reward ?: "",
51-
count = dto.count ?: 0,
46+
},
47+
reward = dto.reward,
48+
count = dto.count,
5249
timeRequired = dto.timeRequired?.takeIf { it.isNotBlank() }?.let { timeSlotStr ->
5350
try {
5451
TimeSlot.valueOf(timeSlotStr)
@@ -58,30 +55,4 @@ class ExperimentPostKeywordMapper {
5855
}
5956
)
6057
}
61-
62-
fun toDto(domain: ExperimentPostKeywords): ExperimentPostKeywordDto {
63-
return ExperimentPostKeywordDto(
64-
targetGroup = domain.targetGroup?.let { targetGroupDomain ->
65-
TargetGroupDto(
66-
startAge = targetGroupDomain.startAge,
67-
endAge = targetGroupDomain.endAge,
68-
genderType = targetGroupDomain.genderType?.name,
69-
otherCondition = targetGroupDomain.otherCondition
70-
)
71-
},
72-
applyMethod = domain.applyMethod?.let { applyMethodDomain ->
73-
ApplyMethodDto(
74-
content = applyMethodDomain.content,
75-
isFormUrl = applyMethodDomain.isFormUrl,
76-
formUrl = applyMethodDomain.formUrl,
77-
isPhoneNum = applyMethodDomain.isPhoneNum,
78-
phoneNum = applyMethodDomain.phoneNum
79-
)
80-
},
81-
matchType = domain.matchType?.name,
82-
reward = domain.reward,
83-
count = domain.count,
84-
timeRequired = domain.timeRequired?.name
85-
)
86-
}
8758
}

infrastructure/src/main/resources/prompts/keyword_extraction_prompt.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"conditions": [
3636
"공고 본문을 정확히 분석하여 각 항목에 맞는 정보를 추출한다.",
3737
"추출된 정보는 반드시 output_format에 따라 JSON 형태로 출력한다.",
38-
"정보가 명시되지 않은 경우 해당 필드는 빈 문자열(\"\") 또는 0으로 설정한다.",
38+
"정보가 명시되지 않은 경우 해당 필드는 null로 설정한다.",
3939
"URL이나 전화번호가 포함된 경우 해당 boolean 값을 true로 설정한다.",
4040
"각 항목은 지정된 최대 글자 수를 초과하지 않도록 한다."
4141
]

0 commit comments

Comments
 (0)