Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#170 관리자 관련 api 구현 #185

Merged
merged 18 commits into from
Sep 11, 2024
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
473e43b
feat: 관리자 계정들의 id 자동 생성되도록 수정
llddang Aug 29, 2024
c7e3e94
feat: super admin 어노테이션 구현
llddang Aug 29, 2024
2b61b0c
feat: 관리자 계정의 어노테이션 구현
llddang Aug 29, 2024
e4148fe
feat: 관리자 단일 등록 api 구현
llddang Aug 29, 2024
a88af17
feat: Admin & SuperAdmin annotation 등록
llddang Sep 4, 2024
3f8f58f
feat: config 폴더 최신화
llddang Sep 4, 2024
4b56650
feat: 파일을 이용한 교직원 등록 api 구현
llddang Sep 4, 2024
6f061b2
feat: 교직원 탈퇴 api 구현
llddang Sep 6, 2024
1c93a56
feat: 로그인 할 때 deleted 된 사용자인지 검증하는 로직 추가
llddang Sep 6, 2024
31d470e
feat: 이메일 및 전화번호 중복확인 api 삭제
llddang Sep 6, 2024
0a1625e
feat: 회원가입 및 이메일 인증시 탈퇴한 회원인지 확인하는 로직 추가
llddang Sep 6, 2024
d3ba960
feat: 로그인 관련 회원을 찾지 못할 때의 문구 수정
llddang Sep 6, 2024
ca78cc0
feat: 교직원 단일/다중 등록 시 deleted 된 회원인지 검증하는 로직 추가
llddang Sep 6, 2024
dac1bfd
refactor: 관리자 등록 및 삭제 api의 컨트롤러 명 수정
llddang Sep 6, 2024
098a488
refactor: 관리자 권한 관련 컨트롤러 명 수정
llddang Sep 7, 2024
67f3b00
feat: 관리자 등록/삭제 관련 api test 코드 작성 및 rest docs 작성
llddang Sep 7, 2024
e62b873
refactor: 코드리뷰 반영
llddang Sep 11, 2024
9428736
refactor: 코드리뷰 반영
llddang Sep 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: 회원가입 및 이메일 인증시 탈퇴한 회원인지 확인하는 로직 추가
llddang committed Sep 6, 2024
commit 0a1625ed2e6348dbc513824cee329934db33de7b
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@
import sw_css.auth.domain.repository.EmailAuthRedisRepository;
import sw_css.auth.exception.AuthException;
import sw_css.auth.exception.AuthExceptionType;
import sw_css.member.domain.Member;
import sw_css.member.domain.repository.MemberRepository;
import sw_css.utils.MailUtil;

@Service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

레파지토리에 접근하는 모든 서비스에는 @Transactional을 붙여주는 것이 좋습니다!

@@ -23,6 +25,7 @@ public class AuthEmailService {
private final MailUtil mailUtil;
private final EmailAuthRedisRepository emailAuthRedisRepository;
private final AuthCheckDuplicateService authCheckDuplicateService;
private final MemberRepository memberRepository;

public SendAuthCodeResponse emailAuth(String email) {
checkIsDuplicateEmail(email);
@@ -59,8 +62,10 @@ private void sendAuthCode(String email, String authCode) {
}

private void checkIsDuplicateEmail(String email) {
if (authCheckDuplicateService.isDuplicateEmail(email)) {
throw new AuthException(AuthExceptionType.MEMBER_EMAIL_DUPLICATE);
Member member = memberRepository.findByEmail(email).orElse(null);
if (member == null || member.isDeleted()) {
return;
}
throw new AuthException(AuthExceptionType.MEMBER_EMAIL_DUPLICATE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JPA에는 엔티티 조회 시 특정 조건에 해당되는 엔티티만 조회되도록 필터링하도록 설정할 수 있는 기능이 있습니다!
관련 글
이렇게 일일이 isDeleted()를 검증해주지 않아도 됩니당

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그리고 그렇게 고친다면 아래처럼 로직을 수정하면 좋을 것 같아용

if(member!= null){
    throw new AuthException(AuthExceptionType.MEMBER_EMAIL_DUPLICATE);
}

}
}
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@
import sw_css.auth.exception.AuthExceptionType;
import sw_css.major.domain.Major;
import sw_css.major.domain.repository.MajorRepository;
import sw_css.member.domain.CareerType;
import sw_css.member.domain.Member;
import sw_css.member.domain.StudentMember;
import sw_css.member.domain.repository.MemberRepository;
import sw_css.member.domain.repository.StudentMemberRepository;
@@ -27,11 +29,19 @@ public class AuthSignUpService {
private final EmailAuthRedisRepository emailAuthRedisRepository;

public long signUp(SignUpRequest request) {
Member member = memberRepository.findByEmail(request.email()).orElse(null);
if (member != null) {
if (!member.isDeleted()) {
throw new AuthException(AuthExceptionType.MEMBER_EMAIL_DUPLICATE);
}

return saveExistMember(request, member);
}

checkIsDuplicateEmail(request.email());
checkIsDuplicateStudentId(request.student_id());

String actualAuthCode = loadActualAuthCode(request.email());
checkAuthCodeMatch(request.auth_code(), actualAuthCode);
checkIsValidAuthCode(request.email(), request.auth_code());

Major major = majorRepository.findById(request.major_id())
.orElseThrow(() -> new AuthException(AuthExceptionType.MAJOR_NOT_EXIST));
@@ -53,6 +63,40 @@ public CheckDuplicateResponse isDuplicateStudentId(String studentId) {
return CheckDuplicateResponse.from(authCheckDuplicateService.isDuplicateStudentID(studentId));
}

private long saveExistMember(SignUpRequest request, Member oldMember) {
checkIsValidAuthCode(request.email(), request.auth_code());

Major major = majorRepository.findById(request.major_id())
.orElseThrow(() -> new AuthException(AuthExceptionType.MAJOR_NOT_EXIST));
Major minor = request.minor_id() == null ? null : majorRepository.findById(request.minor_id())
.orElseThrow(() -> new AuthException(AuthExceptionType.MAJOR_NOT_EXIST));
Major doubleMinor =
request.double_major_id() == null ? null : majorRepository.findById(request.double_major_id())
.orElseThrow(() -> new AuthException(AuthExceptionType.MAJOR_NOT_EXIST));

Member newMember = request.toMember();
newMember.setId(oldMember.getId());
memberRepository.save(newMember);

StudentMember oldStudentMember = studentMemberRepository.findByMemberId(newMember.getId()).orElse(null);
if (oldStudentMember == null) {
final StudentMember newStudentMember = request.toStudentMember(newMember.getId(), major, minor,
doubleMinor);
studentMemberRepository.save(newStudentMember);
} else {
final CareerType careerType = CareerType.valueOf(request.career());

oldStudentMember.setMajor(major);
oldStudentMember.setMinor(minor);
oldStudentMember.setDoubleMajor(doubleMinor);
oldStudentMember.setCareer(careerType);
oldStudentMember.setCareerDetail(request.career_detail());
studentMemberRepository.save(oldStudentMember);
}

return newMember.getId();
}

private void checkIsDuplicateEmail(String email) {
if (authCheckDuplicateService.isDuplicateEmail(email)) {
throw new AuthException(AuthExceptionType.MEMBER_EMAIL_DUPLICATE);
@@ -65,12 +109,6 @@ private void checkIsDuplicateStudentId(String studentId) {
}
}

private void checkIsDuplicatePhoneNumber(String phoneNumber) {
if (authCheckDuplicateService.isDuplicatePhoneNumber(phoneNumber)) {
throw new AuthException(AuthExceptionType.MEMBER_PHONE_NUMBER_DUPLICATE);
}
}

private void checkAuthCodeMatch(String requestAuthCode, String actualAuthCode) {
if (!actualAuthCode.equals(requestAuthCode)) {
throw new AuthException(AuthExceptionType.AUTH_CODE_MISMATCH);
@@ -82,4 +120,9 @@ private String loadActualAuthCode(@Email String email) {
.orElseThrow(() -> new AuthException(AuthExceptionType.AUTH_CODE_EXPIRED))
.getAuthCode();
}

private void checkIsValidAuthCode(String email, String authCode) {
String actualAuthCode = loadActualAuthCode(email);
checkAuthCodeMatch(authCode, actualAuthCode);
}
}
2 changes: 2 additions & 0 deletions backend/src/main/java/sw_css/member/domain/StudentMember.java
Original file line number Diff line number Diff line change
@@ -12,10 +12,12 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import sw_css.base.BaseEntity;
import sw_css.major.domain.Major;

@Entity
@Setter(AccessLevel.PUBLIC)
@Getter
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Original file line number Diff line number Diff line change
@@ -7,7 +7,5 @@
public interface MemberRepository extends JpaRepository<Member, Long> {
boolean existsByEmail(String email);

boolean existsByPhoneNumber(String phoneNumber);

Optional<Member> findByEmail(String email);
}