-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Controller return Response Entity 신규 양식으로 변경 가입, 로그인시 발생하는 위험요소에 대한 Exception 처리
- Loading branch information
gunsight1
committed
Jan 19, 2024
1 parent
e9a036e
commit b80e0fc
Showing
11 changed files
with
182 additions
and
45 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
module-api/src/main/java/com/kernel360/member/code/MemberBusinessCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.kernel360.member.code; | ||
|
||
import com.kernel360.code.BusinessCode; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@RequiredArgsConstructor | ||
public enum MemberBusinessCode implements BusinessCode { | ||
|
||
SUCCESS_REQUEST_JOIN_MEMBER_CREATED(HttpStatus.CREATED.value(), "BMEC001", "회원가입 성공"), | ||
SUCCESS_REQUEST_LOGIN_MEMBER(HttpStatus.OK.value(), "BMEC002", "로그인 성공"); | ||
|
||
|
||
private final int status; | ||
private final String code; | ||
private final String message; | ||
|
||
@Override | ||
public int getStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public String getCode() { | ||
return code; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
module-api/src/main/java/com/kernel360/member/code/MemberErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.kernel360.member.code; | ||
|
||
import com.kernel360.code.ErrorCode; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@RequiredArgsConstructor | ||
public enum MemberErrorCode implements ErrorCode { | ||
|
||
FAILED_NOT_MAPPING_ORDINAL_TO_NAME(HttpStatus.INTERNAL_SERVER_ERROR.value(), "EMEC001", "DB값과 ENUM의 ORDINAL이 불일치하여 NAME을 찾을 수 없음."), | ||
FAILED_NOT_MAPPING_ORDINAL_TO_VALUE(HttpStatus.INTERNAL_SERVER_ERROR.value(), "EMEC002", "DB값과 ENUM의 VALUE가 불일치하여 VALUE을 찾을 수 없음."), | ||
FAILED_NOT_MAPPING_ENUM_VALUEOF(HttpStatus.INTERNAL_SERVER_ERROR.value(), "EMEC003", "PARAMETER 값과 ENUM의 NAME이 불일치함."), | ||
FAILED_GENERATE_JOIN_MEMBER_INFO(HttpStatus.INTERNAL_SERVER_ERROR.value(), "EMEC004", "회원가입에 필요한 정보 생성 실패"), | ||
FAILED_GENERATE_LOGIN_REQUEST_INFO(HttpStatus.INTERNAL_SERVER_ERROR.value(), "EMEC005", "정보 불일치로 인한 로그인 정보 생성 실패"), | ||
FAILED_REQUEST_LOGIN(HttpStatus.BAD_REQUEST.value(), "EMEC006", "정보 불일치로 인한 로그인 실패"); | ||
|
||
|
||
|
||
private final int status; | ||
private final String code; | ||
private final String message; | ||
|
||
@Override | ||
public int getStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public String getCode() { | ||
return code; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
module-api/src/main/java/com/kernel360/member/enumset/Age.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.kernel360.member.enumset; | ||
|
||
import com.kernel360.exception.BusinessException; | ||
import com.kernel360.member.code.MemberErrorCode; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public enum Age { | ||
AGE_20(20), | ||
AGE_30(30), | ||
AGE_40(40), | ||
AGE_50(50), | ||
AGE_60(60); | ||
|
||
private final int value; | ||
|
||
public static String ordinalToValue(int key) { | ||
for (Age age : values()) { | ||
if (age.ordinal() == key) { | ||
return String.valueOf(age.value); | ||
} | ||
} | ||
throw new BusinessException(MemberErrorCode.FAILED_NOT_MAPPING_ORDINAL_TO_VALUE); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
module-api/src/main/java/com/kernel360/member/enumset/Gender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.kernel360.member.enumset; | ||
|
||
import com.kernel360.exception.BusinessException; | ||
import com.kernel360.member.code.MemberErrorCode; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public enum Gender { | ||
man(0), | ||
woman(1); | ||
|
||
private final int value; | ||
public static String ordinalToName(int value) { | ||
for (Gender gender : values()) { | ||
if (gender.ordinal() == value) { | ||
return gender.name(); | ||
} | ||
} | ||
throw new BusinessException(MemberErrorCode.FAILED_NOT_MAPPING_ORDINAL_TO_NAME); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ public void setup() { | |
void 회원가입요청() throws Exception { | ||
|
||
/** given 목데이터 세팅 **/ | ||
MemberDto memberDto = MemberDto.of("testID", "[email protected]", "testPassword"); | ||
MemberDto memberDto = MemberDto.of("testID", "[email protected]", "testPassword", "man","30"); | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
String param = objectMapper.writeValueAsString(memberDto); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,6 @@ | |
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.LocalDate; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
|
||
|
@@ -14,8 +12,8 @@ class MemberTest { | |
private String id; | ||
private String email; | ||
private String password; | ||
private String gender; | ||
private LocalDate birthdate; | ||
private int gender; | ||
private int age; | ||
private Member member; | ||
|
||
@BeforeEach | ||
|
@@ -24,10 +22,10 @@ class MemberTest { | |
id = "user123"; | ||
email = "[email protected]"; | ||
password = "password123"; | ||
gender = "Female"; | ||
birthdate = LocalDate.of(1990, 1, 1); | ||
gender = 0; | ||
age = 3; | ||
|
||
member = Member.of(memberNo, id, email, password, gender, birthdate); | ||
member = Member.of(memberNo, id, email, password, gender, age); | ||
} | ||
|
||
@Test | ||
|
@@ -37,6 +35,6 @@ class MemberTest { | |
assertThat(member.getEmail()).isEqualTo(email); | ||
assertThat(member.getPassword()).isEqualTo(password); | ||
assertThat(member.getGender()).isEqualTo(gender); | ||
assertThat(member.getBirthdate()).isEqualTo(birthdate); | ||
assertThat(member.getAge()).isEqualTo(age); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ public void init() { | |
void 회원가입_로직_테스트() { | ||
|
||
/** given **/ | ||
MemberDto requestDto = MemberDto.of("testID", "[email protected]", "testPassword"); | ||
MemberDto requestDto = MemberDto.of("testID", "[email protected]", "testPassword", "man", "AGE_40"); | ||
Member member = memberService.getNewJoinMemberEntity(requestDto); | ||
|
||
/** when **/ | ||
|
@@ -81,7 +81,7 @@ public void init() { | |
/** given **/ | ||
MemberDto loginDto = MemberDto.of("test03", "1234qwer"); | ||
Member mockLoginEntity = Member.loginMember(loginDto.id(), loginDto.password()); | ||
Member mockEntity = Member.of(502L, loginDto.id(), "[email protected]", "0eb9de69892882d54516e03e30098354a2e39cea36adab275b6300c737c942fd", null, null); | ||
Member mockEntity = Member.of(502L, loginDto.id(), "[email protected]", "0eb9de69892882d54516e03e30098354a2e39cea36adab275b6300c737c942fd", 0, 0); | ||
String mockToken = "dummy_token"; | ||
|
||
/** stub **/ | ||
|
@@ -105,7 +105,7 @@ public void init() { | |
void 토큰_발급_저장_테스트() { | ||
|
||
/** given **/ | ||
Member memberEntity = Member.of(502L, "test03", null, null, null, null); | ||
Member memberEntity = Member.of(502L, "test03", null, null, 0, 0); | ||
String mockToken = "mockToken"; | ||
Auth auth = Auth.jwt(null, 502L, mockToken); | ||
|
||
|
@@ -136,7 +136,7 @@ public void init() { | |
|
||
/** given **/ | ||
String id = "test01"; | ||
Member memberEntity = Member.of(51L, "test01", null, null, null, null); | ||
Member memberEntity = Member.of(51L, "test01", null, null, 0, 0); | ||
|
||
/** stub **/ | ||
when(memberRepository.findOneById(anyString())).thenReturn(memberEntity); | ||
|
@@ -175,7 +175,7 @@ public void init() { | |
|
||
/** given **/ | ||
String email = "[email protected]"; | ||
Member memberEntity = Member.of(51L, "test01", "[email protected]", null, null, null); | ||
Member memberEntity = Member.of(51L, "test01", "[email protected]", null, 0, 0); | ||
|
||
/** stub **/ | ||
when(memberRepository.findOneByEmail(anyString())).thenReturn(memberEntity); | ||
|
Oops, something went wrong.