Skip to content

Commit

Permalink
feat : 특정 날짜(2023-12-12)에 따른 신청 시작일과 신청 종료일을 가지는 정책 리스트 조회 API 구현 ( 모…
Browse files Browse the repository at this point in the history
…달창 )
  • Loading branch information
LHS-11 committed Dec 5, 2023
1 parent d7b3682 commit 5ab9675
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cmc.zenefitserver.domain.policy.api;

import com.cmc.zenefitserver.domain.policy.application.PolicyService;
import com.cmc.zenefitserver.domain.policy.domain.enums.SearchDateType;
import com.cmc.zenefitserver.domain.policy.dto.*;
import com.cmc.zenefitserver.domain.user.domain.User;
import com.cmc.zenefitserver.global.annotation.AuthUser;
Expand Down Expand Up @@ -54,9 +55,16 @@ public CommonResponse<PolicyInfoResponseDto> getPolicy(@AuthUser User user, @Pat
}

@GetMapping("/calendar")
@Operation(summary = "특정 날짜에 따른 관심 정책 조회 API", description = "달력에서 해당 날짜(달)에 신청 시작일 또는 신청 종료일을 가지는 정책을 조회합니다.")
public CommonResponse<List<CalendarPolicyListResponseDto>> getPolicesBySearchDate(@AuthUser User user, @RequestParam("searchDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate searchDate) {
List<CalendarPolicyListResponseDto> result = policyService.getPolicyListBySearchDate(user, searchDate);
@Operation(summary = "특정 달에 따른 관심 정책 리스트 조회 API", description = "달력에서 해당 달에 신청 시작일 또는 신청 종료일을 가지는 정책을 조회합니다.")
public CommonResponse<List<CalendarPolicyListResponseDto>> getPolicesBySearchMonth(@AuthUser User user, @RequestParam("searchDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate searchDate) {
List<CalendarPolicyListResponseDto> result = policyService.getPolicyListBySearchMonth(user, searchDate);
return CommonResponse.success(result);
}

@GetMapping("/calendar/date")
@Operation(summary = "특정 날짜에 따른 관심 정책 리스트 조회 API", description = "달력에서 해당 날짜에 신청 시작일 또는 신청 종료일을 가지는 정책을 조회합니다.")
public CommonResponse<List<CalendarPolicyListResponseDto>> getPolicesBySearchDate(@AuthUser User user, @RequestParam("searchDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate searchDate, @RequestParam SearchDateType searchDateType) {
List<CalendarPolicyListResponseDto> result = policyService.getPolicyListBySearchDate(user, searchDate, searchDateType);
return CommonResponse.success(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.cmc.zenefitserver.domain.policy.dao.PolicyRepository;
import com.cmc.zenefitserver.domain.policy.domain.Policy;
import com.cmc.zenefitserver.domain.policy.domain.enums.DenialReasonType;
import com.cmc.zenefitserver.domain.policy.domain.enums.SearchDateType;
import com.cmc.zenefitserver.domain.policy.domain.enums.SupportPolicyType;
import com.cmc.zenefitserver.domain.policy.dto.*;
import com.cmc.zenefitserver.domain.user.domain.User;
Expand Down Expand Up @@ -82,14 +83,14 @@ public PolicyInfoResponseDto getPolicy(User user, Long policyId) {
return dto;
}

public List<CalendarPolicyListResponseDto> getPolicyListBySearchDate(User user, LocalDate searchDate) {
public List<CalendarPolicyListResponseDto> getPolicyListBySearchMonth(User user, LocalDate searchDate) {

LocalDate searchSttDate = searchDate.withDayOfMonth(1);
LocalDate searchEndDate = searchDate.withDayOfMonth(searchDate.lengthOfMonth());

List<CalendarPolicyListResponseDto> result = null;

List<Policy> polices = policyRepository.findAllBySearchDate(user.getUserId(), searchSttDate, searchEndDate);
List<Policy> polices = policyRepository.findAllBySearchMonth(user.getUserId(), searchSttDate, searchEndDate);

if (polices != null) {
result = polices.stream()
Expand All @@ -113,6 +114,37 @@ public List<CalendarPolicyListResponseDto> getPolicyListBySearchDate(User user,
return result;
}

public List<CalendarPolicyListResponseDto> getPolicyListBySearchDate(User user, LocalDate searchDate, SearchDateType searchDateType) {

List<Policy> policies = null;
if (SearchDateType.STT_DATE.equals(searchDateType)) {
policies = policyRepository.findAllBySearchSttDate(user.getUserId(), searchDate);
}

if (SearchDateType.END_DATE.equals(searchDateType)) {
policies = policyRepository.findAllBySearchEndDate(user.getUserId(), searchDate);
}

return policies.stream()
.map(policy -> {
DenialReasonType denialReasonType = PolicyDenialReasonClassifier.getDenialReasonType(user, policy);
CalendarPolicyListResponseDto dto = CalendarPolicyListResponseDto.builder()
.policyId(policy.getId())
.policyName(policy.getPolicyName())
.applyProcedure("더미데이터 (방문신청, 우편신청, 홈페이지 신청등)")
.policyAgencyLogo(policy.getPolicyLogo())
.applySttDate(policy.getApplySttDate())
.applyEndDate(policy.getApplyEndDate())
.build();

dto.upgradeApplyStatus(denialReasonType);
return dto;
})
.collect(Collectors.toList());


}

public RecommendPolicyInfoResponseDto recommend(User user) {

Map<SupportPolicyType, Policy> supportPolicyTypePolicyMap = policyRecommender.recommendPolicy(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ public interface PolicyRepository extends JpaRepository<Policy, Long> {
"AND (:searchSttDate BETWEEN P.applySttDate AND P.applyEndDate " +
"OR :searchEndDate BETWEEN P.applySttDate AND P.applyEndDate " +
"OR (:searchSttDate <= P.applySttDate AND :searchEndDate >= P.applyEndDate))")
List<Policy> findAllBySearchDate(@Param("userId") Long userId, @Param("searchSttDate") LocalDate searchSttDate, @Param("searchEndDate") LocalDate searchEndDate);
List<Policy> findAllBySearchMonth(@Param("userId") Long userId, @Param("searchSttDate") LocalDate searchSttDate, @Param("searchEndDate") LocalDate searchEndDate);

@Query("SELECT P FROM Policy P LEFT JOIN P.userPolicies UP " +
"WHERE UP.interestFlag = TRUE " +
"AND UP.user.userId = :userId " +
"AND P.applySttDate = :searchSttDate")
List<Policy> findAllBySearchSttDate(@Param("userId") Long userId, @Param("searchSttDate") LocalDate searchSttDate);

@Query("SELECT P FROM Policy P LEFT JOIN P.userPolicies UP " +
"WHERE UP.interestFlag = TRUE " +
"AND UP.user.userId = :userId " +
"AND P.applyEndDate = :searchEndDate")
List<Policy> findAllBySearchEndDate(@Param("userId") Long userId, @Param("searchEndDate") LocalDate searchEndDate);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.cmc.zenefitserver.domain.policy.domain.enums;

import lombok.Getter;

public enum SearchDateType {
STT_DATE,
Expand Down

0 comments on commit 5ab9675

Please sign in to comment.