-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [FEATURE] 판매자 회원가입 승인 요청 처리 및 조회 서비스
✨ [FEATURE] 판매자 회원가입 승인 요청 처리 및 조회 서비스
- Loading branch information
Showing
13 changed files
with
361 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/umc/unimade/domain/accounts/controller/AdminController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/umc/unimade/domain/accounts/dto/AdminSellerRegisterRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/umc/unimade/domain/accounts/dto/AdminSellerRegisterResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/umc/unimade/domain/accounts/dto/SellerRegisterResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/umc/unimade/domain/accounts/dto/SellerRegistersResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/umc/unimade/domain/accounts/exception/BuyerExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/umc/unimade/domain/accounts/exception/SellerExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/umc/unimade/domain/accounts/repository/SellerRegisterRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/umc/unimade/domain/accounts/service/SellerRegisterCommandService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/umc/unimade/domain/accounts/service/SellerRegisterQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.