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

Refactor: 케이크 샵 인증 요청 로직 개선 #189

Merged
merged 13 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cakk.api.dto.request.user;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

import com.cakk.domain.mysql.dto.param.user.CertificationParam;
import com.cakk.domain.mysql.entity.user.User;
Expand All @@ -10,6 +11,7 @@ public record CertificationRequest(
String businessRegistrationImageUrl,
@NotBlank
String idCardImageUrl,
@NotNull
Long cakeShopId,
@NotBlank
String emergencyContact,
Expand Down
6 changes: 0 additions & 6 deletions cakk-api/src/main/java/com/cakk/api/mapper/ShopMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ public static BusinessInformation supplyBusinessInformationBy(final CreateShopRe
.build();
}

public static BusinessInformation supplyBusinessInformationBy() {
return BusinessInformation.builder()
.cakeShop(CakeShop.builder().build())
.build();
}

public static List<CakeShopOperation> supplyCakeShopOperationsBy(
final CakeShop cakeShop,
final List<ShopOperationParam> operationDays
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,10 @@ public CakeShopByMineResponse getMyBusinessId(final User user) {

@Transactional(readOnly = true)
public void requestCertificationBusinessOwner(final CertificationParam param) {
BusinessInformation businessInformation;
final BusinessInformation businessInformation = cakeShopReader.findBusinessInformationByCakeShopId(param.cakeShopId());
final CertificationEvent certificationEvent = verificationPolicy
.requestCertificationBusinessOwner(businessInformation, param);

if (nonNull(param.cakeShopId())) {
businessInformation = cakeShopReader.findBusinessInformationByCakeShopId(param.cakeShopId());
} else {
businessInformation = ShopMapper.supplyBusinessInformationBy();
}

final CertificationEvent certificationEvent = businessInformation.getRequestCertificationMessage(param);
publisher.publishEvent(certificationEvent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Set;
import java.util.stream.Collectors;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
Expand All @@ -27,14 +26,12 @@
import com.cakk.api.dto.param.operation.ShopOperationParam;
import com.cakk.api.dto.request.link.UpdateLinkRequest;
import com.cakk.api.dto.request.operation.UpdateShopOperationRequest;
import com.cakk.api.dto.request.shop.CreateShopRequest;
import com.cakk.api.dto.request.shop.UpdateShopAddressRequest;
import com.cakk.api.dto.request.shop.UpdateShopRequest;
import com.cakk.api.dto.request.user.CertificationRequest;
import com.cakk.api.dto.response.like.HeartResponse;
import com.cakk.api.dto.response.shop.CakeShopByMapResponse;
import com.cakk.api.dto.response.shop.CakeShopByMineResponse;
import com.cakk.api.dto.response.shop.CakeShopCreateResponse;
import com.cakk.api.dto.response.shop.CakeShopDetailResponse;
import com.cakk.api.dto.response.shop.CakeShopInfoResponse;
import com.cakk.api.dto.response.shop.CakeShopOwnerResponse;
Expand Down Expand Up @@ -244,31 +241,6 @@ void detail2() {
assertEquals(ReturnCode.NOT_EXIST_CAKE_SHOP.getMessage(), response.getReturnMessage());
}

@TestWithDisplayName("로그인한 사용자는 자신의 케이크샵이 존재하지 않은 상태에서 사장님 인증을 요청한다")
void request1() {
final String url = "%s%d%s".formatted(BASE_URL, port, API_URL);
final UriComponents uriComponents = UriComponentsBuilder
.fromUriString(url)
.path("/certification")
.build();
CertificationRequest request = getConstructorMonkey().giveMeBuilder(CertificationRequest.class)
.set("businessRegistrationImageUrl", Arbitraries.strings().withCharRange('a', 'z').ofMaxLength(40).ofMinLength(1))
.set("idCardImageUrl", Arbitraries.strings().withCharRange('a', 'z').ofMaxLength(40).ofMinLength(1))
.setNull("cakeShopId")
.set("emergencyContact", Arbitraries.strings().withCharRange('a', 'z').ofMaxLength(11).ofMinLength(1))
.set("message", Arbitraries.strings().withCharRange('a', 'z').ofMaxLength(20)).sample();

HttpEntity<CertificationRequest> entity = new HttpEntity<>(request, getAuthHeader());

final ResponseEntity<ApiResponse> responseEntity = restTemplate.postForEntity(uriComponents.toUriString(), entity,
ApiResponse.class);
final ApiResponse response = objectMapper.convertValue(responseEntity.getBody(), ApiResponse.class);

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

@TestWithDisplayName("로그인한 사용자는 자신의 케이크샵이 존재하는 상태에서 사장님 인증을 요청한다")
void request2() {
final String url = "%s%d%s".formatted(BASE_URL, port, API_URL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.cakk.api.mapper.PointMapper;
import com.cakk.api.mapper.ShopMapper;
import com.cakk.common.enums.ReturnCode;
import com.cakk.common.enums.VerificationStatus;
import com.cakk.common.exception.CakkException;
import com.cakk.domain.mysql.bo.user.VerificationPolicy;
import com.cakk.domain.mysql.dto.param.shop.CakeShopDetailParam;
Expand Down Expand Up @@ -109,6 +110,12 @@ private BusinessInformation getBusinessInformationFixture() {
return getConstructorMonkey().giveMeBuilder(BusinessInformation.class)
.set("businessNumber", Arbitraries.strings().withCharRange('a', 'z').ofMaxLength(20))
.set("cakeShop", getCakeShopFixture())
.set("verificationStatus", VerificationStatus.UNREQUESTED)
.sample();
}

private CertificationEvent getCertificationEventFixture() {
return getConstructorMonkey().giveMeBuilder(CertificationEvent.class)
.sample();
}

Expand Down Expand Up @@ -229,8 +236,9 @@ void promoteUser() {
void requestCertificationEventWithInfo() {
//given
CertificationParam param = getCertificationParamFixture(false);
doReturn(getBusinessInformationFixture())
.when(cakeShopReader).findBusinessInformationByCakeShopId(param.cakeShopId());
doReturn(getBusinessInformationFixture()).when(cakeShopReader).findBusinessInformationByCakeShopId(param.cakeShopId());
when(verificationPolicy.requestCertificationBusinessOwner(any(BusinessInformation.class), any(CertificationParam.class)))
.thenReturn(getCertificationEventFixture());

//when
shopService.requestCertificationBusinessOwner(param);
Expand All @@ -240,19 +248,6 @@ void requestCertificationEventWithInfo() {
verify(publisher, times(1)).publishEvent(any(CertificationEvent.class));
}

@TestWithDisplayName("cakeShopId가 존재하지 않는다면, 요청 정보로만 이벤트를 발행한다")
void requestCertificationEventWithParam() {
//given
CertificationParam param = getCertificationParamFixture(true);

//when
shopService.requestCertificationBusinessOwner(param);

//verify
verify(cakeShopReader, times(0)).findBusinessInformationByCakeShopId(any());
verify(publisher, times(1)).publishEvent(any(CertificationEvent.class));
}

@TestWithDisplayName("id로 케이크 샵을 상세정보를 조회한다.")
void searchInfoById1() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ SET @g1 = 'Point(37.197734 127.098190)';
SET @g2 = 'Point(37.201623 127.091568)';
SET @g3 = 'Point(37.209769 127.100107)';

insert into cake_shop (shop_id, thumbnail_url, shop_name, shop_address, shop_bio, shop_description, location, like_count, heart_count, linked_flag,
created_at, updated_at)
values (1, 'thumbnail_url1', '케이크 맛집1', '서울시 강남구 어쩌고로1', '케이크 맛집입니다.', '케이크 맛집입니다.', ST_GeomFromText(@g1, 4326), 0, 0, false, now(), now()),
(2, 'thumbnail_url2', '케이크 맛집2', '서울시 강남구 어쩌고로2', '케이크 맛집입니다.', '케이크 맛집입니다.', ST_GeomFromText(@g2, 4326), 0, 0, false, now(), now()),
(3, 'thumbnail_url3', '케이크 맛집3', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', '케이크 맛집입니다.', ST_GeomFromText(@g3, 4326), 0, 0, false, now(), now());
insert into cake_shop (shop_id, thumbnail_url, shop_name, shop_address, shop_bio, shop_description, location, like_count, heart_count, created_at, updated_at)
values (1, 'thumbnail_url1', '케이크 맛집1', '서울시 강남구 어쩌고로1', '케이크 맛집입니다.', '케이크 맛집입니다.', ST_GeomFromText(@g1, 4326), 0, 0, now(), now()),
(2, 'thumbnail_url2', '케이크 맛집2', '서울시 강남구 어쩌고로2', '케이크 맛집입니다.', '케이크 맛집입니다.', ST_GeomFromText(@g2, 4326), 0, 0, now(), now()),
(3, 'thumbnail_url3', '케이크 맛집3', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', '케이크 맛집입니다.', ST_GeomFromText(@g3, 4326), 0, 0, now(), now());

insert into business_information(business_number, business_registration_image_url, id_card_image_url, emergency_contact, shop_id, user_id)
values ('010-3375-5555', 'https://business_registration_image_url1', 'https://id_card_image_url1', '010-0000-0000', 1, 1),
Expand Down
51 changes: 26 additions & 25 deletions cakk-api/src/test/resources/sql/insert-cake-shop.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ SET @g8 = 'Point(37.541530 127.054164)';
SET @g9 = 'Point(37.543343 127.052609)';
SET @g10 = 'Point(37.541530 127.054164)';

insert into cake_shop (shop_id, thumbnail_url, shop_name, shop_address, shop_bio, shop_description, location, like_count, heart_count, linked_flag,
created_at, updated_at)
values (1, 'thumbnail_url1', '케이크 맛집1', '케이크 맛집입니다.', '서울시 강남구 어쩌고로1', '케이크 맛집입니다.', ST_GeomFromText(@g1, 4326), 0, 0, false, now(), now()),
(2, 'thumbnail_url2', '케이크 맛집2', '케이크 맛집입니다.', '서울시 강남구 어쩌고로2', '케이크 맛집입니다.', ST_GeomFromText(@g2, 4326), 0, 0, false, now(), now()),
(3, 'thumbnail_url3', '케이크 맛집3', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g3, 4326), 0, 0, false, now(), now()),
(4, 'thumbnail_url4', '케이크 맛집4', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g4, 4326), 0, 0, false, now(), now()),
(5, 'thumbnail_url5', '케이크 맛집5', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g5, 4326), 0, 0, false, now(), now()),
(6, 'thumbnail_url6', '케이크 맛집6', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g6, 4326), 0, 0, false, now(), now()),
(7, 'thumbnail_url7', '케이크 맛집7', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g7, 4326), 0, 0, false, now(), now()),
(8, 'thumbnail_url8', '케이크 맛집8', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g8, 4326), 0, 0, false, now(), now()),
(9, 'thumbnail_url9', '케이크 맛집9', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g9, 4326), 0, 0, false, now(), now()),
(10, 'thumbnail_url10', '케이크 맛집10', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g10, 4326), 0, 0, false, now(), now()),
(11, 'thumbnail_url10', '케이크 맛집11', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g10, 4326), 0, 0, false, now(), now());
insert into cake_shop (shop_id, thumbnail_url, shop_name, shop_address, shop_bio, shop_description, location, like_count, heart_count, created_at, updated_at)
values (1, 'thumbnail_url1', '케이크 맛집1', '케이크 맛집입니다.', '서울시 강남구 어쩌고로1', '케이크 맛집입니다.', ST_GeomFromText(@g1, 4326), 0, 0, now(), now()),
(2, 'thumbnail_url2', '케이크 맛집2', '케이크 맛집입니다.', '서울시 강남구 어쩌고로2', '케이크 맛집입니다.', ST_GeomFromText(@g2, 4326), 0, 0, now(), now()),
(3, 'thumbnail_url3', '케이크 맛집3', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g3, 4326), 0, 0, now(), now()),
(4, 'thumbnail_url4', '케이크 맛집4', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g4, 4326), 0, 0, now(), now()),
(5, 'thumbnail_url5', '케이크 맛집5', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g5, 4326), 0, 0, now(), now()),
(6, 'thumbnail_url6', '케이크 맛집6', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g6, 4326), 0, 0, now(), now()),
(7, 'thumbnail_url7', '케이크 맛집7', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g7, 4326), 0, 0, now(), now()),
(8, 'thumbnail_url8', '케이크 맛집8', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g8, 4326), 0, 0, now(), now()),
(9, 'thumbnail_url9', '케이크 맛집9', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g9, 4326), 0, 0, now(), now()),
(10, 'thumbnail_url10', '케이크 맛집10', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g10, 4326), 0, 0, now(), now()),
(11, 'thumbnail_url10', '케이크 맛집11', '케이크 맛집입니다.', '서울시 강남구 어쩌고로3', '케이크 맛집입니다.', ST_GeomFromText(@g10, 4326), 0, 0, now(), now());

insert into cake (cake_id, shop_id, cake_image_url, heart_count, created_at, updated_at)
values (1, 1, 'cake_image_url1', 0, now(), now()),
Expand Down Expand Up @@ -86,15 +85,17 @@ values (1, 1, 'web', 'https://www.cake-shop1.com', now(), now()),
(6, 3, 'web', 'https://www.cake-shop3.com', now(), now()),
(7, 3, 'kakaotalk', 'https://www.kakaotalk.com/cake-shop3', now(), now());

insert into business_information(business_number, shop_id, user_id)
values ('010-3375-5555', 1, 1),
('010-3375-5555', 2, 2),
('010-3375-5555', 3, 3),
('010-3375-5555', 4, 4),
('010-3375-5555', 5, 5),
('010-3375-5555', 6, 6),
('010-3375-5555', 7, 7),
('010-3375-5555', 8, 8),
('010-3375-5555', 9, 9),
('010-3375-5555', 10, 10),
('010-3375-5555', 11, null);
insert into business_information(business_number, business_registration_image_url, id_card_image_url, emergency_contact, shop_id, user_id)
values ('010-3375-5555', NULL, NULL, NULL, 2, 2),
('010-3375-5555', NULL, NULL, NULL, 3, 3),
('010-3375-5555', NULL, NULL, NULL, 4, 4),
('010-3375-5555', NULL, NULL, NULL, 5, 5),
('010-3375-5555', NULL, NULL, NULL, 6, 6),
('010-3375-5555', NULL, NULL, NULL, 7, 7),
('010-3375-5555', NULL, NULL, NULL, 8, 8),
('010-3375-5555', NULL, NULL, NULL, 9, 9),
('010-3375-5555', NULL, NULL, NULL, 10, 10),
('010-3375-5555', NULL, NULL, NULL, 11, null);

insert into business_information(business_number, business_registration_image_url, id_card_image_url, emergency_contact, shop_id, user_id, verification_status)
values ('010-3375-5555', NULL, NULL, NULL, 1, 1, 1);
Loading
Loading