This repository has been archived by the owner on Oct 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: FinancialProduct 관련 엔티티 추가 (#24)
* [FEAT] RestTemplate Configuration 구현 * [FEAT] financialproduct 엔티티 수정 * [FEAT] Embaded key로 변경 * [FEAT] financialproduct 엔티티 수정
- Loading branch information
Showing
10 changed files
with
217 additions
and
27 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
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 |
---|---|---|
|
@@ -27,4 +27,5 @@ public class PolicyInfo extends BaseEntity { | |
public PolicyInfo(String url){ | ||
this.url=url; | ||
} | ||
|
||
} |
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
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
64 changes: 64 additions & 0 deletions
64
src/main/java/com/finfellows/domain/product/domain/FinancialProductOption.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,64 @@ | ||
package com.finfellows.domain.product.domain; | ||
|
||
import com.finfellows.domain.common.BaseEntity; | ||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.Where; | ||
|
||
@Entity | ||
@Table(name = "Financial_Product_Option") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
@Where(clause = "status = 'ACTIVE'") | ||
public class FinancialProductOption extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id", updatable = false) | ||
private Long id; | ||
|
||
@Column(name = "disclosure_month") | ||
private String disclosureMonth; | ||
|
||
@Column(name = "interest_rate_type") | ||
private String interestRateType; | ||
|
||
@Column(name = "interest_rate_type_name") | ||
private String interestRateTypeName; | ||
|
||
@Column(name = "reserve_type") | ||
private String reserveType; | ||
|
||
@Column(name = "reserve_type_name") | ||
private String reserveTypeName; | ||
|
||
@Column(name = "savings_term") | ||
private Integer savingsTerm; | ||
|
||
@Column(name = "interest_rate") | ||
private String interestRate; | ||
|
||
@Column(name = "maximum_preferred_interest_rate") | ||
private String maximumPreferredInterestRate; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "financial_product_id") | ||
private FinancialProduct financialProduct; | ||
|
||
@Builder | ||
public FinancialProductOption(String disclosureMonth, String interestRateType, String interestRateTypeName, String reserveType, String reserveTypeName, Integer savingsTerm, String interestRate, String maximumPreferredInterestRate, FinancialProduct financialProduct) { | ||
this.disclosureMonth = disclosureMonth; | ||
this.interestRateType = interestRateType; | ||
this.interestRateTypeName = interestRateTypeName; | ||
this.reserveType = reserveType; | ||
this.reserveTypeName = reserveTypeName; | ||
this.savingsTerm = savingsTerm; | ||
this.interestRate = interestRate; | ||
this.maximumPreferredInterestRate = maximumPreferredInterestRate; | ||
this.financialProduct = financialProduct; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/finfellows/domain/product/domain/FinancialProductType.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,7 @@ | ||
package com.finfellows.domain.product.domain; | ||
|
||
public enum FinancialProductType { | ||
SAVING, | ||
DEPOSIT, | ||
CMA | ||
} |
23 changes: 0 additions & 23 deletions
23
src/main/java/com/finfellows/global/config/RestTemplateConfig.java
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
...a/com/finfellows/global/config/resttemplate/RestTemplateClientHttpRequestInterceptor.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,56 @@ | ||
package com.finfellows.global.config.resttemplate; | ||
|
||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpRequest; | ||
import org.springframework.http.client.ClientHttpRequestExecution; | ||
import org.springframework.http.client.ClientHttpRequestInterceptor; | ||
import org.springframework.http.client.ClientHttpResponse; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
@Slf4j | ||
public class RestTemplateClientHttpRequestInterceptor implements ClientHttpRequestInterceptor { | ||
|
||
@NonNull | ||
@Override | ||
public ClientHttpResponse intercept(@NonNull final HttpRequest request, | ||
final byte @NonNull [] body, | ||
@NonNull final ClientHttpRequestExecution execution) throws IOException { | ||
final ClientHttpResponse response = execution.execute(request, body); | ||
|
||
loggingResponse(response); | ||
loggingRequest(request, body); | ||
return execution.execute(request, body); | ||
} | ||
|
||
private void loggingRequest(final HttpRequest request, byte[] body) { | ||
log.info("=====Request======"); | ||
log.info("Headers: {}", request.getHeaders()); | ||
log.info("Request Method: {}", request.getMethod()); | ||
log.info("Request URI: {}", request.getURI()); | ||
log.info("Request body: {}", | ||
body.length == 0 ? null : new String(body, StandardCharsets.UTF_8)); | ||
log.info("=====Request======"); | ||
} | ||
|
||
private void loggingResponse(ClientHttpResponse response) throws IOException { | ||
final String body = getBody(response); | ||
|
||
log.info("======Response======="); | ||
log.info("Headers: {}", response.getHeaders()); | ||
log.info("Response Status : {}", response.getRawStatusCode()); | ||
log.info("Request body: {}", body); | ||
log.info("======Response======="); | ||
} | ||
|
||
private String getBody(@NonNull final ClientHttpResponse response) throws IOException { | ||
try (BufferedReader br = new BufferedReader(new InputStreamReader(response.getBody()))) { | ||
return br.readLine(); | ||
} | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/finfellows/global/config/resttemplate/RestTemplateConfig.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,26 @@ | ||
package com.finfellows.global.config.resttemplate; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.web.client.RestTemplateBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.time.Duration; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class RestTemplateConfig { | ||
|
||
private final RestTemplateBuilder restTemplateBuilder; | ||
|
||
@Bean | ||
public RestTemplate localTestTemplate() { | ||
return restTemplateBuilder.rootUri("http://localhost:8080") | ||
.additionalInterceptors(new RestTemplateClientHttpRequestInterceptor()) | ||
.errorHandler(new RestTemplateErrorHandler()) | ||
.setConnectTimeout(Duration.ofMinutes(3)) | ||
.build(); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/finfellows/global/config/resttemplate/RestTemplateErrorHandler.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,38 @@ | ||
package com.finfellows.global.config.resttemplate; | ||
|
||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.client.ClientHttpResponse; | ||
import org.springframework.web.client.ResponseErrorHandler; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
@Slf4j | ||
public class RestTemplateErrorHandler implements ResponseErrorHandler { | ||
|
||
@Override | ||
public boolean hasError(@NonNull final ClientHttpResponse response) throws IOException { | ||
final HttpStatus statusCode = (HttpStatus) response.getStatusCode(); | ||
return !statusCode.is2xxSuccessful(); | ||
} | ||
|
||
@Override | ||
public void handleError(@NonNull final ClientHttpResponse response) throws IOException { | ||
final String error = getErrorAsString(response); | ||
log.error("================"); | ||
log.error("Headers: {}", response.getHeaders()); | ||
log.error("Response Status : {}", response.getRawStatusCode()); | ||
log.error("Request body: {}", error); | ||
log.error("================"); | ||
} | ||
|
||
private String getErrorAsString(@NonNull final ClientHttpResponse response) throws IOException { | ||
try (BufferedReader br = new BufferedReader(new InputStreamReader(response.getBody()))) { | ||
return br.readLine(); | ||
} | ||
} | ||
|
||
} |