Skip to content

Commit

Permalink
✨ [FEATURE] 판매자 회원가입 승인 요청 처리 및 조회 서비스
Browse files Browse the repository at this point in the history
✨ [FEATURE] 판매자 회원가입 승인 요청 처리 및 조회 서비스
  • Loading branch information
gomin0 authored Jul 20, 2024
2 parents 41046e8 + f2c0c97 commit 3020197
Show file tree
Hide file tree
Showing 13 changed files with 361 additions and 6 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ java {
}
}

compileJava {
options.compilerArgs << '-parameters'
}

configurations {
compileOnly {
extendsFrom annotationProcessor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package umc.unimade.domain.accounts.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;
import umc.unimade.domain.accounts.dto.SellerRegisterResponse;
import umc.unimade.domain.accounts.dto.SellerRegistersResponse;
import umc.unimade.domain.accounts.service.SellerRegisterQueryService;
import umc.unimade.domain.accounts.dto.AdminSellerRegisterRequest;
import umc.unimade.domain.accounts.dto.AdminSellerRegisterResponse;
import umc.unimade.domain.accounts.service.SellerRegisterCommandService;
import umc.unimade.global.common.ApiResponse;
import umc.unimade.global.registerStatus.RegisterStatus;

@RequiredArgsConstructor
@Tag(name = "Admin", description = "관리자 관련 API")
@RequestMapping("/admin")
@RestController
public class AdminController { // TODO: 필터체인에 /admin으로 접근시 ROlE이 ADMIN인지 확인 넣기

private final SellerRegisterCommandService sellerRegisterCommandService;
private final SellerRegisterQueryService sellerRegisterQueryService;

@Operation(summary = "판매자의 회원가입 요청 승인", description = "유저 role이 관리자인 사람만 가능, 요청 상태가 PENDING or HOLD인 것만 승인 가능")
@PostMapping("/{sellerRegisterId}/approve")
public ApiResponse<AdminSellerRegisterResponse> approveSeller(@PathVariable(name = "sellerRegisterId") Long sellerRegisterId) {
return ApiResponse.onSuccess(sellerRegisterCommandService.approveSeller(sellerRegisterId, RegisterStatus.ACCEPTED));
}

@Operation(summary = "판매자의 회원가입 요청 거절", description = "유저 role이 관리자인 사람만 가능, 요청 상태가 PENDING인 것만 거절 가능")
@PostMapping("/{sellerRegisterId}/reject")
public ApiResponse<AdminSellerRegisterResponse> rejectSeller(@PathVariable(name = "sellerRegisterId") Long sellerRegisterId,
@RequestBody AdminSellerRegisterRequest request) {
return ApiResponse.onSuccess(sellerRegisterCommandService.rejectOrHoldSeller(sellerRegisterId, RegisterStatus.REJECTED, request));
}

@Operation(summary = "판매자의 회원가입 요청 보류", description = "유저 role이 관리자인 사람만 가능, 요청 상태가 PENDING인 것만 보류 가능")
@PostMapping("/{sellerRegisterId}/hold")
public ApiResponse<AdminSellerRegisterResponse> holdSeller(@PathVariable(name = "sellerRegisterId") Long sellerRegisterId,
@RequestBody AdminSellerRegisterRequest request) {
return ApiResponse.onSuccess(sellerRegisterCommandService.rejectOrHoldSeller(sellerRegisterId, RegisterStatus.HOLD, request));
}

@Operation(summary = "전체 판매자의 회원가입 요청 목록 조회",
description = "유저 role이 관리자인 사람만 가능, 상태값 파라미터로 아무것도 안넣으면 전체 조회, 상태값에 따라 조회도 가능")
@GetMapping("/sellers")
public ApiResponse<Page<SellerRegistersResponse>> getSellersRegisters(
@RequestParam(name = "page", defaultValue = "0") int page,
@RequestParam(name = "size", defaultValue = "10") int size,
@RequestParam(name = "status", required = false) RegisterStatus status) {
Pageable pageable = PageRequest.of(page, size);
Page<SellerRegistersResponse> responses = sellerRegisterQueryService.getSellersRegisters(pageable, status);
return ApiResponse.onSuccess(responses);
}

@Operation(summary = "판매자의 회원가입 요청 개별 조회", description = "요청한 판매자의 정보 조회")
@GetMapping("{sellerRegisterId}")
public ApiResponse<SellerRegisterResponse> getSellerRegister(@PathVariable(name = "sellerRegisterId") Long sellerRegisterId) {
SellerRegisterResponse sellerRegister = sellerRegisterQueryService.getSellerRegister(sellerRegisterId);
return ApiResponse.onSuccess(sellerRegister);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package umc.unimade.domain.accounts.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class AdminSellerRegisterRequest {

@Schema(description = "사유", example = "이상한데요")
private String reason;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package umc.unimade.domain.accounts.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.unimade.domain.accounts.entity.Seller;
import umc.unimade.domain.accounts.entity.SellerRegister;
import umc.unimade.global.registerStatus.RegisterStatus;

import java.time.LocalDateTime;

@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AdminSellerRegisterResponse {

private Long sellerRegisterId;
private Long sellerId;
private RegisterStatus status;
private String reason;
private LocalDateTime createdAt;

public static AdminSellerRegisterResponse of(SellerRegister sellerRegister, Seller seller) {
return AdminSellerRegisterResponse.builder()
.sellerRegisterId(sellerRegister.getId())
.sellerId(seller.getId())
.status(sellerRegister.getRegisterStatus())
.createdAt(LocalDateTime.now())
.build();
}

public static AdminSellerRegisterResponse of(SellerRegister sellerRegister) {
return AdminSellerRegisterResponse.builder()
.sellerRegisterId(sellerRegister.getId())
.status(sellerRegister.getRegisterStatus())
.reason(sellerRegister.getReason())
.createdAt(LocalDateTime.now())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package umc.unimade.domain.accounts.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.unimade.domain.accounts.entity.Gender;
import umc.unimade.domain.accounts.entity.Provider;
import umc.unimade.domain.accounts.entity.SellerRegister;
import umc.unimade.global.registerStatus.RegisterStatus;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SellerRegisterResponse {

private Long id;
private String name;
private String email;
private String password;
private Gender gender;
private String phone;
private String profileImage;
private Provider provider;
private RegisterStatus registerStatus;
private String reason;

public static SellerRegisterResponse from(SellerRegister sellerRegister) {
return SellerRegisterResponse.builder()
.id(sellerRegister.getId())
.name(sellerRegister.getName())
.email(sellerRegister.getEmail())
.password(sellerRegister.getPassword())
.gender(sellerRegister.getGender())
.phone(sellerRegister.getPhone())
.profileImage(sellerRegister.getProfileImage())
.provider(sellerRegister.getProvider())
.registerStatus(sellerRegister.getRegisterStatus())
.reason(sellerRegister.getReason())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package umc.unimade.domain.accounts.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.unimade.domain.accounts.entity.SellerRegister;
import umc.unimade.global.registerStatus.RegisterStatus;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SellerRegistersResponse {

private Long sellerRegisterId;
private String name;
private RegisterStatus status;

public static SellerRegistersResponse from(SellerRegister sellerRegister) {
return SellerRegistersResponse.builder()
.sellerRegisterId(sellerRegister.getId())
.name(sellerRegister.getName())
.status(sellerRegister.getRegisterStatus())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,19 @@ public class SellerRegister {
@Column(name = "registerStatus", nullable = false)
private RegisterStatus registerStatus;

@Column(name = "reason")
private String reason; // 거부 or 보류 사유

@PostPersist
private void setRegisterStatus() {
registerStatus = RegisterStatus.PENDING;
}

public void changeStatus(RegisterStatus registerStatus) {
this.registerStatus = registerStatus;
}

public void setReason(String reason) {
this.reason = reason;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package umc.unimade.domain.accounts.exception;

import umc.unimade.global.common.BaseErrorCode;
import umc.unimade.global.common.exception.CustomException;

public class BuyerExceptionHandler extends CustomException {
public BuyerExceptionHandler(BaseErrorCode errorCode) {
super(errorCode);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package umc.unimade.domain.accounts.exception;

import umc.unimade.global.common.BaseErrorCode;
import umc.unimade.global.common.exception.CustomException;

public class SellerExceptionHandler extends CustomException {
public SellerExceptionHandler(BaseErrorCode errorCode) {
super(errorCode);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package umc.unimade.domain.accounts.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import umc.unimade.domain.accounts.entity.SellerRegister;
import umc.unimade.global.registerStatus.RegisterStatus;

public interface SellerRegisterRepository extends JpaRepository<SellerRegister, Long> {
Page<SellerRegister> findByRegisterStatus(RegisterStatus status, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package umc.unimade.domain.accounts.service;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import umc.unimade.domain.accounts.dto.AdminSellerRegisterRequest;
import umc.unimade.domain.accounts.dto.AdminSellerRegisterResponse;
import umc.unimade.domain.accounts.entity.Seller;
import umc.unimade.domain.accounts.entity.SellerRegister;
import umc.unimade.domain.accounts.exception.SellerExceptionHandler;
import umc.unimade.domain.accounts.repository.SellerRegisterRepository;
import umc.unimade.domain.accounts.repository.SellerRepository;
import umc.unimade.global.common.ErrorCode;
import umc.unimade.global.registerStatus.RegisterStatus;

@RequiredArgsConstructor
@Transactional
@Service
public class SellerRegisterCommandService {

private final SellerRegisterRepository sellerRegisterRepository;
private final SellerRepository sellerRepository;

public AdminSellerRegisterResponse approveSeller(Long sellerRegisterId, RegisterStatus registerStatus) {

SellerRegister sellerRegister = sellerRegisterRepository.findById(sellerRegisterId)
.orElseThrow(() -> new SellerExceptionHandler(ErrorCode.SELLER_NOT_FOUND));

if (!sellerRegister.getRegisterStatus().equals(RegisterStatus.PENDING) &&
!sellerRegister.getRegisterStatus().equals(RegisterStatus.HOLD)) {
throw new SellerExceptionHandler(ErrorCode.STATUS_IS_NOT_PENDING_OR_HOLD);
}

Seller seller = convertToSeller(sellerRegister);
sellerRepository.save(seller);

sellerRegister.changeStatus(registerStatus);

return AdminSellerRegisterResponse.of(sellerRegister, seller);
}

public AdminSellerRegisterResponse rejectOrHoldSeller(Long sellerRegisterId, RegisterStatus registerStatus, AdminSellerRegisterRequest request) {

SellerRegister sellerRegister = sellerRegisterRepository.findById(sellerRegisterId)
.orElseThrow(() -> new SellerExceptionHandler(ErrorCode.SELLER_NOT_FOUND));

if (!sellerRegister.getRegisterStatus().equals(RegisterStatus.PENDING)) {
throw new SellerExceptionHandler(ErrorCode.STATUS_IS_NOT_PENDING);
}

sellerRegister.changeStatus(registerStatus);
sellerRegister.setReason(request.getReason());

return AdminSellerRegisterResponse.of(sellerRegister);
}

// TODO: sellerRequest 로 옮기기
private Seller convertToSeller(SellerRegister sellerRegister) {
return Seller.builder()
.name(sellerRegister.getName())
.email(sellerRegister.getEmail())
.password(sellerRegister.getPassword())
.gender(sellerRegister.getGender())
.phone(sellerRegister.getPhone())
.profileImage(sellerRegister.getProfileImage())
.provider(sellerRegister.getProvider())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package umc.unimade.domain.accounts.service;


import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import umc.unimade.domain.accounts.dto.SellerRegisterResponse;
import umc.unimade.domain.accounts.dto.SellerRegistersResponse;
import umc.unimade.domain.accounts.entity.SellerRegister;
import umc.unimade.domain.accounts.exception.SellerExceptionHandler;
import umc.unimade.domain.accounts.repository.SellerRegisterRepository;
import umc.unimade.global.common.ErrorCode;
import umc.unimade.global.registerStatus.RegisterStatus;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class SellerRegisterQueryService {

private final SellerRegisterRepository sellerRegisterRepository;

public Page<SellerRegistersResponse> getSellersRegisters(Pageable pageable, RegisterStatus status) {

Page<SellerRegister> sellerRegisters;

if (status == null) {
sellerRegisters = sellerRegisterRepository.findAll(pageable);
} else {
sellerRegisters = sellerRegisterRepository.findByRegisterStatus(status, pageable);
}
return sellerRegisters.map(SellerRegistersResponse::from);
}

public SellerRegisterResponse getSellerRegister(Long sellerRegisterId) {

SellerRegister sellerRegister = sellerRegisterRepository.findById(sellerRegisterId)
.orElseThrow(() -> new SellerExceptionHandler(ErrorCode.SELLER_NOT_FOUND));

return SellerRegisterResponse.from(sellerRegister);
}
}
Loading

0 comments on commit 3020197

Please sign in to comment.