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: 활동 기수 OM 전환 API 개발 (#74) #79

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 12 additions & 4 deletions src/main/java/cotato/csquiz/controller/AdminController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cotato.csquiz.domain.dto.auth.ApplyMemberInfo;
import cotato.csquiz.domain.dto.member.MemberEnrollInfoResponse;
import cotato.csquiz.domain.dto.member.UpdateActiveMemberRoleRequest;
import cotato.csquiz.domain.dto.member.UpdateActiveMemberToOldMemberRequest;
import cotato.csquiz.domain.dto.member.UpdateOldMemberRoleRequest;
import cotato.csquiz.domain.dto.member.MemberApproveRequest;
import cotato.csquiz.domain.dto.member.MemberRejectRequest;
Expand Down Expand Up @@ -41,21 +42,21 @@ public ResponseEntity<?> rejectApplicantList() {

@PatchMapping("/approve")
public ResponseEntity<?> approveApplicant(@RequestBody MemberApproveRequest memberApproveRequest) {
log.info("가입자 승인 컨트롤러, 요청된 member id : {}", memberApproveRequest.getUserId());
log.info("가입자 승인 컨트롤러, 요청된 member id : {}", memberApproveRequest.getMemberId());
adminService.approveApplicant(memberApproveRequest);
return ResponseEntity.ok().build();
}

@PatchMapping("/reject")
public ResponseEntity<?> rejectApplicant(@RequestBody MemberRejectRequest memberRejectRequest) {
log.info("가입자 거절 컨트롤러, 요청된 member id : {}", memberRejectRequest.getUserId());
log.info("가입자 거절 컨트롤러, 요청된 member id : {}", memberRejectRequest.getMemberId());
adminService.rejectApplicant(memberRejectRequest);
return ResponseEntity.ok().build();
}

@PatchMapping("/reapprove")
public ResponseEntity<?> reapproveApplicant(@RequestBody MemberApproveRequest memberApproveRequest) {
log.info("가입자 재승인 컨트롤러, 요청된 member id : {}", memberApproveRequest.getUserId());
log.info("가입자 재승인 컨트롤러, 요청된 member id : {}", memberApproveRequest.getMemberId());
adminService.reapproveApplicant(memberApproveRequest);
return ResponseEntity.ok().build();
}
Expand All @@ -75,6 +76,13 @@ public ResponseEntity<?> updateActiveMemberRole(
return ResponseEntity.ok().build();
}

@PatchMapping("/active-members/to-old-members")
public ResponseEntity<?> updateActiveMemberToOldMember(
@RequestBody UpdateActiveMemberToOldMemberRequest updateActiveMemberToOldMemberRequest) {
log.info("현재 활동 중인 부원들을 OM으로 업데이트 하는 컨트롤러, 대상 member ids : {}", updateActiveMemberToOldMemberRequest.getMemberIds());
adminService.updateActiveMemberToOldMember(updateActiveMemberToOldMemberRequest.getMemberIds());
return ResponseEntity.ok().build();
}

@GetMapping("/old-members")
public ResponseEntity<List<MemberEnrollInfoResponse>> getOldMembersList() {
Expand All @@ -86,7 +94,7 @@ public ResponseEntity<List<MemberEnrollInfoResponse>> getOldMembersList() {
@PatchMapping("/old-members/role")
public ResponseEntity<?> updateOldMemberToActiveGeneration(
@RequestBody UpdateOldMemberRoleRequest updateOldMemberRoleRequest) {
log.info("OM을 현재 활동 기수로 업데이트하는 컨트롤러, 대상 member id: {}", updateOldMemberRoleRequest.getUserId());
log.info("OM을 현재 활동 기수로 업데이트하는 컨트롤러, 대상 member id: {}", updateOldMemberRoleRequest.getMemberId());
adminService.updateOldMemberToActiveGeneration(updateOldMemberRoleRequest);
return ResponseEntity.ok().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import cotato.csquiz.domain.enums.MemberRole;

public record MemberInfoResponse(
Long id,
String name,
Long memberId,
String memberName,
String backFourNumber,
MemberRole role
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@AllArgsConstructor
public class MemberApproveRequest {

private Long userId;
private Long memberId;
private MemberPosition position;
private Long generationId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
@NoArgsConstructor
public class MemberEnrollInfoResponse {

private Long id;
private String name;
private Long memberId;
private String memberName;
private MemberPosition position;
private int generationNumber;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
@AllArgsConstructor
public class MemberRejectRequest {

private Long userId;
private Long memberId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cotato.csquiz.domain.dto.member;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class UpdateActiveMemberToOldMemberRequest {

private List<Long> memberIds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
@NoArgsConstructor
public class UpdateOldMemberRoleRequest {

private Long userId;
private Long memberId;
}
53 changes: 35 additions & 18 deletions src/main/java/cotato/csquiz/service/AdminService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package cotato.csquiz.service;

import static cotato.csquiz.domain.enums.MemberRole.ADMIN;
import static cotato.csquiz.domain.enums.MemberRole.EDUCATION;
import static cotato.csquiz.domain.enums.MemberRole.GENERAL;
import static cotato.csquiz.domain.enums.MemberRole.MEMBER;
import static cotato.csquiz.domain.enums.MemberRole.OLD_MEMBER;
import static cotato.csquiz.domain.enums.MemberRole.REFUSED;

Expand Down Expand Up @@ -32,7 +36,7 @@ public class AdminService {
private final RefusedMemberRepository refusedMemberRepository;

public List<ApplyMemberInfo> getApplicantList() {
List<Member> applicantList = memberRepository.findAllByRole(MemberRole.GENERAL);
List<Member> applicantList = memberRepository.findAllByRole(GENERAL);
return buildApplyInfoList(applicantList);
}

Expand All @@ -43,11 +47,11 @@ public List<ApplyMemberInfo> getRejectApplicantList() {

@Transactional
public void approveApplicant(MemberApproveRequest memberApproveRequest) {
Member member = findMember(memberApproveRequest.getUserId());
Member member = findMember(memberApproveRequest.getMemberId());
Generation findGeneration = getGeneration(memberApproveRequest.getGenerationId());
validateIsGeneral(member);
if (member.getRole() == MemberRole.GENERAL) {
member.updateRole(MemberRole.MEMBER);
if (member.getRole() == GENERAL) {
member.updateRole(MEMBER);
member.updateGeneration(findGeneration);
member.updatePosition(memberApproveRequest.getPosition());
memberRepository.save(member);
Expand All @@ -56,10 +60,10 @@ public void approveApplicant(MemberApproveRequest memberApproveRequest) {

@Transactional
public void reapproveApplicant(MemberApproveRequest memberApproveRequest) {
Member member = findMember(memberApproveRequest.getUserId());
Member member = findMember(memberApproveRequest.getMemberId());
if (member.getRole() == REFUSED) {
Generation findGeneration = getGeneration(memberApproveRequest.getGenerationId());
member.updateRole(MemberRole.MEMBER);
member.updateRole(MEMBER);
member.updateGeneration(findGeneration);
member.updatePosition(memberApproveRequest.getPosition());
deleteRefusedMember(member);
Expand All @@ -68,22 +72,22 @@ public void reapproveApplicant(MemberApproveRequest memberApproveRequest) {

@Transactional
public void rejectApplicant(MemberRejectRequest memberRejectRequest) {
Member member = findMember(memberRejectRequest.getUserId());
Member member = findMember(memberRejectRequest.getMemberId());
validateIsGeneral(member);
if (member.getRole() == MemberRole.GENERAL) {
if (member.getRole() == GENERAL) {
member.updateRole(REFUSED);
memberRepository.save(member);
addRefusedMember(member);
}
}

private Member findMember(Long userId) {
return memberRepository.findById(userId)
private Member findMember(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new AppException(ErrorCode.MEMBER_NOT_FOUND));
}

private void validateIsGeneral(Member member) {
if (member.getRole() != MemberRole.GENERAL) {
if (member.getRole() != GENERAL) {
throw new AppException(ErrorCode.ROLE_IS_NOT_MATCH);
}
}
Expand All @@ -105,25 +109,39 @@ public void updateActiveMemberRole(UpdateActiveMemberRoleRequest updateActiveMem
memberRepository.save(member);
}

@Transactional
public void updateActiveMemberToOldMember(List<Long> memberIds){
for (Long memberId : memberIds) {
Member member = findMember(memberId);
if (member.getRole() == MEMBER || member.getRole() == ADMIN || member.getRole() == EDUCATION ) {
member.updateRole(OLD_MEMBER);
memberRepository.save(member);
}
else {
throw new AppException(ErrorCode.ROLE_IS_NOT_MATCH);
}
}
}

public List<MemberEnrollInfoResponse> getOldMembersList() {
List<Member> oldMembers = memberRepository.findAllByRole(MemberRole.OLD_MEMBER);
List<Member> oldMembers = memberRepository.findAllByRole(OLD_MEMBER);
return oldMembers.stream()
.map(MemberEnrollInfoResponse::from)
.toList();
}

@Transactional
public void updateOldMemberToActiveGeneration(UpdateOldMemberRoleRequest updateOldMemberRoleRequest) {
Member member = findMember(updateOldMemberRoleRequest.getUserId());
Member member = findMember(updateOldMemberRoleRequest.getMemberId());
validateIsOldMember(member);
if (member.getRole() == MemberRole.OLD_MEMBER) {
member.updateRole(MemberRole.MEMBER);
if (member.getRole() == OLD_MEMBER) {
member.updateRole(MEMBER);
memberRepository.save(member);
}
}

private void validateIsOldMember(Member member) {
if (member.getRole() != MemberRole.OLD_MEMBER) {
if (member.getRole() != OLD_MEMBER) {
throw new AppException(ErrorCode.ROLE_IS_NOT_OLD_MEMBER);
}
}
Expand Down Expand Up @@ -151,5 +169,4 @@ private static List<ApplyMemberInfo> buildApplyInfoList(List<Member> applicantLi
.map(ApplyMemberInfo::from)
.toList();
}
}

}
Loading