diff --git a/src/main/java/com/finfellows/domain/bookmark/dto/PolicyInfoBookmarkRes.java b/src/main/java/com/finfellows/domain/bookmark/dto/PolicyInfoBookmarkRes.java index c525ebe..718e415 100644 --- a/src/main/java/com/finfellows/domain/bookmark/dto/PolicyInfoBookmarkRes.java +++ b/src/main/java/com/finfellows/domain/bookmark/dto/PolicyInfoBookmarkRes.java @@ -25,8 +25,8 @@ public PolicyInfoBookmarkRes(String contentName, String content) { public static List toDto(List bookmarks) { return bookmarks.stream() .map(bookmark -> PolicyInfoBookmarkRes.builder() - .contentName(bookmark.getPolicyInfo().getContentName()) - .content(bookmark.getPolicyInfo().getContent()) + .contentName(bookmark.getPolicyInfo().getPolyBizSjNm()) + .content(bookmark.getPolicyInfo().getPolyItcnCn()) .build()) .collect(Collectors.toList()); } diff --git a/src/main/java/com/finfellows/domain/policyinfo/application/PolicyInfoService.java b/src/main/java/com/finfellows/domain/policyinfo/application/PolicyInfoService.java new file mode 100644 index 0000000..c7170e8 --- /dev/null +++ b/src/main/java/com/finfellows/domain/policyinfo/application/PolicyInfoService.java @@ -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 { + + +} diff --git a/src/main/java/com/finfellows/domain/policyinfo/domain/PolicyInfo.java b/src/main/java/com/finfellows/domain/policyinfo/domain/PolicyInfo.java index 9786189..42caa3a 100644 --- a/src/main/java/com/finfellows/domain/policyinfo/domain/PolicyInfo.java +++ b/src/main/java/com/finfellows/domain/policyinfo/domain/PolicyInfo.java @@ -20,15 +20,61 @@ public class PolicyInfo extends BaseEntity { @Column(name = "id", updatable = false) private Long id; - @Column(name = "content_name", nullable = false, unique = true) - private String contentName; + private String polyBizSjNm; - @Column(name="content", nullable = false, unique = true) - private String content; + private String polyItcnCn; + + private String sporCn; + + private String bizPrdCn; + + private String rqutPrdCn; + + private String sporScvl; + + private String ageInfo; + + private String prcpCn; + + private String accrRqisCn; + + private String majrRqisCn; + + private String empmSttsCn; + + private String splzRlmRqisCn; + + private String aditRscn; + + private String prcpLmttTrgtCn; + + private String rqutProcCn; + + private String jdgnPresCn; + + private String rqutUrla; + + private String pstnPaprCn; @Builder - public PolicyInfo(String contentName, String content) { - this.contentName = contentName; - this.content = content; + public PolicyInfo(String polyBizSjNm, String polyItcnCn, String sporCn, String bizPrdCn, String rqutPrdCn, String sporScvl, String ageInfo, String prcpCn, String accrRqisCn, String majrRqisCn, String empmSttsCn, String splzRlmRqisCn, String aditRscn, String prcpLmttTrgtCn, String rqutProcCn, String jdgnPresCn, String rqutUrla, String pstnPaprCn) { + this.polyBizSjNm = polyBizSjNm; + this.polyItcnCn = polyItcnCn; + this.sporCn = sporCn; + this.bizPrdCn = bizPrdCn; + this.rqutPrdCn = rqutPrdCn; + this.sporScvl = sporScvl; + this.ageInfo = ageInfo; + this.prcpCn = prcpCn; + this.accrRqisCn = accrRqisCn; + this.majrRqisCn = majrRqisCn; + this.empmSttsCn = empmSttsCn; + this.splzRlmRqisCn = splzRlmRqisCn; + this.aditRscn = aditRscn; + this.prcpLmttTrgtCn = prcpLmttTrgtCn; + this.rqutProcCn = rqutProcCn; + this.jdgnPresCn = jdgnPresCn; + this.rqutUrla = rqutUrla; + this.pstnPaprCn = pstnPaprCn; } } diff --git a/src/main/java/com/finfellows/domain/policyinfo/domain/repository/PolicyInfoQueryDslRepository.java b/src/main/java/com/finfellows/domain/policyinfo/domain/repository/PolicyInfoQueryDslRepository.java new file mode 100644 index 0000000..851fbba --- /dev/null +++ b/src/main/java/com/finfellows/domain/policyinfo/domain/repository/PolicyInfoQueryDslRepository.java @@ -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 findPolicyInfos(String searchKeyword, Pageable pageable, Long userId); + +} diff --git a/src/main/java/com/finfellows/domain/policyinfo/domain/repository/PolicyInfoQueryDslRepositoryImpl.java b/src/main/java/com/finfellows/domain/policyinfo/domain/repository/PolicyInfoQueryDslRepositoryImpl.java new file mode 100644 index 0000000..0699620 --- /dev/null +++ b/src/main/java/com/finfellows/domain/policyinfo/domain/repository/PolicyInfoQueryDslRepositoryImpl.java @@ -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 findPolicyInfos(String searchKeyword, Pageable pageable, Long userId) { + QPolicyInfoBookmark policyInfoBookmark = QPolicyInfoBookmark.policyInfoBookmark; + + List 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 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; + } + +} diff --git a/src/main/java/com/finfellows/domain/policyinfo/domain/repository/PolicyInfoRepository.java b/src/main/java/com/finfellows/domain/policyinfo/domain/repository/PolicyInfoRepository.java index e65703b..2003a77 100644 --- a/src/main/java/com/finfellows/domain/policyinfo/domain/repository/PolicyInfoRepository.java +++ b/src/main/java/com/finfellows/domain/policyinfo/domain/repository/PolicyInfoRepository.java @@ -3,5 +3,5 @@ import com.finfellows.domain.policyinfo.domain.PolicyInfo; import org.springframework.data.jpa.repository.JpaRepository; -public interface PolicyInfoRepository extends JpaRepository { +public interface PolicyInfoRepository extends JpaRepository , PolicyInfoQueryDslRepository { } diff --git a/src/main/java/com/finfellows/domain/policyinfo/dto/SearchPolicyInfoRes.java b/src/main/java/com/finfellows/domain/policyinfo/dto/SearchPolicyInfoRes.java new file mode 100644 index 0000000..6b6f93c --- /dev/null +++ b/src/main/java/com/finfellows/domain/policyinfo/dto/SearchPolicyInfoRes.java @@ -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; + } + +} diff --git a/src/main/java/com/finfellows/domain/policyinfo/presentation/PolicyInfoController.java b/src/main/java/com/finfellows/domain/policyinfo/presentation/PolicyInfoController.java new file mode 100644 index 0000000..aad7398 --- /dev/null +++ b/src/main/java/com/finfellows/domain/policyinfo/presentation/PolicyInfoController.java @@ -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> findBanks( +// @Parameter(description = "조회 할 페이지와 페이지 크기를 입력해주세요") Pageable pageable +// ) { +// return ResponseCustom.OK(financialProductServiceImpl.findBanks(bankGroupNo)); +// } + +}