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

Commit

Permalink
Merge pull request #61 from FinFellows/develop
Browse files Browse the repository at this point in the history
[FEAT]: 정책 상세 정보 API 구현 (#60)
  • Loading branch information
sejineer authored Jan 7, 2024
2 parents 8e93b44 + 6fbe5fc commit 5e7f23e
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.finfellows.domain.policyinfo.application;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.finfellows.domain.policyinfo.dto.PolicyInfoDetailRes;
import com.finfellows.domain.policyinfo.dto.SearchPolicyInfoRes;
import com.finfellows.global.config.security.token.UserPrincipal;
import com.finfellows.global.payload.PagedResponse;
import org.springframework.data.domain.Pageable;

@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
public class PolicyInfoService {
public interface PolicyInfoService {

PagedResponse<SearchPolicyInfoRes> findPolicyInfos(UserPrincipal userPrincipal, String searchKeyword, Pageable pageable);
PolicyInfoDetailRes findPolicyDetail(UserPrincipal userPrincipal, Long policyId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.finfellows.domain.policyinfo.application;

import com.finfellows.domain.policyinfo.domain.repository.PolicyInfoRepository;
import com.finfellows.domain.policyinfo.dto.PolicyInfoDetailRes;
import com.finfellows.domain.policyinfo.dto.SearchPolicyInfoRes;
import com.finfellows.global.config.security.token.UserPrincipal;
import com.finfellows.global.payload.PagedResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
public class PolicyInfoServiceImpl implements PolicyInfoService {

private final PolicyInfoRepository policyInfoRepository;

@Override
public PagedResponse<SearchPolicyInfoRes> findPolicyInfos(UserPrincipal userPrincipal, String searchKeyword, Pageable pageable) {
Page<SearchPolicyInfoRes> policyInfos = policyInfoRepository.findPolicyInfos(searchKeyword, pageable, userPrincipal.getId());

return new PagedResponse<>(policyInfos);
}

@Override
public PolicyInfoDetailRes findPolicyDetail(UserPrincipal userPrincipal, Long policyId) {
return policyInfoRepository.findPolicyDetail(policyId, userPrincipal.getId());
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.finfellows.domain.policyinfo.domain.repository;

import com.finfellows.domain.policyinfo.dto.PolicyInfoDetailRes;
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);

PolicyInfoDetailRes findPolicyDetail(Long policyId, Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.finfellows.domain.bookmark.domain.QPolicyInfoBookmark;
import com.finfellows.domain.policyinfo.domain.QPolicyInfo;
import com.finfellows.domain.policyinfo.dto.PolicyInfoDetailRes;
import com.finfellows.domain.policyinfo.dto.QPolicyInfoDetailRes;
import com.finfellows.domain.policyinfo.dto.QSearchPolicyInfoRes;
import com.finfellows.domain.policyinfo.dto.SearchPolicyInfoRes;
import com.querydsl.core.types.dsl.BooleanExpression;
Expand Down Expand Up @@ -55,6 +57,42 @@ public Page<SearchPolicyInfoRes> findPolicyInfos(String searchKeyword, Pageable
return PageableExecutionUtils.getPage(results, pageable, countQuery::fetchCount);
}

@Override
public PolicyInfoDetailRes findPolicyDetail(Long policyId, Long userId) {
QPolicyInfoBookmark policyInfoBookmark = QPolicyInfoBookmark.policyInfoBookmark;

List<PolicyInfoDetailRes> result = queryFactory
.select(new QPolicyInfoDetailRes(
policyInfoBookmark.id.isNotNull(),
policyInfo.polyBizSjNm,
policyInfo.polyItcnCn,
policyInfo.sporCn,
policyInfo.bizPrdCn,
policyInfo.rqutPrdCn,
policyInfo.sporScvl,
policyInfo.ageInfo,
policyInfo.prcpCn,
policyInfo.accrRqisCn,
policyInfo.majrRqisCn,
policyInfo.empmSttsCn,
policyInfo.splzRlmRqisCn,
policyInfo.aditRscn,
policyInfo.prcpLmttTrgtCn,
policyInfo.rqutProcCn,
policyInfo.jdgnPresCn,
policyInfo.rqutUrla,
policyInfo.pstnPaprCn
))
.from(policyInfo)
.leftJoin(policyInfoBookmark)
.on(policyInfoBookmark.policyInfo.eq(policyInfo).and(policyInfoBookmark.user.id.eq(userId)))
.where(
policyInfo.id.eq(policyId)
)
.fetch();
return result.get(0);
}

private BooleanExpression searchEq(String searchKeyword) {
return searchKeyword != null ? policyInfo.polyBizSjNm.contains(searchKeyword).or(policyInfo.polyItcnCn.contains(searchKeyword)) : null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.finfellows.domain.policyinfo.dto;

import com.querydsl.core.annotations.QueryProjection;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
public class PolicyInfoDetailRes {

@Schema(description = "좋아요 여부")
private Boolean isLiked;
@Schema(description = "정책 이름")
private String polyBizSjNm;
@Schema(description = "정책 한 줄 소개")
private String polyItcnCn;
@Schema(description = "정책 내용")
private String sporCn;
@Schema(description = "운영 기간")
private String bizPrdCn;
@Schema(description = "신청 기간")
private String rqutPrdCn;
@Schema(description = "지원 규모")
private String sporScvl;
@Schema(description = "연령")
private String ageInfo;
@Schema(description = "거주지 및 소득")
private String prcpCn;
@Schema(description = "학력")
private String accrRqisCn;
@Schema(description = "전공")
private String majrRquisCn;
@Schema(description = "취업 상태")
private String empmSttsCn;
@Schema(description = "특화 분야")
private String spizRlmRqisCn;
@Schema(description = "추가 단서 사항")
private String aditRscn;
@Schema(description = "참여 제한 대상")
private String prcpLmttTrgtCn;
@Schema(description = "신청 절차")
private String rqutProcCn;
@Schema(description = "심사 및 발표")
private String jdgnPresCn;
@Schema(description = "신청 사이트")
private String rqutUrla;
@Schema(description = "제출 서류")
private String pstnPaprCn;

@QueryProjection
public PolicyInfoDetailRes(Boolean isLiked, String polyBizSjNm, String polyItcnCn, String sporCn, String bizPrdCn, String rqutPrdCn, String sporScvl, String ageInfo, String prcpCn, String accrRqisCn, String majrRquisCn, String empmSttsCn, String spizRlmRqisCn, String aditRscn, String prcpLmttTrgtCn, String rqutProcCn, String jdgnPresCn, String rqutUrla, String pstnPaprCn) {
this.isLiked = isLiked;
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.majrRquisCn = majrRquisCn;
this.empmSttsCn = empmSttsCn;
this.spizRlmRqisCn = spizRlmRqisCn;
this.aditRscn = aditRscn;
this.prcpLmttTrgtCn = prcpLmttTrgtCn;
this.rqutProcCn = rqutProcCn;
this.jdgnPresCn = jdgnPresCn;
this.rqutUrla = rqutUrla;
this.pstnPaprCn = pstnPaprCn;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package com.finfellows.domain.policyinfo.presentation;

import com.finfellows.domain.policyinfo.application.PolicyInfoServiceImpl;
import com.finfellows.domain.policyinfo.dto.PolicyInfoDetailRes;
import com.finfellows.domain.policyinfo.dto.SearchPolicyInfoRes;
import com.finfellows.global.config.security.token.CurrentUser;
import com.finfellows.global.config.security.token.UserPrincipal;
import com.finfellows.global.payload.ErrorResponse;
import com.finfellows.global.payload.PagedResponse;
import com.finfellows.global.payload.ResponseCustom;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -12,28 +18,41 @@
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;
import org.springframework.web.bind.annotation.*;

@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));
// }
private final PolicyInfoServiceImpl policyInfoServiceImpl;

@Operation(summary = "정책 리스트 조회", description = "정책 리스트를 조건에 따라 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "정책 리스트 조회 성공", content = {@Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = SearchPolicyInfoRes.class)))}),
@ApiResponse(responseCode = "400", description = "정책 리스트 조회 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@GetMapping
public ResponseCustom<PagedResponse<SearchPolicyInfoRes>> findPolicyInfos(
@Parameter(description = "AccessToken 을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal,
@Parameter(description = "검색어를 입력해 주세요") @RequestParam(required = false) String searchKeyword,
@Parameter(description = "조회 할 페이지와 페이지 크기를 입력해주세요") Pageable pageable
) {
return ResponseCustom.OK(policyInfoServiceImpl.findPolicyInfos(userPrincipal, searchKeyword, pageable));
}

@Operation(summary = "정책 정보 상세 조회", description = "정책 상세정보를 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "정책 상세 정보 조회 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = PolicyInfoDetailRes.class))}),
@ApiResponse(responseCode = "400", description = "정책 상세 정보 조회 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@GetMapping("/{policy-id}")
public ResponseCustom<PolicyInfoDetailRes> findPolicyDetail(
@Parameter(description = "AccessToken 을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal,
@Parameter(description = "정책 ID를 입력해 주세요") @PathVariable("policy-id") Long policyId
) {
return ResponseCustom.OK(policyInfoServiceImpl.findPolicyDetail(userPrincipal, policyId));
}

}

0 comments on commit 5e7f23e

Please sign in to comment.