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

feat: 어드민 멤버 가입신청 승인하기 api 구현 #63

Merged
merged 10 commits into from
Feb 12, 2024
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.gdschongik.gdsc.domain.member.api;

import com.gdschongik.gdsc.domain.member.application.MemberService;
import com.gdschongik.gdsc.domain.member.dto.request.MemberGrantRequest;
import com.gdschongik.gdsc.domain.member.dto.request.MemberQueryRequest;
import com.gdschongik.gdsc.domain.member.dto.request.MemberUpdateRequest;
import com.gdschongik.gdsc.domain.member.dto.response.MemberFindAllResponse;
import com.gdschongik.gdsc.domain.member.dto.response.MemberGrantResponse;
import com.gdschongik.gdsc.domain.member.dto.response.MemberPendingFindAllResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -56,4 +58,11 @@ public ResponseEntity<Void> updateMember(
memberService.updateMember(memberId, request);
return ResponseEntity.ok().build();
}

@Operation(summary = "회원 승인", description = "회원의 가입을 승인합니다.")
@PutMapping("/grant")
public ResponseEntity<MemberGrantResponse> grantMember(@Valid @RequestBody MemberGrantRequest request) {
MemberGrantResponse response = memberService.grantMember(request);
return ResponseEntity.ok().body(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
import com.gdschongik.gdsc.domain.member.dao.MemberRepository;
import com.gdschongik.gdsc.domain.member.domain.Member;
import com.gdschongik.gdsc.domain.member.domain.MemberRole;
import com.gdschongik.gdsc.domain.member.dto.request.MemberGrantRequest;
import com.gdschongik.gdsc.domain.member.dto.request.MemberQueryRequest;
import com.gdschongik.gdsc.domain.member.dto.request.MemberUpdateRequest;
import com.gdschongik.gdsc.domain.member.dto.response.MemberFindAllResponse;
import com.gdschongik.gdsc.domain.member.dto.response.MemberGrantResponse;
import com.gdschongik.gdsc.domain.member.dto.response.MemberPendingFindAllResponse;
import com.gdschongik.gdsc.global.exception.CustomException;
import com.gdschongik.gdsc.global.exception.ErrorCode;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -46,4 +50,20 @@ public Page<MemberPendingFindAllResponse> findAllPendingMembers(Pageable pageabl
Page<Member> members = memberRepository.findAllByRole(MemberRole.GUEST, pageable);
return members.map(MemberPendingFindAllResponse::of);
}

@Transactional
public MemberGrantResponse grantMember(MemberGrantRequest request) {
List<Member> verifiedMembers = getVerifiedMembers(request);
verifiedMembers.forEach(Member::grant);
return MemberGrantResponse.of(verifiedMembers);
}

private List<Member> getVerifiedMembers(MemberGrantRequest request) {
List<Long> memberIdList = request.memberIdList();
return memberIdList.stream()
.map(memberRepository::findVerifiedById)
.filter(Optional::isPresent)
.map(Optional::get)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public interface MemberCustomRepository {
Page<Member> findAll(MemberQueryRequest queryRequest, Pageable pageable);

Optional<Member> findNormalByOauthId(String oauthId);

Optional<Member> findVerifiedById(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.gdschongik.gdsc.domain.member.domain.Member;
import com.gdschongik.gdsc.domain.member.domain.MemberStatus;
import com.gdschongik.gdsc.domain.member.domain.RequirementStatus;
import com.gdschongik.gdsc.domain.member.dto.request.MemberQueryRequest;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.dsl.BooleanExpression;
Expand Down Expand Up @@ -44,6 +45,34 @@ public Optional<Member> findNormalByOauthId(String oauthId) {
.fetchOne());
}

@Override
public Optional<Member> findVerifiedById(Long id) {
return Optional.ofNullable(queryFactory
.selectFrom(member)
.where(eqId(id), requirementVerified())
.fetchOne());
}

private BooleanBuilder requirementVerified() {
return new BooleanBuilder().and(discordVerified()).and(univVerified()).and(paymentVerified());
}

private BooleanExpression discordVerified() {
return member.requirement.discordStatus.eq(RequirementStatus.VERIFIED);
}

private BooleanExpression univVerified() {
return member.requirement.univStatus.eq(RequirementStatus.VERIFIED);
}

private BooleanExpression paymentVerified() {
return member.requirement.paymentStatus.eq(RequirementStatus.VERIFIED);
}

private BooleanExpression eqId(Long id) {
return member.id.eq(id);
}

private BooleanExpression eqOauthId(String oauthId) {
return member.oauthId.eq(oauthId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,8 @@ private void validateStatusUpdatable() {
throw new CustomException(MEMBER_FORBIDDEN);
}
}

public void grant() {
this.role = MemberRole.USER;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.gdschongik.gdsc.domain.member.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;

public record MemberGrantRequest(@Schema(description = "승인할 멤버 ID 리스트") List<Long> memberIdList) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.gdschongik.gdsc.domain.member.dto.response;

import com.gdschongik.gdsc.domain.member.domain.Member;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;

public record MemberGrantResponse(@Schema(description = "승인에 성공한 멤버 ID 리스트") List<Long> grantedMembers) {
public static MemberGrantResponse of(List<Member> grantedMembers) {
List<Long> grantedMemberIdList =
grantedMembers.stream().map(Member::getId).toList();
return new MemberGrantResponse(grantedMemberIdList);
}
}
Loading