Skip to content

Commit

Permalink
Feature: 사장님 인증 요청 상세 내용 조회 API 개발
Browse files Browse the repository at this point in the history
Feature: 사장님 인증 요청 상세 내용 조회 API 개발
  • Loading branch information
YongsHub authored Aug 14, 2024
2 parents d618169 + ac13af6 commit f893d05
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import jakarta.validation.Valid;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -16,6 +16,7 @@
import com.cakk.api.dto.request.shop.PromotionRequest;
import com.cakk.api.dto.response.shop.CakeShopCreateResponse;
import com.cakk.api.dto.response.shop.CakeShopOwnerCandidateResponse;
import com.cakk.api.dto.response.shop.CakeShopOwnerCandidatesResponse;
import com.cakk.api.service.shop.ShopService;
import com.cakk.common.response.ApiResponse;

Expand All @@ -27,12 +28,20 @@ public class AdminController {
private final ShopService shopService;

@GetMapping("/shops/candidates")
public ApiResponse<CakeShopOwnerCandidateResponse> getBusinessOwnerCandidates() {
final CakeShopOwnerCandidateResponse response = shopService.getBusinessOwnerCandidates();
public ApiResponse<CakeShopOwnerCandidatesResponse> getBusinessOwnerCandidates() {
final CakeShopOwnerCandidatesResponse response = shopService.getBusinessOwnerCandidates();

return ApiResponse.success(response);
}

@GetMapping("/shops/candidates/{userId}")
public ApiResponse<CakeShopOwnerCandidateResponse> getCandidateSpecificationInformation(@PathVariable Long userId) {
final CakeShopOwnerCandidateResponse response = shopService.getCandidateInformation(userId);

return ApiResponse.success(response);
}


@PostMapping("/shops/create")
public ApiResponse<CakeShopCreateResponse> createByAdmin(
@Valid @RequestBody CreateShopRequest createShopRequest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.cakk.api.dto.response.shop;

import java.util.List;

import com.cakk.api.dto.param.operation.OwnerCandidateParam;
import lombok.Builder;

@Builder
public record CakeShopOwnerCandidateResponse(
List<OwnerCandidateParam> candidates
Long userId,
Long cakeShopId,
String email,
String businessRegistrationImageUrl,
String idCardImageUrl,
String emergencyContact
) {
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.cakk.api.dto.response.shop;

import java.util.List;

import com.cakk.api.dto.param.operation.OwnerCandidateParam;

public record CakeShopOwnerCandidatesResponse(
List<OwnerCandidateParam> candidates
) {
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

import com.cakk.api.dto.param.operation.OwnerCandidateParam;
import com.cakk.api.dto.response.shop.CakeShopOwnerCandidateResponse;
import com.cakk.api.dto.response.shop.CakeShopOwnerCandidatesResponse;
import com.cakk.domain.mysql.entity.user.BusinessInformation;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class BusinessInformationMapper {

public static CakeShopOwnerCandidateResponse supplyCakeShopOwnerCandidateResponseBy(
public static CakeShopOwnerCandidatesResponse supplyCakeShopOwnerCandidatesResponseBy(
List<BusinessInformation> businessInformations
) {
List<OwnerCandidateParam> candidates = businessInformations
Expand All @@ -27,7 +28,20 @@ public static CakeShopOwnerCandidateResponse supplyCakeShopOwnerCandidateRespons
.build())
.toList();

return new CakeShopOwnerCandidateResponse(candidates);
return new CakeShopOwnerCandidatesResponse(candidates);
}

public static CakeShopOwnerCandidateResponse supplyCakeShopOwnerCandidateResponseBy(
BusinessInformation businessInformation
) {
return CakeShopOwnerCandidateResponse.builder()
.userId(businessInformation.getUser().getId())
.cakeShopId(businessInformation.getCakeShop().getId())
.email(businessInformation.getUser().getEmail())
.businessRegistrationImageUrl(businessInformation.getBusinessRegistrationImageUrl())
.idCardImageUrl(businessInformation.getIdCardImageUrl())
.emergencyContact(businessInformation.getEmergencyContact())
.build();
}
}

12 changes: 10 additions & 2 deletions cakk-api/src/main/java/com/cakk/api/service/shop/ShopService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.cakk.api.dto.response.shop.CakeShopDetailResponse;
import com.cakk.api.dto.response.shop.CakeShopInfoResponse;
import com.cakk.api.dto.response.shop.CakeShopOwnerCandidateResponse;
import com.cakk.api.dto.response.shop.CakeShopOwnerCandidatesResponse;
import com.cakk.api.dto.response.shop.CakeShopOwnerResponse;
import com.cakk.api.dto.response.shop.CakeShopSearchResponse;
import com.cakk.api.dto.response.shop.CakeShopSimpleResponse;
Expand Down Expand Up @@ -210,14 +211,21 @@ public CakeShopOwnerResponse isExistBusinessInformation(final User owner, final
}

@Transactional(readOnly = true)
public CakeShopOwnerCandidateResponse getBusinessOwnerCandidates() {
public CakeShopOwnerCandidatesResponse getBusinessOwnerCandidates() {
List<BusinessInformation> businessInformations = businessInformationReader.findAllCakeShopBusinessOwnerCandidates();

businessInformations = businessInformations
.stream()
.filter(businessInformation -> businessInformation.isBusinessOwnerCandidate(verificationPolicy))
.toList();

return BusinessInformationMapper.supplyCakeShopOwnerCandidateResponseBy(businessInformations);
return BusinessInformationMapper.supplyCakeShopOwnerCandidatesResponseBy(businessInformations);
}

@Transactional(readOnly = true)
public CakeShopOwnerCandidateResponse getCandidateInformation(final Long userId) {
BusinessInformation businessInformation = businessInformationReader.findByUserId(userId);

return BusinessInformationMapper.supplyCakeShopOwnerCandidateResponseBy(businessInformation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.cakk.api.dto.request.shop.PromotionRequest;
import com.cakk.api.dto.response.shop.CakeShopCreateResponse;
import com.cakk.api.dto.response.shop.CakeShopOwnerCandidateResponse;
import com.cakk.api.dto.response.shop.CakeShopOwnerCandidatesResponse;
import com.cakk.common.enums.ReturnCode;
import com.cakk.common.response.ApiResponse;

Expand Down Expand Up @@ -72,8 +73,8 @@ void backOfficeSearchByCakeShopBusinessOwnerCandidates() {

// then
final ApiResponse response = objectMapper.convertValue(responseEntity.getBody(), ApiResponse.class);
final CakeShopOwnerCandidateResponse data = objectMapper.convertValue(response.getData(),
CakeShopOwnerCandidateResponse.class);
final CakeShopOwnerCandidatesResponse data = objectMapper.convertValue(response.getData(),
CakeShopOwnerCandidatesResponse.class);

assertEquals(HttpStatusCode.valueOf(200), responseEntity.getStatusCode());
assertEquals(ReturnCode.SUCCESS.getCode(), response.getReturnCode());
Expand Down Expand Up @@ -108,5 +109,34 @@ void backOfficeCakeShopBusinessOwnerApproved() {
assertEquals(ReturnCode.SUCCESS.getCode(), response.getReturnCode());
assertEquals(ReturnCode.SUCCESS.getMessage(), response.getReturnMessage());
}

@TestWithDisplayName("백 오피스 API, 케이크샵 사장님 인증 요청 상세 내용 조회에 성공한다")
void backOfficeSearchByCakeShopBusinessOwnerCandidate() {
//given
final Long userId = 1L;
final String url = "%s%d%s/shops/candidates/{userId}".formatted(BASE_URL, port, API_URL);
final UriComponents uriComponents = UriComponentsBuilder
.fromUriString(url)
.buildAndExpand(userId);

// when
final ResponseEntity<ApiResponse> responseEntity = restTemplate.getForEntity(uriComponents.toUriString(), ApiResponse.class);

// then
final ApiResponse response = objectMapper.convertValue(responseEntity.getBody(), ApiResponse.class);
final CakeShopOwnerCandidateResponse data = objectMapper.convertValue(response.getData(),
CakeShopOwnerCandidateResponse.class);

assertEquals(HttpStatusCode.valueOf(200), responseEntity.getStatusCode());
assertEquals(ReturnCode.SUCCESS.getCode(), response.getReturnCode());
assertEquals(ReturnCode.SUCCESS.getMessage(), response.getReturnMessage());

assertEquals(1L, data.userId().longValue());
assertEquals(1L, data.cakeShopId().longValue());
assertEquals("test1@google.com", data.email());
assertEquals("https://business_registration_image_url1", data.businessRegistrationImageUrl());
assertEquals("https://id_card_image_url1", data.idCardImageUrl());
assertEquals("010-0000-0000", data.emergencyContact());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ public interface BusinessInformationJpaRepository extends JpaRepository<Business
@Query("select bi from BusinessInformation as bi join fetch bi.user join fetch bi.cakeShop"
+ " where bi.verificationStatus =:verificationStatus")
List<BusinessInformation> findAllCakeShopBusinessOwnerCandidates(VerificationStatus verificationStatus);

@Query("select bi from BusinessInformation as bi join fetch bi.user join fetch bi.cakeShop"
+ " where bi.user.id =:userId")
Optional<BusinessInformation> findBusinessInformationByUserId(final Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import lombok.RequiredArgsConstructor;

import com.cakk.common.enums.ReturnCode;
import com.cakk.common.enums.VerificationStatus;
import com.cakk.common.exception.CakkException;
import com.cakk.domain.mysql.annotation.Reader;
import com.cakk.domain.mysql.entity.user.BusinessInformation;
import com.cakk.domain.mysql.entity.user.User;
Expand All @@ -27,4 +29,9 @@ public List<BusinessInformation> findAllWithCakeShopByUser(final User owner) {
public List<BusinessInformation> findAllCakeShopBusinessOwnerCandidates() {
return businessInformationJpaRepository.findAllCakeShopBusinessOwnerCandidates(VerificationStatus.PENDING);
}

public BusinessInformation findByUserId(final Long userId) {
return businessInformationJpaRepository.findBusinessInformationByUserId(userId)
.orElseThrow(() -> new CakkException(ReturnCode.NOT_EXIST_CAKE_SHOP));
}
}

0 comments on commit f893d05

Please sign in to comment.