From c05b481d52ffe69c222044239923e87736372885 Mon Sep 17 00:00:00 2001 From: KIMSEI1124 Date: Thu, 28 Sep 2023 23:09:54 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Feat:=20=EC=98=88=EA=B8=88=EC=A3=BC=20?= =?UTF-8?q?=EC=8B=A4=EB=AA=85=20=EC=A1=B0=ED=9A=8C=20APIKey=20=EC=9C=A0?= =?UTF-8?q?=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=82=AC=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 올바르지 않은 API Key이면 예외를 발생 Related to: #97 --- build.gradle | 1 + .../tott/api/exception/APIErrorCode.java | 4 +- .../ShinhanBankSearchNameFetchAPI.java | 41 ++++++++++++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 871f94d..d8786c4 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-redis' /* API */ implementation 'org.springframework.boot:spring-boot-starter-webflux' + implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1' // String JSON Parse /* querydsl */ implementation "com.querydsl:querydsl-jpa:${queryDslVersion}" implementation "com.querydsl:querydsl-apt:${queryDslVersion}" diff --git a/src/main/java/com/ssafy/tott/api/exception/APIErrorCode.java b/src/main/java/com/ssafy/tott/api/exception/APIErrorCode.java index 57ccb4a..8a4068b 100644 --- a/src/main/java/com/ssafy/tott/api/exception/APIErrorCode.java +++ b/src/main/java/com/ssafy/tott/api/exception/APIErrorCode.java @@ -9,7 +9,9 @@ @Getter public enum APIErrorCode implements ErrorCode { ERROR_SERVER_BY_JSON_PROCESSING(500, "API_01", "내부 서버 오류 입니다."), - ERROR_SERVER_BY_OUTER_API_SERVER(500, "API_02", "API 서버 오류 입니다."); + ERROR_SERVER_BY_OUTER_API_SERVER(500, "API_02", "API 서버 오류 입니다."), + ERROR_SERVER_BY_API_KEY_IS_NOT_VALID(500, "API_03", "올바르지 않은 API 키 입니다."), + ; private int statusCode; private String errorCode; diff --git a/src/main/java/com/ssafy/tott/api/shinhan/service/searchname/ShinhanBankSearchNameFetchAPI.java b/src/main/java/com/ssafy/tott/api/shinhan/service/searchname/ShinhanBankSearchNameFetchAPI.java index d93e09c..9ea785f 100644 --- a/src/main/java/com/ssafy/tott/api/shinhan/service/searchname/ShinhanBankSearchNameFetchAPI.java +++ b/src/main/java/com/ssafy/tott/api/shinhan/service/searchname/ShinhanBankSearchNameFetchAPI.java @@ -2,11 +2,17 @@ import com.ssafy.tott.api.core.FetchAPICore; import com.ssafy.tott.api.core.dto.APIRequest; -import com.ssafy.tott.api.shinhan.dto.response.ShinhanBankAPIResponse; +import com.ssafy.tott.api.exception.APIErrorCode; +import com.ssafy.tott.api.exception.APIException; +import com.ssafy.tott.api.shinhan.dto.request.ShinhanBankAPIRequest; import com.ssafy.tott.api.shinhan.factory.ShinhanBankWebClientFactory; import com.ssafy.tott.api.shinhan.service.searchname.dto.request.ShinhanBankSearchNameRequest; +import com.ssafy.tott.api.shinhan.service.searchname.dto.request.ShinhanBankSearchNameRequestDataBody; import com.ssafy.tott.api.shinhan.service.searchname.dto.response.ShinhanBankSearchNameResponse; import lombok.RequiredArgsConstructor; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.client.WebClient; @@ -19,6 +25,9 @@ public class ShinhanBankSearchNameFetchAPI implements FetchAPICore { @Value("${SHINHAN_BANK.API.URI.SEARCH_NAME}") private String uri; + @Value("${SHINHAN_BANK.API.KEY}") + private String validateKey; // 실제 `API`가 존재시 삭제 필요 + @Override public ShinhanBankSearchNameResponse fetchAPI(APIRequest json) { ShinhanBankSearchNameRequest shinhanBankSearchNameRequest = (ShinhanBankSearchNameRequest) json; @@ -30,4 +39,34 @@ public ShinhanBankSearchNameResponse fetchAPI(APIRequest json) { .bodyToMono(ShinhanBankSearchNameResponse.class) .block(); } + + private ShinhanBankSearchNameResponse dummyFetchAPI(APIRequest request) { + if (request instanceof ShinhanBankSearchNameRequest) { + ShinhanBankSearchNameRequest shinhanBankSearchNameRequest = (ShinhanBankSearchNameRequest) request; + ShinhanBankAPIRequest searchNameRequest = parseByJson(shinhanBankSearchNameRequest.getJson()); + validateApiKey(searchNameRequest.getDataHeader().getApikey()); + } + throw new APIException(APIErrorCode.ERROR_SERVER_BY_JSON_PROCESSING); + } + + private ShinhanBankAPIRequest parseByJson(String json) { + try { + JSONParser parser = new JSONParser(); + JSONObject object = (JSONObject) parser.parse(json); + JSONObject dataHeader = (JSONObject) object.get("dataHeader"); + JSONObject dataBody = (JSONObject) object.get("dataBody"); + String apiKey = (String) dataHeader.get("apiKey"); + String bankCode = (String) dataBody.get("입금은행코드"); + String account = (String) dataBody.get("입금계좌번호"); + return ShinhanBankAPIRequest.of(apiKey, ShinhanBankSearchNameRequestDataBody.of(bankCode, account)); + } catch (ParseException e) { + throw new APIException(APIErrorCode.ERROR_SERVER_BY_JSON_PROCESSING); + } + } + + private void validateApiKey(String apiKey) { + if (!apiKey.equals(validateKey)) { + throw new APIException(APIErrorCode.ERROR_SERVER_BY_API_KEY_IS_NOT_VALID); + } + } } From 51f50ef24824e2ba9f801864363f01258e071b21 Mon Sep 17 00:00:00 2001 From: KIMSEI1124 Date: Fri, 29 Sep 2023 00:20:09 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Feat:=20=EC=98=88=EA=B8=88=EC=A3=BC=20?= =?UTF-8?q?=EC=8B=A4=EB=AA=85=20=EC=A1=B0=ED=9A=8C=20API=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B4=80=EB=A0=A8=20=ED=95=A8=EC=88=98=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related to: #97 --- .../dto/response/ShinhanBankAPIResponse.java | 4 ++ .../response/header/ResponseDataHeader.java | 10 +++++ .../ShinhanBankSearchNameFetchAPI.java | 43 ++++++++++++++----- .../ShinhanBankSearchNameResponse.java | 12 ++++++ ...ShinhanBankSearchNameResponseDataBody.java | 10 +++++ 5 files changed, 69 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/ssafy/tott/api/shinhan/dto/response/ShinhanBankAPIResponse.java b/src/main/java/com/ssafy/tott/api/shinhan/dto/response/ShinhanBankAPIResponse.java index 1527441..f818d55 100644 --- a/src/main/java/com/ssafy/tott/api/shinhan/dto/response/ShinhanBankAPIResponse.java +++ b/src/main/java/com/ssafy/tott/api/shinhan/dto/response/ShinhanBankAPIResponse.java @@ -18,4 +18,8 @@ public abstract class ShinhanBankAPIResponse implements APIResponse { public boolean isFailed() { return dataHeader.getSuccessCode().equals(ERROR_CODE); } + + protected void setDataHeader(ResponseDataHeader dataHeader) { + this.dataHeader = dataHeader; + } } diff --git a/src/main/java/com/ssafy/tott/api/shinhan/dto/response/header/ResponseDataHeader.java b/src/main/java/com/ssafy/tott/api/shinhan/dto/response/header/ResponseDataHeader.java index 55a0413..7026ce1 100644 --- a/src/main/java/com/ssafy/tott/api/shinhan/dto/response/header/ResponseDataHeader.java +++ b/src/main/java/com/ssafy/tott/api/shinhan/dto/response/header/ResponseDataHeader.java @@ -16,4 +16,14 @@ public class ResponseDataHeader { @JsonProperty("resultMessage") private String resultMessage; + + private ResponseDataHeader(String successCode) { + this.successCode = successCode; + this.resultCode = ""; + this.resultMessage = ""; + } + + public static ResponseDataHeader from(String successCode) { + return new ResponseDataHeader(successCode); + } } diff --git a/src/main/java/com/ssafy/tott/api/shinhan/service/searchname/ShinhanBankSearchNameFetchAPI.java b/src/main/java/com/ssafy/tott/api/shinhan/service/searchname/ShinhanBankSearchNameFetchAPI.java index 9ea785f..945bacc 100644 --- a/src/main/java/com/ssafy/tott/api/shinhan/service/searchname/ShinhanBankSearchNameFetchAPI.java +++ b/src/main/java/com/ssafy/tott/api/shinhan/service/searchname/ShinhanBankSearchNameFetchAPI.java @@ -1,24 +1,30 @@ package com.ssafy.tott.api.shinhan.service.searchname; +import com.ssafy.tott.account.domain.BankCode; import com.ssafy.tott.api.core.FetchAPICore; import com.ssafy.tott.api.core.dto.APIRequest; import com.ssafy.tott.api.exception.APIErrorCode; import com.ssafy.tott.api.exception.APIException; import com.ssafy.tott.api.shinhan.dto.request.ShinhanBankAPIRequest; +import com.ssafy.tott.api.shinhan.dto.response.header.ResponseDataHeader; import com.ssafy.tott.api.shinhan.factory.ShinhanBankWebClientFactory; import com.ssafy.tott.api.shinhan.service.searchname.dto.request.ShinhanBankSearchNameRequest; import com.ssafy.tott.api.shinhan.service.searchname.dto.request.ShinhanBankSearchNameRequestDataBody; import com.ssafy.tott.api.shinhan.service.searchname.dto.response.ShinhanBankSearchNameResponse; +import com.ssafy.tott.api.shinhan.service.searchname.dto.response.body.ShinhanBankSearchNameResponseDataBody; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import org.springframework.web.reactive.function.client.WebClient; + +import java.util.regex.Pattern; @RequiredArgsConstructor @Component +@Slf4j public class ShinhanBankSearchNameFetchAPI implements FetchAPICore { private final ShinhanBankWebClientFactory shinhanBankWebClientFactory; @@ -30,14 +36,16 @@ public class ShinhanBankSearchNameFetchAPI implements FetchAPICore { @Override public ShinhanBankSearchNameResponse fetchAPI(APIRequest json) { - ShinhanBankSearchNameRequest shinhanBankSearchNameRequest = (ShinhanBankSearchNameRequest) json; - WebClient webClient = shinhanBankWebClientFactory.createWebClientWithURI(uri); - return webClient - .post() - .bodyValue(shinhanBankSearchNameRequest.getJson()) - .retrieve() - .bodyToMono(ShinhanBankSearchNameResponse.class) - .block(); + return dummyFetchAPI(json); + /* 원래라면 정상 동작하는 코드이지만 현재는 비활성화 되어서 주석 처리 */ +// ShinhanBankSearchNameRequest shinhanBankSearchNameRequest = (ShinhanBankSearchNameRequest) json; +// WebClient webClient = shinhanBankWebClientFactory.createWebClientWithURI(uri); +// return webClient +// .post() +// .bodyValue(shinhanBankSearchNameRequest.getJson()) +// .retrieve() +// .bodyToMono(ShinhanBankSearchNameResponse.class) +// .block(); } private ShinhanBankSearchNameResponse dummyFetchAPI(APIRequest request) { @@ -45,6 +53,7 @@ private ShinhanBankSearchNameResponse dummyFetchAPI(APIRequest request) { ShinhanBankSearchNameRequest shinhanBankSearchNameRequest = (ShinhanBankSearchNameRequest) request; ShinhanBankAPIRequest searchNameRequest = parseByJson(shinhanBankSearchNameRequest.getJson()); validateApiKey(searchNameRequest.getDataHeader().getApikey()); + return sendResponse((ShinhanBankSearchNameRequestDataBody) searchNameRequest.getShinhanBankDataBody()); } throw new APIException(APIErrorCode.ERROR_SERVER_BY_JSON_PROCESSING); } @@ -55,7 +64,7 @@ private ShinhanBankAPIRequest parseByJson(String json) { JSONObject object = (JSONObject) parser.parse(json); JSONObject dataHeader = (JSONObject) object.get("dataHeader"); JSONObject dataBody = (JSONObject) object.get("dataBody"); - String apiKey = (String) dataHeader.get("apiKey"); + String apiKey = (String) dataHeader.get("apikey"); String bankCode = (String) dataBody.get("입금은행코드"); String account = (String) dataBody.get("입금계좌번호"); return ShinhanBankAPIRequest.of(apiKey, ShinhanBankSearchNameRequestDataBody.of(bankCode, account)); @@ -69,4 +78,18 @@ private void validateApiKey(String apiKey) { throw new APIException(APIErrorCode.ERROR_SERVER_BY_API_KEY_IS_NOT_VALID); } } + + private ShinhanBankSearchNameResponse sendResponse(ShinhanBankSearchNameRequestDataBody dataBody) { + if (validateDataBody(dataBody)) { + return ShinhanBankSearchNameResponse.of(ResponseDataHeader.from("1"), + ShinhanBankSearchNameResponseDataBody.of(dataBody.getBankCode(), dataBody.getAccount(), null)); + } + return ShinhanBankSearchNameResponse.of(ResponseDataHeader.from("0"), + ShinhanBankSearchNameResponseDataBody.of(dataBody.getBankCode(), dataBody.getAccount(), "김신한")); + } + + private boolean validateDataBody(ShinhanBankSearchNameRequestDataBody dataBody) { + return !dataBody.getBankCode().equals(BankCode.SHINHAN.getCode()) || + !Pattern.matches("\\d{10,14}", dataBody.getAccount()); + } } diff --git a/src/main/java/com/ssafy/tott/api/shinhan/service/searchname/dto/response/ShinhanBankSearchNameResponse.java b/src/main/java/com/ssafy/tott/api/shinhan/service/searchname/dto/response/ShinhanBankSearchNameResponse.java index 23e2564..d9f7f96 100644 --- a/src/main/java/com/ssafy/tott/api/shinhan/service/searchname/dto/response/ShinhanBankSearchNameResponse.java +++ b/src/main/java/com/ssafy/tott/api/shinhan/service/searchname/dto/response/ShinhanBankSearchNameResponse.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.ssafy.tott.api.shinhan.dto.response.ShinhanBankAPIResponse; +import com.ssafy.tott.api.shinhan.dto.response.header.ResponseDataHeader; import com.ssafy.tott.api.shinhan.service.searchname.dto.response.body.ShinhanBankSearchNameResponseDataBody; import lombok.AccessLevel; import lombok.Getter; @@ -13,6 +14,17 @@ public class ShinhanBankSearchNameResponse extends ShinhanBankAPIResponse { @JsonProperty("dataBody") private ShinhanBankSearchNameResponseDataBody shinhanBankSearchNameResponseDataBody; + private ShinhanBankSearchNameResponse(ResponseDataHeader dataHeader, + ShinhanBankSearchNameResponseDataBody dataBody) { + setDataHeader(dataHeader); + this.shinhanBankSearchNameResponseDataBody = dataBody; + } + + public static ShinhanBankSearchNameResponse of(ResponseDataHeader dataHeader, + ShinhanBankSearchNameResponseDataBody dataBody) { + return new ShinhanBankSearchNameResponse(dataHeader, dataBody); + } + public String getOwnerName() { return shinhanBankSearchNameResponseDataBody.getAccountOwnerName(); } diff --git a/src/main/java/com/ssafy/tott/api/shinhan/service/searchname/dto/response/body/ShinhanBankSearchNameResponseDataBody.java b/src/main/java/com/ssafy/tott/api/shinhan/service/searchname/dto/response/body/ShinhanBankSearchNameResponseDataBody.java index 97b9bb9..55affcb 100644 --- a/src/main/java/com/ssafy/tott/api/shinhan/service/searchname/dto/response/body/ShinhanBankSearchNameResponseDataBody.java +++ b/src/main/java/com/ssafy/tott/api/shinhan/service/searchname/dto/response/body/ShinhanBankSearchNameResponseDataBody.java @@ -17,4 +17,14 @@ public class ShinhanBankSearchNameResponseDataBody extends ShinhanBankDataBody { @JsonProperty("입금계좌성명") private String accountOwnerName; + + private ShinhanBankSearchNameResponseDataBody(String bankCode, String account, String accountOwnerName) { + this.bankCode = bankCode; + this.account = account; + this.accountOwnerName = accountOwnerName; + } + + public static ShinhanBankSearchNameResponseDataBody of(String bankCode, String account, String accountOwnerName) { + return new ShinhanBankSearchNameResponseDataBody(bankCode, account, accountOwnerName); + } } From be2402a8a4ec24662616834fe3f99e8322c6c2d5 Mon Sep 17 00:00:00 2001 From: KIMSEI1124 Date: Fri, 29 Sep 2023 15:19:13 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Feat:=201=EC=9B=90=20=EC=9D=B4=EC=B2=B4=20A?= =?UTF-8?q?PI=20=EA=B8=B0=EB=8A=A5=20=EC=9E=AC=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존에 제공하던 API가 비활성화되어서 비슷하게 동작하는 함수로 구현 Related to: #97 --- .../ShinhanBankTransfer1FetchAPI.java | 90 ++++++++++++++++--- .../ShinhanBankTransfer1Response.java | 12 +++ .../Transfer1ResponseShinhanBankDataBody.java | 10 +++ 3 files changed, 102 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/ssafy/tott/api/shinhan/service/transfer1/ShinhanBankTransfer1FetchAPI.java b/src/main/java/com/ssafy/tott/api/shinhan/service/transfer1/ShinhanBankTransfer1FetchAPI.java index 4bef9d3..e2b7942 100644 --- a/src/main/java/com/ssafy/tott/api/shinhan/service/transfer1/ShinhanBankTransfer1FetchAPI.java +++ b/src/main/java/com/ssafy/tott/api/shinhan/service/transfer1/ShinhanBankTransfer1FetchAPI.java @@ -1,15 +1,25 @@ package com.ssafy.tott.api.shinhan.service.transfer1; +import com.ssafy.tott.account.domain.BankCode; import com.ssafy.tott.api.core.FetchAPICore; import com.ssafy.tott.api.core.dto.APIRequest; -import com.ssafy.tott.api.shinhan.dto.response.ShinhanBankAPIResponse; +import com.ssafy.tott.api.exception.APIErrorCode; +import com.ssafy.tott.api.exception.APIException; +import com.ssafy.tott.api.shinhan.dto.request.ShinhanBankAPIRequest; +import com.ssafy.tott.api.shinhan.dto.response.header.ResponseDataHeader; import com.ssafy.tott.api.shinhan.factory.ShinhanBankWebClientFactory; import com.ssafy.tott.api.shinhan.service.transfer1.dto.request.ShinhanBankTransfer1Request; +import com.ssafy.tott.api.shinhan.service.transfer1.dto.request.ShinhanBankTransfer1RequestDataBody; import com.ssafy.tott.api.shinhan.service.transfer1.dto.response.ShinhanBankTransfer1Response; +import com.ssafy.tott.api.shinhan.service.transfer1.dto.response.body.Transfer1ResponseShinhanBankDataBody; import lombok.RequiredArgsConstructor; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import org.springframework.web.reactive.function.client.WebClient; + +import java.util.regex.Pattern; @RequiredArgsConstructor @Component @@ -20,15 +30,75 @@ public class ShinhanBankTransfer1FetchAPI implements FetchAPICore { @Value("${SHINHAN_BANK.API.URI.1TRANSFER}") private String uri; + @Value("${SHINHAN_BANK.API.KEY}") + private String validateKey; // 실제 `API`가 존재시 삭제 필요 + @Override public ShinhanBankTransfer1Response fetchAPI(APIRequest request) { - ShinhanBankTransfer1Request shinhanBankTransfer1Request = (ShinhanBankTransfer1Request) request; - WebClient webClient = shinhanBankWebClientFactory.createWebClientWithURI(uri); - return webClient - .post() - .bodyValue(shinhanBankTransfer1Request.getJson()) - .retrieve() - .bodyToMono(ShinhanBankTransfer1Response.class) - .block(); + return dummyFetchAPI(request); +// ShinhanBankTransfer1Request shinhanBankTransfer1Request = (ShinhanBankTransfer1Request) request; +// WebClient webClient = shinhanBankWebClientFactory.createWebClientWithURI(uri); +// return webClient +// .post() +// .bodyValue(shinhanBankTransfer1Request.getJson()) +// .retrieve() +// .bodyToMono(ShinhanBankTransfer1Response.class) +// .block(); + } + + private ShinhanBankTransfer1Response dummyFetchAPI(APIRequest request) { + if (request instanceof ShinhanBankTransfer1Request) { + ShinhanBankTransfer1Request shinhanBankTransfer1Request = (ShinhanBankTransfer1Request) request; + ShinhanBankAPIRequest searchNameRequest = parseByJson(shinhanBankTransfer1Request.getJson()); + validateApiKey(searchNameRequest.getDataHeader().getApikey()); + return sendResponse((ShinhanBankTransfer1RequestDataBody) searchNameRequest.getShinhanBankDataBody()); + } + throw new APIException(APIErrorCode.ERROR_SERVER_BY_JSON_PROCESSING); + } + + private ShinhanBankAPIRequest parseByJson(String json) { + try { + JSONParser parser = new JSONParser(); + JSONObject object = (JSONObject) parser.parse(json); + JSONObject dataHeader = (JSONObject) object.get("dataHeader"); + JSONObject dataBody = (JSONObject) object.get("dataBody"); + String apiKey = (String) dataHeader.get("apikey"); + String bankCode = (String) dataBody.get("입금은행코드"); + String account = (String) dataBody.get("입금계좌번호"); + String memo = (String) dataBody.get("입금통장메모"); + return ShinhanBankAPIRequest.of(apiKey, + ShinhanBankTransfer1RequestDataBody.of(getBankCode(bankCode), account, memo)); + } catch (ParseException e) { + throw new APIException(APIErrorCode.ERROR_SERVER_BY_JSON_PROCESSING); + } + } + + private BankCode getBankCode(String bankCode) { + for (BankCode code : BankCode.values()) { + if (code.getCode().equals(bankCode)) { + return code; + } + } + return null; + } + + private void validateApiKey(String apiKey) { + if (!apiKey.equals(validateKey)) { + throw new APIException(APIErrorCode.ERROR_SERVER_BY_API_KEY_IS_NOT_VALID); + } + } + + private ShinhanBankTransfer1Response sendResponse(ShinhanBankTransfer1RequestDataBody dataBody) { + if (validateDataBody(dataBody)) { + return ShinhanBankTransfer1Response.of(ResponseDataHeader.from("1"), + Transfer1ResponseShinhanBankDataBody.from(dataBody)); + } + return ShinhanBankTransfer1Response.of(ResponseDataHeader.from("0"), + Transfer1ResponseShinhanBankDataBody.from(dataBody)); + } + + private boolean validateDataBody(ShinhanBankTransfer1RequestDataBody dataBody) { + return !dataBody.getBankCode().equals(BankCode.SHINHAN.getCode()) || + !Pattern.matches("\\d{10,14}", dataBody.getAccount()); } } diff --git a/src/main/java/com/ssafy/tott/api/shinhan/service/transfer1/dto/response/ShinhanBankTransfer1Response.java b/src/main/java/com/ssafy/tott/api/shinhan/service/transfer1/dto/response/ShinhanBankTransfer1Response.java index af90562..ddb0cc1 100644 --- a/src/main/java/com/ssafy/tott/api/shinhan/service/transfer1/dto/response/ShinhanBankTransfer1Response.java +++ b/src/main/java/com/ssafy/tott/api/shinhan/service/transfer1/dto/response/ShinhanBankTransfer1Response.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.ssafy.tott.api.shinhan.dto.response.ShinhanBankAPIResponse; +import com.ssafy.tott.api.shinhan.dto.response.header.ResponseDataHeader; import com.ssafy.tott.api.shinhan.service.transfer1.dto.response.body.Transfer1ResponseShinhanBankDataBody; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -11,6 +12,17 @@ public class ShinhanBankTransfer1Response extends ShinhanBankAPIResponse { @JsonProperty("dataBody") private Transfer1ResponseShinhanBankDataBody transfer1ResponseShinhanBankDataBody; + private ShinhanBankTransfer1Response(ResponseDataHeader dataHeader, + Transfer1ResponseShinhanBankDataBody dataBody) { + setDataHeader(dataHeader); + this.transfer1ResponseShinhanBankDataBody = dataBody; + } + + public static ShinhanBankTransfer1Response of(ResponseDataHeader dataHeader, + Transfer1ResponseShinhanBankDataBody dataBody) { + return new ShinhanBankTransfer1Response(dataHeader, dataBody); + } + public Transfer1ResponseShinhanBankDataBody getDataBody() { return transfer1ResponseShinhanBankDataBody; } diff --git a/src/main/java/com/ssafy/tott/api/shinhan/service/transfer1/dto/response/body/Transfer1ResponseShinhanBankDataBody.java b/src/main/java/com/ssafy/tott/api/shinhan/service/transfer1/dto/response/body/Transfer1ResponseShinhanBankDataBody.java index 075460f..6537c3c 100644 --- a/src/main/java/com/ssafy/tott/api/shinhan/service/transfer1/dto/response/body/Transfer1ResponseShinhanBankDataBody.java +++ b/src/main/java/com/ssafy/tott/api/shinhan/service/transfer1/dto/response/body/Transfer1ResponseShinhanBankDataBody.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.ssafy.tott.api.shinhan.dto.ShinhanBankDataBody; +import com.ssafy.tott.api.shinhan.service.transfer1.dto.request.ShinhanBankTransfer1RequestDataBody; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -14,4 +15,13 @@ public class Transfer1ResponseShinhanBankDataBody extends ShinhanBankDataBody { @JsonProperty("입금계좌번호") private String account; + + private Transfer1ResponseShinhanBankDataBody(String bankCode, String account) { + this.bankCode = bankCode; + this.account = account; + } + + public static Transfer1ResponseShinhanBankDataBody from(ShinhanBankTransfer1RequestDataBody dataBody) { + return new Transfer1ResponseShinhanBankDataBody(dataBody.getBankCode(), dataBody.getAccount()); + } }