Skip to content

Commit

Permalink
feat: 회원가입 시 산업경영공학부 전공 이름 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
redcarrot1 committed Sep 9, 2024
1 parent c81d7e5 commit a96fcd5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ public class UserManagementApi {
public ApiResponse<UserRegisterResponse> 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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

// 문과대학
Expand Down Expand Up @@ -99,14 +107,25 @@ public enum Major {

private final Collage collage;

Major(Collage collage) {
this.collage = collage;
private static final Map<String, Major> stringToEnum =
Stream.of(values())
.collect(toMap(Object::toString, e -> e));

public static Optional<Major> 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),
Expand All @@ -125,9 +144,6 @@ enum Collage {

private final BadgeType collageBadgeType;

Collage(BadgeType collageBadgeType) {
this.collageBadgeType = collageBadgeType;
}
}

}

0 comments on commit a96fcd5

Please sign in to comment.