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/#105 #110

Merged
merged 8 commits into from
Sep 4, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public AuthUseCase(MemberRepository memberRepository,
public CompletableFuture<ResponseData<LoginRes>> login(LoginReq req) {
Member member = memberRepository.getById(req.id());
member.checkIfPasswordIsCorrect(Sha512PasswordEncoder.encode(req.pw()));
member.checkIfStatusIsDeactivate();
member.checkIfStatusIncorrect();
return CompletableFuture.supplyAsync(() -> member, executor)
.thenCompose(m -> tokenClient.issueTokens(member.getId(), member.getRole().getNumber()))
.thenApply(tokens -> new LoginRes(member, tokens.accessToken(), tokens.refreshToken()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers(GET, "/member/my").authenticated()
.requestMatchers(GET, "/member/check/broadcast-club-member").hasAnyRole(STUDENT, ADMIN)
.requestMatchers(GET, "/member/**").hasAnyRole(TEACHER, ADMIN)
.requestMatchers(PATCH, "/member/student/info/**").hasAnyRole(TEACHER, ADMIN)
.requestMatchers(PATCH, "/member/teacher/info/**").hasAnyRole(TEACHER, ADMIN)
.requestMatchers(PATCH, "/member/status/**").hasRole(ADMIN)
.requestMatchers(PATCH, "/member/active/**").hasRole(ADMIN)
.requestMatchers(PATCH, "/member/deactivate").authenticated()
.requestMatchers(PATCH, "/member/deactivate/**").hasRole(ADMIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ public Response delete(String id) {
return Response.noContent("멤버 삭제 성공");
}

@CacheEvict(value = "members-cache", key = "'activeMembers'")
public Response status(String id, ActiveStatus status) {
Copy link
Member

Choose a reason for hiding this comment

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

updateStatus 같이 동사를 추가해서 네이밍해주세요

Copy link
Member Author

Choose a reason for hiding this comment

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

현재 updateStatus메서드를 사용하는 기존 메서드가 있어서 임시로 네이밍을 해뒀습니다
웹에서 변경사항에 맞춰 수정하면 기존메서드를 삭제하고 메서드 명도 updateStatus로 변경할 예정입니다.

Member member = memberRepository.getById(id);
member.updateStatus(status);
return Response.ok("멤버 상태변경 성공");
}

@CacheEvict(value = "members-cache", key = "'activeMembers'")
public Response active(String id) {
updateStatus(id, ActiveStatus.ACTIVE);
Expand All @@ -98,7 +105,7 @@ public Response deactivate(String id) {
@CacheEvict(value = "members-cache", key = "'activeMembers'")
public Response deactivate() {
Member member = memberAuthenticationHolder.current();
member.updateStatus(ActiveStatus.DEACTIVATE);
member.updateStatus(ActiveStatus.DEACTIVATED);
memberRepository.save(member);
return Response.ok("멤버 비활성화 성공");
}
Expand Down Expand Up @@ -130,22 +137,16 @@ public Response updateStudentInfo(UpdateStudentInfoReq req) {
return Response.noContent("내 학생 정보 수정 성공");
}

@CacheEvict(value = "members-cache", key = "'activeMembers'")
public Response updateStudentParentPhone(String id, UpdateStudentForAdminReq req){
Member current = memberAuthenticationHolder.current();
if (!(current.getRole() == MemberRole.TEACHER || current.getRole() == MemberRole.ADMIN)){
throw new UnauthorizedException();
}
Member member = memberRepository.getById(id);
Student student = studentRepository.getByMember(member);
student.updateParentPhone(req.parentPhone());
return Response.noContent("학생 정보 수정 성공");
}

@CacheEvict(value = "members-cache", key = "'activeMembers'")
public Response updateTeacherForAdmin(String id, UpdateTeacherForAdminReq req){
Member current = memberAuthenticationHolder.current();
if (!(current.getRole() == MemberRole.TEACHER)){
throw new UnauthorizedException();
}
Member member = memberRepository.getById(id);
Teacher teacher = teacherRepository.getByMember(member);
teacher.updateInfo(req.tel(), req.position());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,27 @@ public ResponseData<List<MemberInfoRes>> searchByName(String name) {
.toList());
}

public ResponseData<List<MemberInfoRes>> getMembersByStatus(ActiveStatus status) {
return ResponseData.ok("상태변 멤버 조회 성공", memberRepository.findByStatusOrderByStudent(status)
.parallelStream()
.map(this::getMemberInfo)
.toList());
}

public ResponseData<List<MemberInfoRes>> getDeactivateMembers() {
return ResponseData.ok("비활성화된 멤버 조회 성공", memberRepository.findByStatusOrderByStudent(ActiveStatus.DEACTIVATE)
.parallelStream()
.map(this::getMemberInfo)
.toList());
}

public ResponseData<List<MemberInfoRes>> getPendingMembers(){
return ResponseData.ok("대기중인 멤버 조회 성공", memberRepository.findByStatusOrderByStudent(ActiveStatus.PENDING)
.parallelStream()
.map(this::getMemberInfo)
.toList());
}

@Cacheable(value = "members-cache", key = "'activeMembers'")
public List<MemberInfoRes> getAll() {
return memberRepository.findByStatusOrderByStudent(ActiveStatus.ACTIVE).parallelStream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Member mapToMember(String encodedPw) {
.name(name)
.role(MemberRole.STUDENT)
.phone(phone)
.status(ActiveStatus.DEACTIVATE)
.status(ActiveStatus.PENDING)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Member mapToMember(String encodedPw) {
.name(name)
.role(MemberRole.TEACHER)
.phone(phone)
.status(ActiveStatus.DEACTIVATE)
.status(ActiveStatus.PENDING)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package b1nd.dodam.restapi.member.presentation;

import b1nd.dodam.domain.rds.member.enumeration.ActiveStatus;
import b1nd.dodam.restapi.member.application.MemberCommandUseCase;
import b1nd.dodam.restapi.member.application.MemberQueryUseCase;
import b1nd.dodam.restapi.member.application.data.req.*;
Expand Down Expand Up @@ -40,6 +41,11 @@ public Response delete(@PathVariable String id) {
return commandUseCase.delete(id);
}

@PatchMapping("/status/{id}")
public Response updateStatus(@PathVariable String id, @RequestParam ActiveStatus status){
return commandUseCase.status(id, status);
}

@PatchMapping("/active/{id}")
public Response active(@PathVariable("id") String id) {
return commandUseCase.active(id);
Expand Down Expand Up @@ -95,11 +101,21 @@ public ResponseData<List<MemberInfoRes>> searchByName(@RequestParam String name)
return queryUseCase.searchByName(name);
}

@GetMapping("/status")
public ResponseData<List<MemberInfoRes>> getMembersByStatus(@RequestParam ActiveStatus status) {
return queryUseCase.getMembersByStatus(status);
}

@GetMapping("/deactivate")
public ResponseData<List<MemberInfoRes>> getDeactivateMembers() {
return queryUseCase.getDeactivateMembers();
}

@GetMapping("/pending")
public ResponseData<List<MemberInfoRes>> getPendingMembers(){
return queryUseCase.getPendingMembers();
}

@GetMapping("/all")
public ResponseData<List<MemberInfoRes>> getAll() {
return ResponseData.ok("모든 멤버 정보 조회 성공", queryUseCase.getAll());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import b1nd.dodam.domain.rds.member.enumeration.ActiveStatus;
import b1nd.dodam.domain.rds.member.enumeration.MemberRole;
import b1nd.dodam.domain.rds.member.exception.ActiveMemberException;
import b1nd.dodam.domain.rds.member.exception.DeactivateMemberException;
import b1nd.dodam.domain.rds.member.exception.WrongPasswordException;
import b1nd.dodam.domain.rds.member.exception.*;
import b1nd.dodam.domain.rds.support.entity.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.Entity;
Expand Down Expand Up @@ -80,18 +78,6 @@ public void updateInfo(String name, String email, String phone, String profileIm
}
}

public void updateInfoForAdmin(String pw, String name, String phone){
if(StringUtils.isNotBlank(pw)){
this.pw = pw;
}
if(StringUtils.isNotBlank(name)){
this.name = name;
}
if(StringUtils.isNotBlank(phone)){
this.phone = phone;
}
}

public void updateStatus(ActiveStatus status) {
this.status = status;
}
Expand All @@ -108,9 +94,9 @@ public void checkIfStatusIsActive() {
}
}

public void checkIfStatusIsDeactivate() {
if(this.status == ActiveStatus.DEACTIVATE) {
throw new DeactivateMemberException();
public void checkIfStatusIncorrect() {
if(!(this.status == ActiveStatus.ACTIVE)) {
throw new MemberNotActiveException();
}
}

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

public enum ActiveStatus {

ACTIVE, DEACTIVATE
ACTIVE, DEACTIVATE, PENDING, DEACTIVATED

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
public enum MemberExceptionCode implements ExceptionCode {

WRONG_PASSWORD(401, "잘못된 비밀번호"),
DEACTIVATE_MEMBER(403, "비활성화된 멤버"),
MEMBER_NOT_ACTIVE(403, "활성화되지 않은 멤버"),
ACTIVE_MEMBER(403, "활성화된 멤버"),
MEMBER_NOT_FOUND(404, "없는 멤버"),
STUDENT_NOT_FOUND(404, "없는 학생"),
PARENT_NOT_FOUND(404, "없는 부모님 정보"),
TEACHER_NOT_FOUND(404, "없는 선생님"),
MEMBER_DUPLICATION(409, "이미 존재하는 멤버"),
BROADCAST_CLUB_MEMBER_DUPLICATION(409, "이미 존재하는 방송부원"),
UNAUTHORIZED(403, "권한 없음");
BROADCAST_CLUB_MEMBER_DUPLICATION(409, "이미 존재하는 방송부원");

private final int status;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package b1nd.dodam.domain.rds.member.exception;

import b1nd.dodam.core.exception.CustomException;

public class MemberNotActiveException extends CustomException {

public MemberNotActiveException() {
super(MemberExceptionCode.MEMBER_NOT_ACTIVE);
}
}

This file was deleted.