-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from Chapter-1/dev
Deploy: 개발 1차 완료
- Loading branch information
Showing
51 changed files
with
2,529 additions
and
209 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.chapter1.blueprint; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
import org.springframework.data.domain.Page; | ||
|
||
import java.io.IOException; | ||
|
||
public class PageSerializer extends StdSerializer<Page<?>> { | ||
|
||
@SuppressWarnings("unchecked") | ||
public PageSerializer() { | ||
super((Class<Page<?>>) (Class<?>) Page.class); | ||
} | ||
|
||
@Override | ||
public void serialize(Page<?> page, JsonGenerator gen, SerializerProvider provider) throws IOException { | ||
gen.writeStartObject(); | ||
gen.writeObjectField("content", page.getContent()); | ||
gen.writeNumberField("totalPages", page.getTotalPages()); | ||
gen.writeNumberField("totalElements", page.getTotalElements()); | ||
gen.writeNumberField("number", page.getNumber()); | ||
gen.writeNumberField("size", page.getSize()); | ||
gen.writeBooleanField("first", page.isFirst()); | ||
gen.writeBooleanField("last", page.isLast()); | ||
gen.writeEndObject(); | ||
} | ||
} |
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,55 @@ | ||
package com.chapter1.blueprint; | ||
|
||
import io.swagger.v3.oas.models.Components; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.info.Contact; | ||
import io.swagger.v3.oas.models.info.Info; | ||
import io.swagger.v3.oas.models.info.License; | ||
import io.swagger.v3.oas.models.security.SecurityRequirement; | ||
import io.swagger.v3.oas.models.security.SecurityScheme; | ||
import io.swagger.v3.oas.models.servers.Server; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.Arrays; | ||
|
||
@Configuration | ||
public class SwaggerConfig { | ||
|
||
@Bean | ||
public OpenAPI openAPI() { | ||
Info info = new Info() | ||
.title("Project API Documentation") | ||
.version("v1.0.0") | ||
.description("API 명세서") | ||
.contact(new Contact() | ||
.name("Chapter 1") | ||
.email("[email protected]") | ||
.url("https://github.com/Chapter-1")) | ||
.license(new License() | ||
.name("Apache License Version 2.0") | ||
.url("http://www.apache.org/licenses/LICENSE-2.0")); | ||
|
||
// Security 스키마 설정 | ||
SecurityScheme bearerAuth = new SecurityScheme() | ||
.type(SecurityScheme.Type.HTTP) | ||
.scheme("bearer") | ||
.bearerFormat("JWT") | ||
.in(SecurityScheme.In.HEADER) | ||
.name("Authorization"); | ||
|
||
// Security 요청 설정 | ||
SecurityRequirement securityRequirement = new SecurityRequirement().addList("bearerAuth"); | ||
|
||
return new OpenAPI() | ||
.openapi("3.0.1") | ||
.info(info) | ||
.servers(Arrays.asList( | ||
new Server().url("http://localhost:8080").description("Local Server"), | ||
new Server().url("http://localhost:5173/frontend").description("Production Server") | ||
)) | ||
.components(new Components() | ||
.addSecuritySchemes("bearerAuth", bearerAuth)) | ||
.addSecurityItem(securityRequirement); | ||
} | ||
} |
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,29 @@ | ||
package com.chapter1.blueprint; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.http.converter.HttpMessageConverter; | ||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import java.util.List; | ||
|
||
@Configuration | ||
@EnableWebMvc | ||
public class WebMvcConfig implements WebMvcConfigurer { | ||
@Override | ||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { | ||
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); | ||
converter.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); | ||
|
||
// Register the custom Page serializer | ||
SimpleModule module = new SimpleModule(); | ||
module.addSerializer((Class<Page<?>>) (Class<?>) Page.class, new PageSerializer()); | ||
converter.getObjectMapper().registerModule(module); | ||
|
||
converters.add(0, converter); | ||
} | ||
} |
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
104 changes: 104 additions & 0 deletions
104
src/main/java/com/chapter1/blueprint/finance/controller/FinanceController.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 |
---|---|---|
@@ -1,42 +1,146 @@ | ||
package com.chapter1.blueprint.finance.controller; | ||
|
||
import com.chapter1.blueprint.exception.dto.SuccessResponse; | ||
import com.chapter1.blueprint.finance.domain.LoanList; | ||
import com.chapter1.blueprint.finance.domain.SavingsList; | ||
import com.chapter1.blueprint.finance.service.FinanceService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/finance") | ||
@Tag(name = "Finance", description = "금융 상품 관리 API") | ||
public class FinanceController { | ||
private final FinanceService financeService; | ||
|
||
@Operation(summary = "예금 상품 업데이트", description = "예금 상품 정보를 최신 데이터로 업데이트합니다.") | ||
@ApiResponse(responseCode = "200", description = "업데이트 성공") | ||
@GetMapping(value = "/update/deposit") | ||
public ResponseEntity<?> updateDeposit() { | ||
String result = financeService.updateDeposit(); | ||
return ResponseEntity.ok(new SuccessResponse(result)); | ||
} | ||
|
||
@Operation(summary = "적금 상품 업데이트", description = "적금 상품 정보를 최신 데이터로 업데이트합니다.") | ||
@ApiResponse(responseCode = "200", description = "업데이트 성공") | ||
@GetMapping(value = "/update/saving") | ||
public ResponseEntity<?> updateSaving() { | ||
String result = financeService.updateSaving(); | ||
return ResponseEntity.ok(new SuccessResponse(result)); | ||
} | ||
|
||
@Operation(summary = "주택담보대출 상품 업데이트", description = "주택담보대출 상품 정보를 최신 데이터로 업데이트합니다.") | ||
@ApiResponse(responseCode = "200", description = "업데이트 성공") | ||
@GetMapping(value = "/update/mortgage") | ||
public ResponseEntity<?> updateMortgage() { | ||
String result = financeService.updateMortgageLoan(); | ||
return ResponseEntity.ok(new SuccessResponse(result)); | ||
} | ||
|
||
@Operation(summary = "전세자금대출 상품 업데이트", description = "전세자금대출 상품 정보를 최신 데이터로 업데이트합니다.") | ||
@ApiResponse(responseCode = "200", description = "업데이트 성공") | ||
@GetMapping(value = "/update/rentHouse") | ||
public ResponseEntity<?> updateRentHouse() { | ||
String result = financeService.updateRenthouse(); | ||
return ResponseEntity.ok(new SuccessResponse(result)); | ||
} | ||
|
||
@Operation(summary = "적금 상품 필터 조회", description = "적금 상품 필터 정보를 조회합니다.") | ||
@ApiResponse(responseCode = "200", description = "조회 성공", | ||
content = @Content(schema = @Schema(implementation = SavingsList.class))) | ||
@GetMapping("/filter/savings") | ||
public ResponseEntity<SuccessResponse> getSavingsFilter() { | ||
|
||
SavingsList savingsList = financeService.getSavingsFilter(); | ||
return ResponseEntity.ok(new SuccessResponse(savingsList)); | ||
} | ||
|
||
@Operation(summary = "대출 상품 필터 조회", description = "대출 상품 필터 정보를 조회합니다.") | ||
@ApiResponse(responseCode = "200", description = "조회 성공", | ||
content = @Content(schema = @Schema(implementation = LoanList.class))) | ||
@GetMapping("/filter/loan") | ||
public ResponseEntity<SuccessResponse> getLoanFilter() { | ||
|
||
LoanList loanList = financeService.getLoanFilter(); | ||
return ResponseEntity.ok(new SuccessResponse(loanList)); | ||
} | ||
|
||
@Operation(summary = "대출 상품 목록 조회", description = "페이지네이션과 필터를 적용하여 대출 상품 목록을 조회합니다.") | ||
@ApiResponse(responseCode = "200", description = "조회 성공") | ||
@GetMapping("/loans") | ||
public ResponseEntity<?> getLoans( | ||
@RequestParam int page, | ||
@RequestParam int size, | ||
@RequestParam(required = false, defaultValue = "") String mrtgTypeNm, | ||
@RequestParam(required = false, defaultValue = "") String lendRateTypeNm, | ||
@RequestParam(required = false, defaultValue = "lendRateMin") String sortBy, | ||
@RequestParam(required = false, defaultValue = "asc") String direction | ||
) { | ||
// Sort 객체 생성 | ||
Sort sort = Sort.by(Sort.Direction.fromString(direction), sortBy); | ||
Pageable pageable = PageRequest.of(page, size, sort); | ||
|
||
// 서비스 호출 | ||
Page<LoanList> result = financeService.getFilteredLoans(pageable, | ||
mrtgTypeNm.isEmpty() ? null : mrtgTypeNm, | ||
lendRateTypeNm.isEmpty() ? null : lendRateTypeNm); | ||
|
||
return ResponseEntity.ok(new SuccessResponse(result)); | ||
} | ||
|
||
@Operation(summary = "저축 상품 목록 조회", description = "페이지네이션과 필터를 적용하여 저축 상품 목록을 조회합니다.") | ||
@ApiResponse(responseCode = "200", description = "조회 성공") | ||
@GetMapping("/savings") | ||
public ResponseEntity<?> getSavings( | ||
@RequestParam int page, | ||
@RequestParam int size, | ||
@RequestParam(required = false, defaultValue = "") String intrRateNm, | ||
@RequestParam(required = false, defaultValue = "") String prdCategory, | ||
@RequestParam(required = false, defaultValue = "intrRate") String sortBy, | ||
@RequestParam(required = false, defaultValue = "asc") String direction | ||
) { | ||
// Sort 객체 생성 | ||
Sort sort = Sort.by(Sort.Direction.fromString(direction), sortBy); | ||
Pageable pageable = PageRequest.of(page, size, sort); | ||
|
||
// 서비스 호출 | ||
Page<SavingsList> result = financeService.getFilteredSavings(pageable, | ||
intrRateNm.isEmpty() ? null : intrRateNm, | ||
prdCategory.isEmpty() ? null : prdCategory); | ||
|
||
return ResponseEntity.ok(new SuccessResponse(result)); | ||
} | ||
|
||
@GetMapping("/getAllLoans") | ||
public ResponseEntity<?> getAllLoans() { | ||
List<LoanList> loanList = financeService.getAllLoans(); | ||
return ResponseEntity.ok(new SuccessResponse(loanList)); | ||
} | ||
|
||
@GetMapping("/getAllSavings") | ||
public ResponseEntity<?> getAllSavings() { | ||
List<SavingsList> savingsList = financeService.getAllSavings(); | ||
return ResponseEntity.ok(new SuccessResponse(savingsList)); | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/main/java/com/chapter1/blueprint/finance/repository/LoanListRepository.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 |
---|---|---|
@@ -1,9 +1,23 @@ | ||
package com.chapter1.blueprint.finance.repository; | ||
|
||
import com.chapter1.blueprint.finance.domain.LoanList; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Map; | ||
|
||
@Repository | ||
public interface LoanListRepository extends JpaRepository<LoanList, Long> { | ||
|
||
@Query(value = "SELECT * FROM finance.loan_list ORDER BY lend_rate_avg LIMIT 1", nativeQuery = true) | ||
LoanList getLoanFilter(); | ||
|
||
// @Query("SELECT l FROM LoanList l WHERE (:filter1 IS NULL OR l.mrtg_type_nm = :filter1) AND (:filter2 IS NULL OR l.lend_rate_type_nm = :filter2)") | ||
@Query("SELECT l FROM LoanList l WHERE (:mrtgTypeNm is null or l.mrtgTypeNm = :mrtgTypeNm) AND (:lendRateTypeNm is null or l.lendRateTypeNm = :lendRateTypeNm)") | ||
Page<LoanList> findLoansWithFilters(@Param("mrtgTypeNm") String mrtgTypeNm, @Param("lendRateTypeNm") String lendRateTypeNm, Pageable pageable); | ||
|
||
} |
Oops, something went wrong.