Skip to content

Commit

Permalink
Revert "[refactor/#179] SignUp 개편 및 관련 코드 수정"
Browse files Browse the repository at this point in the history
This reverts commit 8fa85f1.
  • Loading branch information
whitem4rk authored Dec 17, 2023
1 parent 8fa85f1 commit 12f8c7d
Show file tree
Hide file tree
Showing 94 changed files with 2,521 additions and 1,851 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.inhabas.api.auth.domain.exception.InvalidUserInfoException;
import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member;
import com.inhabas.api.auth.domain.oauth2.socialAccount.SocialAccountService;
import com.inhabas.api.auth.domain.oauth2.socialAccount.type.UID;
import com.inhabas.api.auth.domain.oauth2.userAuthorityProvider.UserAuthorityProvider;
import com.inhabas.api.auth.domain.oauth2.userInfo.OAuth2UserInfo;
Expand All @@ -24,6 +25,7 @@
@RequiredArgsConstructor
public class CustomOAuth2UserService extends DefaultOAuth2UserService {

private final SocialAccountService socialAccountService;
private final UserAuthorityProvider userAuthorityProvider;
private final MemberService memberService;
private final MemberRepository memberRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,12 @@ public Member(String name, String email, Role role) {
this.email = new Email(email);
this.ibasInformation = new IbasInformation(role);
}

public String getStudentId() {
return this.studentId != null ? this.studentId.getValue() : null;
}

public String getName() {
return this.name != null ? this.name.getValue() : null;
return this.name.getValue();
}

public String getPhone() {
return this.phone != null ? this.phone.getValue() : null;
}
public SchoolInformation getSchoolInformation() {
return this.schoolInformation != null ? this.schoolInformation : null;
return this.phone.getValue();
}

public String getEmail() {
Expand All @@ -128,21 +120,10 @@ public void setName(String name) {
this.name = new Name(name);
}

public void setStudentId(String studentId) {
this.studentId = new StudentId(studentId);
}
public void setPhone(String phone) {
this.phone = new Phone(phone);
}

public void setEmail(String email) {
this.email = new Email(email);
}

public void setSchoolInformation(SchoolInformation schoolInformation) {
this.schoolInformation = schoolInformation;
}

public void setRole(Role role) {
this.ibasInformation.setRole(role);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role;
import com.inhabas.api.auth.domain.oauth2.member.dto.ApprovedMemberManagementDto;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId;
import com.inhabas.api.auth.domain.oauth2.member.dto.ContactDto;
import com.inhabas.api.auth.domain.oauth2.member.dto.NotApprovedMemberManagementDto;
import com.inhabas.api.auth.domain.oauth2.member.dto.ApprovedMemberManagementDto;
import com.inhabas.api.auth.domain.oauth2.userInfo.OAuth2UserInfo;
import org.springframework.data.domain.Pageable;

Expand All @@ -16,6 +17,8 @@ public interface MemberService {
// 가입 관련
void save(Member member);

Member findById(StudentId studentId);

Optional<Member> updateMember(Member member);

void changeRole(Member member, Role role);
Expand All @@ -28,7 +31,7 @@ public interface MemberService {

List<ApprovedMemberManagementDto> getApprovedMembersBySearchAndRole(String search);

void updateUnapprovedMembers(List<Long> memberIdList, String state);
void updateUnapprovedMembers(List<Integer> memberIdList, String state);

void updateApprovedMembers(List<Long> memberIdList, Role role);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member;
import com.inhabas.api.auth.domain.oauth2.member.domain.exception.DuplicatedMemberFieldException;
import com.inhabas.api.auth.domain.oauth2.member.domain.exception.MemberNotFoundException;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role;
import com.inhabas.api.auth.domain.oauth2.member.dto.ApprovedMemberManagementDto;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId;
import com.inhabas.api.auth.domain.oauth2.member.dto.ContactDto;
import com.inhabas.api.auth.domain.oauth2.member.dto.NotApprovedMemberManagementDto;
import com.inhabas.api.auth.domain.oauth2.member.dto.ApprovedMemberManagementDto;
import com.inhabas.api.auth.domain.oauth2.member.repository.MemberRepository;
import com.inhabas.api.auth.domain.oauth2.socialAccount.type.UID;
import com.inhabas.api.auth.domain.oauth2.userInfo.OAuth2UserInfo;
Expand Down Expand Up @@ -50,6 +52,14 @@ public void save(Member member) {
memberRepository.save(member);
}


@Override
@Transactional(readOnly = true)
public Member findById(StudentId studentId) {
return memberRepository.findByStudentId(studentId)
.orElseThrow(MemberNotFoundException::new);
}

@Override
@Transactional
public Optional<Member> updateMember(Member member) {
Expand Down Expand Up @@ -86,7 +96,7 @@ public List<NotApprovedMemberManagementDto> getNotApprovedMembersBySearchAndRole
.map(member -> new NotApprovedMemberManagementDto(
member.getName(),
member.getId(),
member.getStudentId(),
member.getStudentId().getValue(),
member.getPhone(),
member.getEmail(),
member.getSchoolInformation().getGrade(),
Expand All @@ -106,7 +116,7 @@ public List<ApprovedMemberManagementDto> getApprovedMembersBySearchAndRole(Strin
.map(member -> new ApprovedMemberManagementDto(
member.getName(),
member.getId(),
member.getStudentId(),
member.getStudentId().getValue(),
member.getPhone(),
member.getRole(),
member.getSchoolInformation().getGeneration(),
Expand All @@ -117,9 +127,13 @@ public List<ApprovedMemberManagementDto> getApprovedMembersBySearchAndRole(Strin

@Override
@Transactional
public void updateUnapprovedMembers(List<Long> memberIdList, String state) {
public void updateUnapprovedMembers(List<Integer> memberIdList, String state) {

List<Member> members = memberRepository.findAllById(memberIdList);
List<Long> memberLongList = memberIdList.stream()
.map(Long::valueOf)
.collect(Collectors.toList());

List<Member> members = memberRepository.findAllById(memberLongList);
boolean allNewMembers = members.stream().allMatch(
member -> DEFAULT_ROLE_AFTER_FINISH_SIGNUP.equals(member.getRole()));

Expand All @@ -128,6 +142,7 @@ public void updateUnapprovedMembers(List<Long> memberIdList, String state) {
}

if (state.equals(PASS_STATE)) {

for (Member member : members)
member.setRole(DEACTIVATED);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ boolean validate(Object value) {
if (Objects.isNull(value)) return true;
if (!(value instanceof Integer)) return false;
int o = (Integer) value;
return 0 <= o && o <= 5; // 1학년부터 5학년(초과학기)까지 가능, 0학년은 학생이 아닐때
return 1 <= o && o <= 5; // 1학년부터 5학년(초과학기)까지 가능, 0학년은 학생이 아닐때
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public SchoolInformation(String major, Integer generation, MemberType memberType
this.major = new Major(major);
this.generation = new Generation(generation);
this.memberType = memberType;
this.grade = new Grade(DEFAULT_GRADE);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@AllArgsConstructor
public class UpdateRequestDto {

private List<Long> memberIdList;
private List<Integer> memberIdList;

@Schema(example = "pass, fail")
private String state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
public interface MemberRepository extends JpaRepository<Member, Long>, MemberRepositoryCustom {

List<Member> findAllById(Iterable<Long> memberIdList);

Member getByStudentId(StudentId studentId);

Optional<Member> findByStudentId(StudentId studentId);

Member findByIbasInformation_Role(Role role);


// OAuth
boolean existsByProviderAndUid(OAuth2Provider provider, UID uid);
Optional<Member> findByProviderAndUid(OAuth2Provider provider, UID uid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId;
import com.inhabas.api.auth.domain.oauth2.member.dto.MemberDuplicationQueryCondition;
import com.inhabas.api.auth.domain.oauth2.member.security.MemberAuthorityProvider;

Expand All @@ -10,7 +11,7 @@

public interface MemberRepositoryCustom {

MemberAuthorityProvider.RoleDto fetchRoleByStudentId(Long id);
MemberAuthorityProvider.RoleDto fetchRoleByStudentId(StudentId studentId);

boolean isDuplicated(MemberDuplicationQueryCondition condition);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.inhabas.api.auth.domain.oauth2.OAuth2Provider;
import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId;
import com.inhabas.api.auth.domain.oauth2.member.dto.MemberDuplicationQueryCondition;
import com.inhabas.api.auth.domain.oauth2.member.security.MemberAuthorityProvider;
import com.inhabas.api.auth.domain.oauth2.socialAccount.type.UID;
Expand All @@ -28,10 +29,10 @@ public class MemberRepositoryImpl implements MemberRepositoryCustom {
private final JPAQueryFactory queryFactory;

@Override
public MemberAuthorityProvider.RoleDto fetchRoleByStudentId(Long id) {
public MemberAuthorityProvider.RoleDto fetchRoleByStudentId(StudentId studentId) {
Role role = queryFactory
.select(member.ibasInformation.role).from(member)
.where(member.id.eq(id))
.where(member.studentId.eq(studentId))
.fetchOne();

return new MemberAuthorityProvider.RoleDto(role);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

import com.inhabas.api.auth.domain.exception.InvalidUserInfoException;
import com.inhabas.api.auth.domain.oauth2.member.domain.entity.Member;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId;
import com.inhabas.api.auth.domain.oauth2.member.repository.MemberRepository;
import com.inhabas.api.auth.domain.oauth2.socialAccount.type.UID;
import com.inhabas.api.auth.domain.oauth2.userAuthorityProvider.UserAuthorityProvider;
import com.inhabas.api.auth.domain.oauth2.userInfo.OAuth2UserInfo;
import com.inhabas.api.auth.domain.oauth2.userInfo.OAuth2UserInfoAuthentication;
import com.inhabas.api.auth.domain.token.securityFilter.UserPrincipalService;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
import java.util.*;

import static com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role.SIGNING_UP;

Expand All @@ -34,9 +33,9 @@ public Collection<SimpleGrantedAuthority> determineAuthorities(OAuth2UserInfo oA

OAuth2UserInfoAuthentication authentication =
new OAuth2UserInfoAuthentication(oAuth2UserInfo.getId(), oAuth2UserInfo.getProvider().toString(), oAuth2UserInfo.getEmail());
Long memberId = (Long) userPrincipalService.loadUserPrincipal(authentication);
StudentId studentId = (StudentId) userPrincipalService.loadUserPrincipal(authentication);

if (Objects.isNull(memberId)) { // 기존회원이 아니면, member 테이블에 임시데이터 저장
if (Objects.isNull(studentId)) { // 기존회원이 아니면, member 테이블에 임시데이터 저장
Member member = memberRepository.findByProviderAndUid(
oAuth2UserInfo.getProvider(), new UID(oAuth2UserInfo.getId()))
.orElseThrow(InvalidUserInfoException::new);
Expand All @@ -47,7 +46,7 @@ public Collection<SimpleGrantedAuthority> determineAuthorities(OAuth2UserInfo oA
}
else {
// 기존회원이면,
RoleDto roleDto = memberRepository.fetchRoleByStudentId(memberId);
RoleDto roleDto = memberRepository.fetchRoleByStudentId(studentId);

if (roleDto.isEmpty())
throw new InvalidUserInfoException(); // 가입된 소셜 계정으로 회원 프로필을 찾을 수 없는 경우.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import com.inhabas.api.auth.domain.oauth2.OAuth2Provider;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Email;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId;
import com.inhabas.api.auth.domain.oauth2.member.security.socialAccount.MemberSocialAccount;
import com.inhabas.api.auth.domain.oauth2.member.security.socialAccount.MemberSocialAccountRepository;
import com.inhabas.api.auth.domain.oauth2.socialAccount.type.UID;
import com.inhabas.api.auth.domain.oauth2.userInfo.OAuth2UserInfoAuthentication;
import com.inhabas.api.auth.domain.token.securityFilter.UserPrincipalNotFoundException;
import com.inhabas.api.auth.domain.token.securityFilter.UserPrincipalService;
import com.inhabas.api.auth.domain.oauth2.member.security.socialAccount.MemberSocialAccountRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
Expand Down Expand Up @@ -42,23 +43,23 @@ public Object loadUserPrincipal(Authentication authentication) {
Email email = new Email(oauth2UserInfoToken.getEmail());

try {
Long memberId = this.getMemberId(provider, uid, email).orElseThrow(UserPrincipalNotFoundException::new);
return memberId;
StudentId studentId = this.getMemberId(provider, uid, email).orElseThrow(UserPrincipalNotFoundException::new);
return studentId;
} catch (UserPrincipalNotFoundException e) {
log.info(e.getMessage());
return null;
}
}


private Optional<Long> getMemberId(OAuth2Provider provider, UID uid, Email email) {
private Optional<StudentId> getMemberId(OAuth2Provider provider, UID uid, Email email) {

return memberSocialAccountRepository.findMemberIdByUidAndProvider(uid, provider)
.or(() -> this.findByEmailAndProviderForLegacy(email, provider, uid));
}


private Optional<Long> findByEmailAndProviderForLegacy(Email email, OAuth2Provider provider, UID uid) {
private Optional<StudentId> findByEmailAndProviderForLegacy(Email email, OAuth2Provider provider, UID uid) {

Optional<MemberSocialAccount> memberSocialAccount =
memberSocialAccountRepository.findMemberSocialAccountByEmailAndProvider(email, provider);
Expand All @@ -68,7 +69,7 @@ private Optional<Long> findByEmailAndProviderForLegacy(Email email, OAuth2Provid
MemberSocialAccount socialAccount = memberSocialAccount.get();
socialAccount.SetUID(uid);
memberSocialAccountRepository.save(socialAccount);
return Optional.of(socialAccount.getMember().getId());
return Optional.of(socialAccount.getMember().getStudentId());

} else {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -17,8 +16,6 @@ public ObjectMapper objectMapper() {
module.addSerializer(String.class, new StringPropertyMasker());
objectMapper.registerModule(module);

objectMapper.registerModule(new JavaTimeModule());

return objectMapper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class MemberSocialAccount {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer id;

@OneToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "USER_ID")
Expand Down Expand Up @@ -48,7 +48,7 @@ public MemberSocialAccount(Member member, String email, String uid, OAuth2Provid
this.provider = provider;
}

public Long getId() {
public Integer getId() {
return this.id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.Optional;

public interface MemberSocialAccountRepository
extends JpaRepository<MemberSocialAccount, Long>, MemberSocialAccountRepositoryCustom {
extends JpaRepository<MemberSocialAccount, Integer>, MemberSocialAccountRepositoryCustom {

/**
* 레거시 호환성을 위해 존재. "회원가입 되어있지만 uid가 존재하지 않는 경우"에만 사용할 것.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.inhabas.api.auth.domain.oauth2.member.security.socialAccount;

import com.inhabas.api.auth.domain.oauth2.OAuth2Provider;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId;
import com.inhabas.api.auth.domain.oauth2.socialAccount.type.UID;

import java.util.Optional;

public interface MemberSocialAccountRepositoryCustom {

Optional<Long> findMemberIdByUidAndProvider(UID uid, OAuth2Provider provider);
Optional<StudentId> findMemberIdByUidAndProvider(UID uid, OAuth2Provider provider);
}
Loading

0 comments on commit 12f8c7d

Please sign in to comment.