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.
Merge pull request #57 from FinFellows/develop
[FEAT]: 50 policy api (#56)
- Loading branch information
Showing
8 changed files
with
203 additions
and
10 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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/finfellows/domain/policyinfo/application/PolicyInfoService.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,13 @@ | ||
package com.finfellows.domain.policyinfo.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
@Transactional(readOnly = true) | ||
public class PolicyInfoService { | ||
|
||
|
||
} |
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
11 changes: 11 additions & 0 deletions
11
...java/com/finfellows/domain/policyinfo/domain/repository/PolicyInfoQueryDslRepository.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,11 @@ | ||
package com.finfellows.domain.policyinfo.domain.repository; | ||
|
||
import com.finfellows.domain.policyinfo.dto.SearchPolicyInfoRes; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
public interface PolicyInfoQueryDslRepository { | ||
|
||
Page<SearchPolicyInfoRes> findPolicyInfos(String searchKeyword, Pageable pageable, Long userId); | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
.../com/finfellows/domain/policyinfo/domain/repository/PolicyInfoQueryDslRepositoryImpl.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,62 @@ | ||
package com.finfellows.domain.policyinfo.domain.repository; | ||
|
||
import com.finfellows.domain.bookmark.domain.QPolicyInfoBookmark; | ||
import com.finfellows.domain.policyinfo.domain.QPolicyInfo; | ||
import com.finfellows.domain.policyinfo.dto.QSearchPolicyInfoRes; | ||
import com.finfellows.domain.policyinfo.dto.SearchPolicyInfoRes; | ||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQuery; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.support.PageableExecutionUtils; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
import static com.finfellows.domain.policyinfo.domain.QPolicyInfo.*; | ||
|
||
@RequiredArgsConstructor | ||
@Repository | ||
public class PolicyInfoQueryDslRepositoryImpl implements PolicyInfoQueryDslRepository { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public Page<SearchPolicyInfoRes> findPolicyInfos(String searchKeyword, Pageable pageable, Long userId) { | ||
QPolicyInfoBookmark policyInfoBookmark = QPolicyInfoBookmark.policyInfoBookmark; | ||
|
||
List<SearchPolicyInfoRes> results = queryFactory | ||
.select(new QSearchPolicyInfoRes( | ||
policyInfo.id, | ||
policyInfo.polyBizSjNm, | ||
policyInfo.polyItcnCn, | ||
policyInfoBookmark.id.isNotNull() | ||
)) | ||
.from(policyInfo) | ||
.leftJoin(policyInfoBookmark) | ||
.on(policyInfoBookmark.policyInfo.eq(policyInfo).and(policyInfoBookmark.user.id.eq(userId))) | ||
.where( | ||
searchEq(searchKeyword) | ||
) | ||
.orderBy(policyInfo.polyBizSjNm.asc()) | ||
.offset(pageable.getOffset()) | ||
.limit(pageable.getPageSize()) | ||
.fetch(); | ||
|
||
JPAQuery<Long> countQuery = queryFactory | ||
.select(policyInfo.count()) | ||
.from(policyInfo) | ||
.where( | ||
searchEq(searchKeyword) | ||
); | ||
|
||
return PageableExecutionUtils.getPage(results, pageable, countQuery::fetchCount); | ||
} | ||
|
||
private BooleanExpression searchEq(String searchKeyword) { | ||
return searchKeyword != null ? policyInfo.polyBizSjNm.contains(searchKeyword).or(policyInfo.polyItcnCn.contains(searchKeyword)) : null; | ||
} | ||
|
||
} |
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
22 changes: 22 additions & 0 deletions
22
src/main/java/com/finfellows/domain/policyinfo/dto/SearchPolicyInfoRes.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,22 @@ | ||
package com.finfellows.domain.policyinfo.dto; | ||
|
||
import com.querydsl.core.annotations.QueryProjection; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class SearchPolicyInfoRes { | ||
|
||
private Long policyInfoId; | ||
private String policyName; | ||
private String policyContent; | ||
private Boolean isLiked; | ||
|
||
@QueryProjection | ||
public SearchPolicyInfoRes(Long policyInfoId, String policyName, String policyContent, Boolean isLiked) { | ||
this.policyInfoId = policyInfoId; | ||
this.policyName = policyName; | ||
this.policyContent = policyContent; | ||
this.isLiked = isLiked; | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/finfellows/domain/policyinfo/presentation/PolicyInfoController.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,39 @@ | ||
package com.finfellows.domain.policyinfo.presentation; | ||
|
||
import com.finfellows.global.payload.ErrorResponse; | ||
import com.finfellows.global.payload.ResponseCustom; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.media.ArraySchema; | ||
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.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@Tag(name = "Policy Information", description = "Policy Information API") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/policy-info") | ||
public class PolicyInfoController { | ||
|
||
// @Operation(summary = "정책 리스트 조회", description = "정책 리스트를 조건에 따라 조회합니다.") | ||
// @ApiResponses(value = { | ||
// @ApiResponse(responseCode = "200", description = "정책 리스트 조회 성공", content = {@Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = String.class)))}), | ||
// @ApiResponse(responseCode = "400", description = "정책 리스트 조회 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}), | ||
// }) | ||
// @GetMapping("/bank") | ||
// public ResponseCustom<List<String>> findBanks( | ||
// @Parameter(description = "조회 할 페이지와 페이지 크기를 입력해주세요") Pageable pageable | ||
// ) { | ||
// return ResponseCustom.OK(financialProductServiceImpl.findBanks(bankGroupNo)); | ||
// } | ||
|
||
} |