From a96fcd53abaa933189a708afe11926a92debb287 Mon Sep 17 00:00:00 2001 From: seungtaekhong Date: Mon, 9 Sep 2024 14:01:01 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20?= =?UTF-8?q?=EC=8B=9C=20=EC=82=B0=EC=97=85=EA=B2=BD=EC=98=81=EA=B3=B5?= =?UTF-8?q?=ED=95=99=EB=B6=80=20=EC=A0=84=EA=B3=B5=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/api/UserManagementApi.java | 4 ++- .../user/api/request/UserRegisterRequest.java | 5 ++-- .../domain/user/domain/Major.java | 26 +++++++++++++++---- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/playkuround/playkuroundserver/domain/user/api/UserManagementApi.java b/src/main/java/com/playkuround/playkuroundserver/domain/user/api/UserManagementApi.java index 4f6bd4bb..1180aa99 100644 --- a/src/main/java/com/playkuround/playkuroundserver/domain/user/api/UserManagementApi.java +++ b/src/main/java/com/playkuround/playkuroundserver/domain/user/api/UserManagementApi.java @@ -37,8 +37,10 @@ public class UserManagementApi { public ApiResponse registerUser(@RequestBody @Valid UserRegisterRequest request) { tokenService.validateAuthVerifyToken(request.getAuthVerifyToken()); + Major major = Major.fromString(request.getMajor()) + .orElseThrow(() -> new IllegalArgumentException("잘못된 학과명입니다.")); UserRegisterDto userRegisterDto - = new UserRegisterDto(request.getEmail(), request.getNickname(), Major.valueOf(request.getMajor())); + = new UserRegisterDto(request.getEmail(), request.getNickname(), major); TokenDto tokenDto = userRegisterService.registerUser(userRegisterDto); tokenService.deleteAuthVerifyToken(request.getAuthVerifyToken()); diff --git a/src/main/java/com/playkuround/playkuroundserver/domain/user/api/request/UserRegisterRequest.java b/src/main/java/com/playkuround/playkuroundserver/domain/user/api/request/UserRegisterRequest.java index 26bb056c..cf373a96 100644 --- a/src/main/java/com/playkuround/playkuroundserver/domain/user/api/request/UserRegisterRequest.java +++ b/src/main/java/com/playkuround/playkuroundserver/domain/user/api/request/UserRegisterRequest.java @@ -1,7 +1,5 @@ package com.playkuround.playkuroundserver.domain.user.api.request; -import com.playkuround.playkuroundserver.domain.user.domain.Major; -import com.playkuround.playkuroundserver.global.validation.ValidEnum; import io.swagger.v3.oas.annotations.ExternalDocumentation; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema.RequiredMode; @@ -30,7 +28,8 @@ public class UserRegisterRequest { @Schema(description = "사용할 닉네임(한글, 영어, 숫자만 허용)", example = "tester", minLength = 2, maxLength = 8) private String nickname; - @ValidEnum(enumClass = Major.class, message = "잘못된 학과명입니다.") + //@ValidEnum(enumClass = Major.class, message = "잘못된 학과명입니다.") + @NotBlank(message = "학과는 필수값입니다.") @Schema(description = "학과. 학과 리스트는 외부 문서 참고", example = "컴퓨터공학부", requiredMode = RequiredMode.REQUIRED) private String major; diff --git a/src/main/java/com/playkuround/playkuroundserver/domain/user/domain/Major.java b/src/main/java/com/playkuround/playkuroundserver/domain/user/domain/Major.java index 92fc5f26..45b4e2de 100644 --- a/src/main/java/com/playkuround/playkuroundserver/domain/user/domain/Major.java +++ b/src/main/java/com/playkuround/playkuroundserver/domain/user/domain/Major.java @@ -1,8 +1,16 @@ package com.playkuround.playkuroundserver.domain.user.domain; import com.playkuround.playkuroundserver.domain.badge.domain.BadgeType; +import lombok.RequiredArgsConstructor; + +import java.util.Map; +import java.util.Optional; +import java.util.stream.Stream; + +import static java.util.stream.Collectors.toMap; @SuppressWarnings("NonAsciiCharacters") +@RequiredArgsConstructor public enum Major { // 문과대학 @@ -99,14 +107,25 @@ public enum Major { private final Collage collage; - Major(Collage collage) { - this.collage = collage; + private static final Map stringToEnum = + Stream.of(values()) + .collect(toMap(Object::toString, e -> e)); + + public static Optional fromString(String source) { + if ("산업경영공학부 산업공학과".equals(source)) { + return Optional.of(Major.산업경영공학부_산업공학과); + } + if ("산업경영공학부 신산업융합학과".equals(source)) { + return Optional.of(Major.산업경영공학부_신산업융합학과); + } + return Optional.ofNullable(stringToEnum.get(source)); } public BadgeType getCollageBadgeType() { return collage.collageBadgeType; } + @RequiredArgsConstructor enum Collage { 문과대학(BadgeType.COLLEGE_OF_LIBERAL_ARTS), 이과대학(BadgeType.COLLEGE_OF_SCIENCES), @@ -125,9 +144,6 @@ enum Collage { private final BadgeType collageBadgeType; - Collage(BadgeType collageBadgeType) { - this.collageBadgeType = collageBadgeType; - } } }