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

Commit

Permalink
[FEAT]: 정책 삭제/수정 API 구현 (#62)
Browse files Browse the repository at this point in the history
* [FEAT]: PolicyInfo Entity 스팩 변경

* [FEAT]: PolicyInfo 리스트 조회 API 구현

* [FEAT]: PolicyInfo 리스트 조회 API 구현

* [FEAT]: 정책 상세 정보 API 구현

* [FEAT]: 정책 삭제/수정 API 구현
  • Loading branch information
sejineer authored Jan 7, 2024
1 parent 6fbe5fc commit 5072213
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.finfellows.domain.policyinfo.application;

import com.finfellows.domain.policyinfo.dto.PolicyInfoDetailRes;
import com.finfellows.domain.policyinfo.dto.PolicyUpdateReq;
import com.finfellows.domain.policyinfo.dto.SearchPolicyInfoRes;
import com.finfellows.global.config.security.token.UserPrincipal;
import com.finfellows.global.payload.PagedResponse;
Expand All @@ -10,5 +11,7 @@ public interface PolicyInfoService {

PagedResponse<SearchPolicyInfoRes> findPolicyInfos(UserPrincipal userPrincipal, String searchKeyword, Pageable pageable);
PolicyInfoDetailRes findPolicyDetail(UserPrincipal userPrincipal, Long policyId);
void deletePolicy(Long policyId);
void updatePolicy(Long policyId, PolicyUpdateReq policyUpdateReq);

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

import com.finfellows.domain.common.Status;
import com.finfellows.domain.policyinfo.domain.PolicyInfo;
import com.finfellows.domain.policyinfo.domain.repository.PolicyInfoRepository;
import com.finfellows.domain.policyinfo.dto.PolicyInfoDetailRes;
import com.finfellows.domain.policyinfo.dto.PolicyUpdateReq;
import com.finfellows.domain.policyinfo.dto.SearchPolicyInfoRes;
import com.finfellows.domain.policyinfo.exception.InvalidPolicyInfoException;
import com.finfellows.global.config.security.token.UserPrincipal;
import com.finfellows.global.payload.PagedResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -11,6 +15,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
Expand All @@ -30,4 +35,22 @@ public PolicyInfoDetailRes findPolicyDetail(UserPrincipal userPrincipal, Long po
return policyInfoRepository.findPolicyDetail(policyId, userPrincipal.getId());
}

}
@Override
@Transactional
public void deletePolicy(Long policyId) {
PolicyInfo policy = policyInfoRepository.findById(policyId)
.orElseThrow(InvalidPolicyInfoException::new);

policy.updateStatus(Status.DELETE);
}

@Override
@Transactional
public void updatePolicy(Long policyId, PolicyUpdateReq policyUpdateReq) {
PolicyInfo policyInfo = policyInfoRepository.findById(policyId)
.orElseThrow(InvalidPolicyInfoException::new);

policyInfo.updatePolicyInfo(policyUpdateReq);
}

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

import com.finfellows.domain.common.BaseEntity;
import com.finfellows.domain.policyinfo.dto.PolicyUpdateReq;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
Expand Down Expand Up @@ -56,6 +57,27 @@ public class PolicyInfo extends BaseEntity {

private String pstnPaprCn;

public void updatePolicyInfo(PolicyUpdateReq policyUpdateReq) {
this.polyBizSjNm = policyUpdateReq.getPolyBizSjNm();
this.polyItcnCn = policyUpdateReq.getPolyItcnCn();
this.sporCn = policyUpdateReq.getSporCn();
this.bizPrdCn = policyUpdateReq.getBizPrdCn();
this.rqutPrdCn = policyUpdateReq.getRqutPrdCn();
this.sporScvl = policyUpdateReq.getSporScvl();
this.ageInfo = policyUpdateReq.getAgeInfo();
this.prcpCn = policyUpdateReq.getPrcpCn();
this.accrRqisCn = policyUpdateReq.getAccrRqisCn();
this.majrRqisCn = policyUpdateReq.getMajrRquisCn();
this.empmSttsCn = policyUpdateReq.getEmpmSttsCn();
this.splzRlmRqisCn = policyUpdateReq.getSpizRlmRqisCn();
this.aditRscn = policyUpdateReq.getAditRscn();
this.prcpLmttTrgtCn = policyUpdateReq.getPrcpLmttTrgtCn();
this.rqutProcCn = policyUpdateReq.getRqutProcCn();
this.jdgnPresCn = policyUpdateReq.getJdgnPresCn();
this.rqutUrla = policyUpdateReq.getRqutUrla();
this.pstnPaprCn = policyUpdateReq.getPstnPaprCn();
}

@Builder
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;
Expand All @@ -77,4 +99,5 @@ public PolicyInfo(String polyBizSjNm, String polyItcnCn, String sporCn, String b
this.rqutUrla = rqutUrla;
this.pstnPaprCn = pstnPaprCn;
}

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

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
public class PolicyUpdateReq {

@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;

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

public class InvalidPolicyInfoException extends RuntimeException {

public InvalidPolicyInfoException() {
super("정책 정보가 올바르지 않습니다.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.finfellows.domain.policyinfo.application.PolicyInfoServiceImpl;
import com.finfellows.domain.policyinfo.dto.PolicyInfoDetailRes;
import com.finfellows.domain.policyinfo.dto.PolicyUpdateReq;
import com.finfellows.domain.policyinfo.dto.SearchPolicyInfoRes;
import com.finfellows.global.config.security.token.CurrentUser;
import com.finfellows.global.config.security.token.UserPrincipal;
Expand Down Expand Up @@ -55,4 +56,31 @@ public ResponseCustom<PolicyInfoDetailRes> findPolicyDetail(
return ResponseCustom.OK(policyInfoServiceImpl.findPolicyDetail(userPrincipal, policyId));
}

@Operation(summary = "정책 삭제", description = "정책을 삭제합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "정책 삭제 성공"),
@ApiResponse(responseCode = "400", description = "정책 삭제 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@PatchMapping("/{policy-id}")
public ResponseCustom<Void> deletePolicy(
@Parameter(description = "정책 ID를 입력해 주세요") @PathVariable("policy-id") Long policyId
) {
this.policyInfoServiceImpl.deletePolicy(policyId);
return ResponseCustom.OK();
}

@Operation(summary = "정책 수정", description = "정책을 수정합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "정책 수정 성공"),
@ApiResponse(responseCode = "400", description = "정책 수정 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@PutMapping("/{policy-id}")
public ResponseCustom<Void> updatePolicy(
@Parameter(description = "정책 ID를 입력해 주세요") @PathVariable("policy-id") Long policyId,
@Parameter(description = "PolicyUpdateReq Schema를 참고해 주세요.") @RequestBody PolicyUpdateReq policyInfoUpdateReq
) {
this.policyInfoServiceImpl.updatePolicy(policyId, policyInfoUpdateReq);
return ResponseCustom.OK();
}

}

0 comments on commit 5072213

Please sign in to comment.