Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
feat: FinancialProduct 관련 엔티티 추가 (#24)
Browse files Browse the repository at this point in the history
* [FEAT] RestTemplate Configuration 구현

* [FEAT] financialproduct 엔티티 수정

* [FEAT] Embaded key로 변경

* [FEAT] financialproduct 엔티티 수정
  • Loading branch information
sejineer authored Jan 2, 2024
1 parent 6c9dd09 commit 135577c
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@Getter
@Where(clause = "status = 'ACTIVE'")
public class EduContent extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", updatable = false)
Expand All @@ -36,4 +37,5 @@ public EduContent(Post post_id, Long sequence, String content){
this.sequence=sequence;
this.content=content;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ public class PolicyInfo extends BaseEntity {
public PolicyInfo(String url){
this.url=url;
}

}
2 changes: 2 additions & 0 deletions src/main/java/com/finfellows/domain/post/domain/Content.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@Getter
@Where(clause = "status = 'ACTIVE'")
public class Content {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", updatable = false)
Expand All @@ -34,4 +35,5 @@ public Content(Post post_id, Long sequence, String content){
this.sequence=sequence;
this.content=content;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,19 @@ public class FinancialProduct extends BaseEntity {
@Column(name = "id", updatable = false)
private Long id;

@Column(name="disclosure_month")
@Column(name = "financial_company_no")
private String financialCompanyNo;

@Column(name = "financial_product_code")
private String financialProductCode;

@Column(name = "top_financial_group_no")
private String topFinancialGroupNo;

@Column(name = "disclosure_month")
private String disclosureMonth;

@Column(name="company_name")
@Column(name = "company_name")
private String companyName;

@Column(name = "product_name")
Expand Down Expand Up @@ -62,8 +71,15 @@ public class FinancialProduct extends BaseEntity {
@Column(name = "financial_company_submission_day")
private LocalDateTime financialCompanySubmissionDay;

@Enumerated(value = EnumType.STRING)
@Column(name = "financial_product_type")
private FinancialProductType financialProductType;

@Builder
public FinancialProduct(String disclosureMonth, String companyName, String productName, String joinWay, String maturityInterestRate, String specialCondition, Integer joinDeny, String joinMember, String etcNote, Integer maxLimit, LocalDate disclosureStartDay, LocalDate disclosureEndDay, LocalDateTime financialCompanySubmissionDay) {
public FinancialProduct(String financialCompanyNo, String financialProductCode, String topFinancialGroupNo, String disclosureMonth, String companyName, String productName, String joinWay, String maturityInterestRate, String specialCondition, Integer joinDeny, String joinMember, String etcNote, Integer maxLimit, LocalDate disclosureStartDay, LocalDate disclosureEndDay, LocalDateTime financialCompanySubmissionDay, FinancialProductType financialProductType) {
this.financialCompanyNo = financialCompanyNo;
this.financialProductCode = financialProductCode;
this.topFinancialGroupNo = topFinancialGroupNo;
this.disclosureMonth = disclosureMonth;
this.companyName = companyName;
this.productName = productName;
Expand All @@ -77,6 +93,7 @@ public FinancialProduct(String disclosureMonth, String companyName, String produ
this.disclosureStartDay = disclosureStartDay;
this.disclosureEndDay = disclosureEndDay;
this.financialCompanySubmissionDay = financialCompanySubmissionDay;
this.financialProductType = financialProductType;
}

}
}
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;
}

}
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 src/main/java/com/finfellows/global/config/RestTemplateConfig.java

This file was deleted.

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();
}
}

}
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();
}

}
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();
}
}

}

0 comments on commit 135577c

Please sign in to comment.