Skip to content

Commit fd8012b

Browse files
committed
[fix] 설문조사 값 한글 변환문제 해결
1 parent 0172807 commit fd8012b

File tree

8 files changed

+108
-67
lines changed

8 files changed

+108
-67
lines changed

src/main/java/com/arom/with_travel/domain/survey/enums/CommStyle.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import com.fasterxml.jackson.annotation.JsonValue;
88
import lombok.AllArgsConstructor;
99

10-
import java.util.Arrays;
10+
import java.util.*;
1111

12-
import static com.arom.with_travel.domain.survey.error.SurveyErrorCode.INVALID_SURVEY_TRAVELGOAL;
12+
import static com.arom.with_travel.domain.survey.error.SurveyErrorCode.*;
1313

1414
@AllArgsConstructor
1515
public enum CommStyle implements SurveyEnum {
@@ -28,11 +28,18 @@ public enum CommStyle implements SurveyEnum {
2828
@JsonValue
2929
public String json(){return code;}
3030

31-
@JsonCreator
32-
public static CommStyle from(String value){
33-
return Arrays.stream(values())
34-
.filter(v -> v.name().equalsIgnoreCase(value) || v.getCode().equalsIgnoreCase(value))
35-
.findFirst()
36-
.orElseThrow(() -> SurveyException.from(INVALID_SURVEY_TRAVELGOAL));
31+
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
32+
public static CommStyle from(String raw) {
33+
if (raw == null) throw SurveyException.from(INVALID_SURVEY_COMMSTYLE);
34+
String v = raw.trim();
35+
36+
for (CommStyle e : values()) {
37+
// 영문 name/code
38+
if (e.name().equalsIgnoreCase(v) || e.code.equalsIgnoreCase(v)) return e;
39+
// 라벨(해시 포함/미포함)
40+
if (e.label.equals(v)) return e;
41+
if (e.label.startsWith("#") && e.label.substring(1).equals(v)) return e;
42+
}
43+
throw SurveyException.from(INVALID_SURVEY_COMMSTYLE);
3744
}
3845
}

src/main/java/com/arom/with_travel/domain/survey/enums/CompanionStyle.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
import com.fasterxml.jackson.annotation.JsonValue;
88
import lombok.AllArgsConstructor;
99

10-
import java.util.Arrays;
10+
import java.util.*;
1111

12+
import static com.arom.with_travel.domain.survey.error.SurveyErrorCode.INVALID_SURVEY_COMPANIONSTYLE;
1213
import static com.arom.with_travel.domain.survey.error.SurveyErrorCode.INVALID_SURVEY_TRAVELGOAL;
1314

1415
@AllArgsConstructor
@@ -28,11 +29,18 @@ public enum CompanionStyle implements SurveyEnum {
2829
@JsonValue
2930
public String json(){return code;}
3031

31-
@JsonCreator
32-
public static CompanionStyle from(String value){
33-
return Arrays.stream(values())
34-
.filter(v -> v.name().equalsIgnoreCase(value) || v.getCode().equalsIgnoreCase(value))
35-
.findFirst()
36-
.orElseThrow(() -> SurveyException.from(INVALID_SURVEY_TRAVELGOAL));
32+
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
33+
public static CompanionStyle from(String raw) {
34+
if (raw == null) throw SurveyException.from(INVALID_SURVEY_COMPANIONSTYLE);
35+
String v = raw.trim();
36+
37+
for (CompanionStyle e : values()) {
38+
// 영문 name/code
39+
if (e.name().equalsIgnoreCase(v) || e.code.equalsIgnoreCase(v)) return e;
40+
// 라벨(해시 포함/미포함)
41+
if (e.label.equals(v)) return e;
42+
if (e.label.startsWith("#") && e.label.substring(1).equals(v)) return e;
43+
}
44+
throw SurveyException.from(INVALID_SURVEY_COMPANIONSTYLE);
3745
}
3846
}
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
11
package com.arom.with_travel.domain.survey.enums;
22

33
import com.arom.with_travel.domain.survey.error.SurveyException;
4-
import com.arom.with_travel.global.exception.BaseException;
5-
import com.arom.with_travel.global.exception.error.ErrorCode;
64
import com.fasterxml.jackson.annotation.JsonCreator;
75
import com.fasterxml.jackson.annotation.JsonValue;
86
import lombok.AllArgsConstructor;
9-
10-
import java.util.Arrays;
11-
127
import static com.arom.with_travel.domain.survey.error.SurveyErrorCode.INVALID_SURVEY_ENERGYLEVEL;
138

149
@AllArgsConstructor
1510
public enum EnergyLevel implements SurveyEnum {
1611

1712
MORNING_PERSON("MORNING_PERSON", "#아침형인간"),
18-
NIGHT_OWL("NIGHT_OWL", "#밤올빼미"),
19-
ENERGIZER("ENERGIZER", "#에너자이저"),
20-
HEALING_MODE("HEALING_MODE", "#힐링모드");
13+
NIGHT_OWL ("NIGHT_OWL", "#밤올빼미"),
14+
ENERGIZER ("ENERGIZER", "#에너자이저"),
15+
HEALING_MODE ("HEALING_MODE", "#힐링모드");
2116

2217
private final String code;
2318
private final String label;
2419

2520
@Override public String getCode() { return code; }
2621
@Override public String getLabel() { return label; }
2722

28-
// 응답으로는 code를 내보내기
23+
/** 응답은 code로 통일 */
2924
@JsonValue
3025
public String json() { return code; }
3126

32-
// 요청으로는 name/code 둘 다 허용
33-
@JsonCreator
34-
public static EnergyLevel from(String value) {
35-
return Arrays.stream(values())
36-
.filter(v -> v.name().equalsIgnoreCase(value) || v.code.equalsIgnoreCase(value))
37-
.findFirst()
38-
.orElseThrow(() -> SurveyException.from(INVALID_SURVEY_ENERGYLEVEL));
27+
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
28+
public static EnergyLevel from(String raw) {
29+
if (raw == null) throw SurveyException.from(INVALID_SURVEY_ENERGYLEVEL);
30+
String v = raw.trim();
31+
32+
for (EnergyLevel e : values()) {
33+
// 영문 name/code
34+
if (e.name().equalsIgnoreCase(v) || e.code.equalsIgnoreCase(v)) return e;
35+
// 라벨(해시 포함/미포함)
36+
if (e.label.equals(v)) return e;
37+
if (e.label.startsWith("#") && e.label.substring(1).equals(v)) return e;
38+
}
39+
throw SurveyException.from(INVALID_SURVEY_ENERGYLEVEL);
3940
}
40-
}
41+
}

src/main/java/com/arom/with_travel/domain/survey/enums/RecordTendency.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import com.fasterxml.jackson.annotation.JsonValue;
88
import lombok.AllArgsConstructor;
99

10-
import java.util.Arrays;
10+
import java.util.*;
1111

12-
import static com.arom.with_travel.domain.survey.error.SurveyErrorCode.INVALID_SURVEY_TRAVELGOAL;
12+
import static com.arom.with_travel.domain.survey.error.SurveyErrorCode.*;
1313

1414
@AllArgsConstructor
1515
public enum RecordTendency implements SurveyEnum {
@@ -28,11 +28,18 @@ public enum RecordTendency implements SurveyEnum {
2828
@JsonValue
2929
public String json(){return code;}
3030

31-
@JsonCreator
32-
public static RecordTendency from(String value){
33-
return Arrays.stream(values())
34-
.filter(v -> v.name().equalsIgnoreCase(value) || v.getCode().equalsIgnoreCase(value))
35-
.findFirst()
36-
.orElseThrow(() -> SurveyException.from(INVALID_SURVEY_TRAVELGOAL));
31+
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
32+
public static RecordTendency from(String raw) {
33+
if (raw == null) throw SurveyException.from(INVALID_SURVEY_RECORDTENDENCY);
34+
String v = raw.trim();
35+
36+
for (RecordTendency e : values()) {
37+
// 영문 name/code
38+
if (e.name().equalsIgnoreCase(v) || e.code.equalsIgnoreCase(v)) return e;
39+
// 라벨(해시 포함/미포함)
40+
if (e.label.equals(v)) return e;
41+
if (e.label.startsWith("#") && e.label.substring(1).equals(v)) return e;
42+
}
43+
throw SurveyException.from(INVALID_SURVEY_RECORDTENDENCY);
3744
}
3845
}

src/main/java/com/arom/with_travel/domain/survey/enums/SpendPattern.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import com.fasterxml.jackson.annotation.JsonValue;
88
import lombok.AllArgsConstructor;
99

10-
import java.util.Arrays;
10+
import java.util.*;
1111

12-
import static com.arom.with_travel.domain.survey.error.SurveyErrorCode.INVALID_SURVEY_TRAVELGOAL;
12+
import static com.arom.with_travel.domain.survey.error.SurveyErrorCode.*;
1313

1414
@AllArgsConstructor
1515
public enum SpendPattern implements SurveyEnum {
@@ -27,11 +27,18 @@ public enum SpendPattern implements SurveyEnum {
2727
@JsonValue
2828
public String json(){return code;}
2929

30-
@JsonCreator
31-
public static SpendPattern from(String value){
32-
return Arrays.stream(values())
33-
.filter(v -> v.name().equalsIgnoreCase(value) || v.getCode().equalsIgnoreCase(value))
34-
.findFirst()
35-
.orElseThrow(() -> SurveyException.from(INVALID_SURVEY_TRAVELGOAL));
30+
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
31+
public static SpendPattern from(String raw) {
32+
if (raw == null) throw SurveyException.from(INVALID_SURVEY_SPENDPATTERN);
33+
String v = raw.trim();
34+
35+
for (SpendPattern e : values()) {
36+
// 영문 name/code
37+
if (e.name().equalsIgnoreCase(v) || e.code.equalsIgnoreCase(v)) return e;
38+
// 라벨(해시 포함/미포함)
39+
if (e.label.equals(v)) return e;
40+
if (e.label.startsWith("#") && e.label.substring(1).equals(v)) return e;
41+
}
42+
throw SurveyException.from(INVALID_SURVEY_SPENDPATTERN);
3643
}
3744
}

src/main/java/com/arom/with_travel/domain/survey/enums/TravelGoal.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
import com.fasterxml.jackson.annotation.JsonValue;
88
import lombok.AllArgsConstructor;
99

10-
import java.util.Arrays;
10+
import java.util.*;
1111

12+
import static com.arom.with_travel.domain.survey.error.SurveyErrorCode.INVALID_SURVEY_SPENDPATTERN;
1213
import static com.arom.with_travel.domain.survey.error.SurveyErrorCode.INVALID_SURVEY_TRAVELGOAL;
1314

1415
@AllArgsConstructor
@@ -29,11 +30,18 @@ public enum TravelGoal implements SurveyEnum {
2930
@JsonValue
3031
public String json(){return code;}
3132

32-
@JsonCreator
33-
public static TravelGoal from(String value){
34-
return Arrays.stream(values())
35-
.filter(v -> v.name().equalsIgnoreCase(value) || v.getCode().equalsIgnoreCase(value))
36-
.findFirst()
37-
.orElseThrow(() -> SurveyException.from(INVALID_SURVEY_TRAVELGOAL));
33+
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
34+
public static TravelGoal from(String raw) {
35+
if (raw == null) throw SurveyException.from(INVALID_SURVEY_TRAVELGOAL);
36+
String v = raw.trim();
37+
38+
for (TravelGoal e : values()) {
39+
// 영문 name/code
40+
if (e.name().equalsIgnoreCase(v) || e.code.equalsIgnoreCase(v)) return e;
41+
// 라벨(해시 포함/미포함)
42+
if (e.label.equals(v)) return e;
43+
if (e.label.startsWith("#") && e.label.substring(1).equals(v)) return e;
44+
}
45+
throw SurveyException.from(INVALID_SURVEY_TRAVELGOAL);
3846
}
3947
}
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package com.arom.with_travel.domain.survey.enums;
22

33
import com.arom.with_travel.domain.survey.error.SurveyException;
4-
import com.arom.with_travel.global.exception.BaseException;
5-
import com.arom.with_travel.global.exception.error.ErrorCode;
64
import com.fasterxml.jackson.annotation.JsonCreator;
75
import com.fasterxml.jackson.annotation.JsonValue;
86
import lombok.AllArgsConstructor;
97

10-
import java.util.Arrays;
11-
12-
import static com.arom.with_travel.domain.survey.error.SurveyErrorCode.INVALID_SURVEY_TRAVELGOAL;
8+
import static com.arom.with_travel.domain.survey.error.SurveyErrorCode.INVALID_SURVEY_TRAVELPACE;
139

1410
@AllArgsConstructor
1511
public enum TravelPace implements SurveyEnum {
@@ -28,11 +24,18 @@ public enum TravelPace implements SurveyEnum {
2824
@JsonValue
2925
public String json(){return code;}
3026

31-
@JsonCreator
32-
public static TravelPace from(String value){
33-
return Arrays.stream(values())
34-
.filter(v -> v.name().equalsIgnoreCase(value) || v.getCode().equalsIgnoreCase(value))
35-
.findFirst()
36-
.orElseThrow(() -> SurveyException.from(INVALID_SURVEY_TRAVELGOAL));
27+
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
28+
public static TravelPace from(String raw) {
29+
if (raw == null) throw SurveyException.from(INVALID_SURVEY_TRAVELPACE);
30+
String v = raw.trim();
31+
32+
for (TravelPace e : values()) {
33+
// 영문 name/code
34+
if (e.name().equalsIgnoreCase(v) || e.code.equalsIgnoreCase(v)) return e;
35+
// 라벨(해시 포함/미포함)
36+
if (e.label.equals(v)) return e;
37+
if (e.label.startsWith("#") && e.label.substring(1).equals(v)) return e;
38+
}
39+
throw SurveyException.from(INVALID_SURVEY_TRAVELPACE);
3740
}
3841
}

src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
spring:
22
profiles:
3-
active: dev
3+
active: local

0 commit comments

Comments
 (0)