Skip to content

Commit

Permalink
fix: 회원가입 시 입력된 문자열을 enum으로 변환하도록 변경 (#102)
Browse files Browse the repository at this point in the history
- MainCategory enum화에 따른 변경
  • Loading branch information
ja7811 authored Aug 30, 2024
1 parent cc11476 commit e42e32b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/main/java/com/umc/owncast/domain/enums/MainCategory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.umc.owncast.domain.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.AllArgsConstructor;
import lombok.Getter;

Expand All @@ -20,4 +21,45 @@ public enum MainCategory {
public String getKrSubCategory() {
return this.subCategory;
}

@JsonCreator
/** String에서 MainCategory 추출 */
public static MainCategory fromValue(String value) {
String normalizedValue = value.toUpperCase().strip();

switch(normalizedValue){
case "스포츠":
return SPORTS;
case "음악":
return MUSIC;
case "책":
return BOOK;
case "미술":
return ART;
case "드라마":
case "영화":
case "드라마/영화":
case "영화/드라마":
return DRAMA;
case "음식":
return FOOD;
case "시사":
case "뉴스":
case "시사/뉴스":
case "뉴스/시사":
return NEWS;
case "직접 입력":
return ETC;
default:
break;
}

for (MainCategory category : MainCategory.values()) {
if (category.name().equals(normalizedValue)) {
return category;
}
}

throw new IllegalArgumentException("Unknown main category: " + value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public MemberSettingResponseDTO languageSetting(Member member, String language)
}

public MemberSettingResponseDTO preferSetting(Member member, MemberPreferRequestDTO memberPreferRequestDTO) {
MainCategory mainCategory = MainCategory.valueOf(memberPreferRequestDTO.getMainCategory().toUpperCase(Locale.ROOT));
MainCategory mainCategory = MainCategory.fromValue(memberPreferRequestDTO.getMainCategory());
SubCategory subCategory = subCategoryRepository.findByName(memberPreferRequestDTO.getSubCategory())
.orElseGet(() -> {
if (memberPreferRequestDTO.getSubCategory() == null) {
Expand Down

0 comments on commit e42e32b

Please sign in to comment.