Skip to content

Commit

Permalink
Merge pull request #226 from gunsight1/feature_add_account_type
Browse files Browse the repository at this point in the history
feature :: 회원가입, 로그인시 계정 타입 추가
  • Loading branch information
gunsight1 authored Feb 29, 2024
2 parents 51239ee + 68bfa3a commit f350c16
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public Member toEntity() {
this.email(),
this.password(),
Gender.valueOf(this.gender()).ordinal(),
Age.valueOf(this.age()).ordinal()
Age.valueOf(this.age()).ordinal(),
null
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.kernel360.member.enumset;

public enum AccountType {
PLATFORM, KAKAO, NAVER, GOOGLE
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.kernel360.member.dto.*;
import com.kernel360.member.entity.Member;
import com.kernel360.member.entity.WithdrawMember;
import com.kernel360.member.enumset.AccountType;
import com.kernel360.member.enumset.Age;
import com.kernel360.member.enumset.Gender;
import com.kernel360.member.repository.MemberRepository;
Expand Down Expand Up @@ -63,7 +64,7 @@ protected Member getNewJoinMemberEntity(MemberDto requestDto) {
throw new BusinessException(MemberErrorCode.FAILED_NOT_MAPPING_ENUM_VALUE_OF);
}

return Member.createJoinMember(requestDto.id(), requestDto.email(), encodePassword, genderOrdinal, ageOrdinal);
return Member.createJoinMember(requestDto.id(), requestDto.email(), encodePassword, genderOrdinal, ageOrdinal, AccountType.PLATFORM.name());
}

@Transactional
Expand All @@ -78,6 +79,7 @@ public MemberDto login(MemberDto loginDto, HttpServletRequest request) {

String loginToken = jwt.generateToken(memberEntity.getId());

//TODO REFACTOR AUTH 정보를 RDB -> 래디스로 변경
authService.saveAuthByMember(memberEntity.getMemberNo(), ConvertSHA256.convertToSHA256(loginToken), request);

return MemberDto.login(memberEntity, loginToken);
Expand Down Expand Up @@ -123,12 +125,11 @@ public void deleteMember(String id) {
}

@Transactional
public void deleteMemberByToken(String token) {
final String id = JWT.ownerId(token);
Member member = memberRepository.findOneById(id);
//Fixme :: 멤버 탈퇴시, Deleted Table을 만들고, 데이터를 백업한후, 삭제하는 방식이나, MemberTable에 삭제여부를 표시하는 방식으로 리팩토링 필요
public void deleteMemberByToken(String accessToken) {
Member member = memberRepository.findOneById(JWT.ownerId(accessToken));
withdrawMemberRepository.save(WithdrawMember.of(member)); //of 받는식을 변경했습니다. 이 방식으로 리팩터를 하면 코드가 깔끔하네요.
memberRepository.delete(member);
log.info("{} 회원 탈퇴 처리 완료", id);
log.info("{} 회원 탈퇴 처리 완료", accessToken);
}

@Transactional
Expand Down Expand Up @@ -256,28 +257,20 @@ public MemberDto loginForKakao(String accessToken, HttpServletRequest request) {
KakaoUserDto kakaoUser = kakaoRequest.getKakaoUserByToken(accessToken);
if (Objects.isNull(memberRepository.findOneById(kakaoUser.id()))) {
memberRepository.save(
Member.createForKakao(kakaoUser.id(), kakaoUser.email(), "kakao", Gender.OTHERS.ordinal(),
Age.AGE_99.ordinal()));
Member.createJoinMember(kakaoUser.id(), kakaoUser.email(), "kakao", Gender.OTHERS.ordinal(),
Age.AGE_99.ordinal(), AccountType.KAKAO.name()));
}

MemberDto memberDto = MemberDto.from(memberRepository.findOneById(kakaoUser.id()));

String loginToken = jwt.generateToken(memberDto.id());

//TODO REFACTOR AUTH 정보를 RDB -> 래디스로 변경
authService.saveAuthByMember(memberDto.memberNo(), ConvertSHA256.convertToSHA256(loginToken), request);

return MemberDto.fromKakao(memberDto, loginToken);
}

@Transactional
public void signOut(String accessToken) {
Member member = memberRepository.findOneById(JWT.ownerId(accessToken));

withdrawMemberRepository.save(WithdrawMember.of(member.getMemberNo(),member.getId(), member.getEmail(), null));

memberRepository.delete(member);
}

@Transactional(readOnly = true)
public boolean validatePassword(String password, String token) {
String id = JWT.ownerId(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ ResponseEntity<ApiResponse<WashInfoDto>> myWash(@RequestHeader("Authorization")
return ApiResponse.toResponseEntity(MemberBusinessCode.SUCCESS_FIND_WASH_INFO_IN_MEMBER, washInfoDto);
}


@DeleteMapping("/member")
ResponseEntity<ApiResponse<Void>> memberDelete(@RequestHeader("Authorization") String authToken) {
memberService.deleteMemberByToken(authToken);

return ApiResponse.toResponseEntity(MemberBusinessCode.SUCCESS_REQUEST_DELETE_MEMBER);
}


@PostMapping("/member")
ResponseEntity<ApiResponse<String>> changePassword(@RequestBody String password, @RequestHeader("Authorization") String authToken) {
memberService.changePassword(password, authToken);
Expand All @@ -68,7 +66,6 @@ boolean validatePassword(@RequestBody PasswordDto password, @RequestHeader("Auth
return memberService.validatePassword(password.password(), authToken);
}


@PatchMapping("/member")
<T> ResponseEntity<ApiResponse<T>> updateMember(@RequestBody MemberInfo memberInfo,
@RequestHeader("Authorization") String authToken) {
Expand Down
4 changes: 3 additions & 1 deletion module-api/src/main/resources/db/migration/V1.0.0__init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CREATE TABLE if not exists Auth
created_by varchar NOT NULL,
modified_at date NULL,
modified_by varchar NULL

);


Expand All @@ -39,7 +40,8 @@ CREATE TABLE if not exists Member
created_at DATE NOT NULL,
created_by VARCHAR NOT NULL,
modified_at DATE,
modified_by VARCHAR
modified_by VARCHAR,
account_type varchar
);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ SELECT member_no,
created_at,
created_by,
modified_at,
modified_by
modified_by,
account_type
FROM member;


Expand All @@ -51,10 +52,10 @@ CREATE
RETURNS TRIGGER AS
$$
BEGIN
INSERT INTO member (member_no, id, "password", email, gender, age, created_at, created_by, modified_at, modified_by)
INSERT INTO member (member_no, id, "password", email, gender, age, created_at, created_by, modified_at, modified_by, account_type)
VALUES (nextval('member_member_no_seq'::regclass), NEW.id, pgp_sym_encrypt(NEW.password::TEXT, 'changeRequired'),
pgp_sym_encrypt(NEW.email::TEXT, 'changeRequired'), NEW.gender, NEW.age, NEW.created_at, NEW.created_by,
NEW.modified_at, NEW.modified_by);
NEW.modified_at, NEW.modified_by, NEW.account_type);

RETURN NEW;

Expand Down Expand Up @@ -88,7 +89,8 @@ BEGIN
created_at = NEW.created_at,
created_by = NEW.created_by,
modified_at = NEW.modified_at,
modified_by = NEW.modified_by
modified_by = NEW.modified_by,
account_type = NEW.account_type
WHERE member_no = NEW.member_no;
RETURN NEW;
END;
Expand Down Expand Up @@ -132,4 +134,4 @@ EXECUTE FUNCTION member_view_delete_trigger();


-- 테이블 member 권한 회수 설정
REVOKE INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES ON member FROM wash_admin;
REVOKE INSERT, UPDATE, DELETE, TRUNCATE ON member FROM wash_admin;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kernel360.member.entity;

import com.kernel360.member.enumset.AccountType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -25,7 +26,7 @@ class MemberTest {
gender = 0;
age = 3;

member = Member.of(memberNo, id, email, password, gender, age);
member = Member.of(memberNo, id, email, password, gender, age, AccountType.PLATFORM.name());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.kernel360.auth.service.AuthService;
import com.kernel360.member.dto.MemberDto;
import com.kernel360.member.entity.Member;
import com.kernel360.member.enumset.AccountType;
import com.kernel360.member.repository.MemberRepository;
import com.kernel360.utils.ConvertSHA256;
import com.kernel360.utils.JWT;
Expand Down Expand Up @@ -87,7 +88,7 @@ public void init() {
MemberDto loginDto = MemberDto.of("test03", "1234qwer");
Member mockLoginEntity = Member.loginMember(loginDto.id(), loginDto.password());
Member mockEntity = Member.of(502L, loginDto.id(), "[email protected]",
"0eb9de69892882d54516e03e30098354a2e39cea36adab275b6300c737c942fd", 0, 0);
"0eb9de69892882d54516e03e30098354a2e39cea36adab275b6300c737c942fd", 0, 0, AccountType.PLATFORM.name());
String mockToken = "dummy_token";

/** stub **/
Expand All @@ -111,7 +112,7 @@ public void init() {
void 토큰_발급_저장_테스트() {

/** given **/
Member memberEntity = Member.of(502L, "test03", null, null, 0, 0);
Member memberEntity = Member.of(502L, "test03", null, null, 0, 0, AccountType.PLATFORM.name());
String mockToken = "mockToken";
Auth auth = Auth.jwt(null, 502L, mockToken);
MockHttpServletRequest request = new MockHttpServletRequest();
Expand Down Expand Up @@ -143,7 +144,7 @@ public void init() {

/** given **/
String id = "test01";
Member memberEntity = Member.of(51L, "test01", null, null, 0, 0);
Member memberEntity = Member.of(51L, "test01", null, null, 0, 0, AccountType.PLATFORM.name());

/** stub **/
when(memberRepository.findOneById(anyString())).thenReturn(memberEntity);
Expand Down Expand Up @@ -182,7 +183,7 @@ public void init() {

/** given **/
String email = "[email protected]";
Member memberEntity = Member.of(51L, "test01", "[email protected]", null, 0, 0);
Member memberEntity = Member.of(51L, "test01", "[email protected]", null, 0, 0, AccountType.PLATFORM.name());

/** stub **/
when(memberRepository.findOneByEmail(anyString())).thenReturn(memberEntity);
Expand Down
23 changes: 12 additions & 11 deletions module-domain/src/main/java/com/kernel360/member/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ public class Member extends BaseEntity {
@Column(name = "age")
private int age;

public static Member of(Long memberNo, String id, String email, String password, int gender, int age) {
@Column(name = "account_type")
private String accountType;

return new Member(memberNo, id, email, password, gender, age);
public static Member of(Long memberNo, String id, String email, String password, int gender, int age, String accountType) {

return new Member(memberNo, id, email, password, gender, age, accountType);
}

/**
Expand All @@ -55,33 +58,36 @@ private Member(
String email,
String password,
int gender,
int age
int age,
String accountType
) {
this.memberNo = memberNo;
this.id = id;
this.email = email;
this.password = password;
this.gender = gender;
this.age = age;
this.accountType = accountType;
}

/**
* joinMember
**/
public static Member createJoinMember(String id, String email, String password, int gender, int age) {
public static Member createJoinMember(String id, String email, String password, int gender, int age, String accountType) {

return new Member(id, email, password, gender, age);
return new Member(id, email, password, gender, age, accountType);
}

/**
* joinMember Binding
**/
private Member(String id, String email, String password, int gender, int age) {
private Member(String id, String email, String password, int gender, int age, String accountType) {
this.id = id;
this.email = email;
this.password = password;
this.gender = gender;
this.age = age;
this.accountType = accountType;
}

/**
Expand Down Expand Up @@ -112,11 +118,6 @@ public void updateCarInfo(CarInfo carInfo) {
this.carInfo = carInfo;
}

public static Member createForKakao(String id, String email, String password, int gender, int age) {

return new Member(id, email, password, gender, age);
}

public void updateFromInfo(int gender, int age) {
this.gender = gender;
this.age = age;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class WithdrawMember extends BaseEntity {
private String ip;


public static WithdrawMember of(Long memberNo, String id, String email, String ip) {
public static WithdrawMember of(Member member) {

return new WithdrawMember(memberNo, id, email, ip);
return new WithdrawMember(member.getMemberNo(), member.getId(), member.getEmail(), null); //IP정보를 저장한다면 파라메터를 추가해야
}

private WithdrawMember(
Expand Down

0 comments on commit f350c16

Please sign in to comment.