diff --git a/src/main/java/com/finfellows/domain/policyinfo/application/PolicyInfoService.java b/src/main/java/com/finfellows/domain/policyinfo/application/PolicyInfoService.java index 4d61895..868eb7c 100644 --- a/src/main/java/com/finfellows/domain/policyinfo/application/PolicyInfoService.java +++ b/src/main/java/com/finfellows/domain/policyinfo/application/PolicyInfoService.java @@ -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; @@ -10,5 +11,7 @@ public interface PolicyInfoService { PagedResponse findPolicyInfos(UserPrincipal userPrincipal, String searchKeyword, Pageable pageable); PolicyInfoDetailRes findPolicyDetail(UserPrincipal userPrincipal, Long policyId); + void deletePolicy(Long policyId); + void updatePolicy(Long policyId, PolicyUpdateReq policyUpdateReq); } diff --git a/src/main/java/com/finfellows/domain/policyinfo/application/PolicyInfoServiceImpl.java b/src/main/java/com/finfellows/domain/policyinfo/application/PolicyInfoServiceImpl.java index 0d4e599..2d28a4d 100644 --- a/src/main/java/com/finfellows/domain/policyinfo/application/PolicyInfoServiceImpl.java +++ b/src/main/java/com/finfellows/domain/policyinfo/application/PolicyInfoServiceImpl.java @@ -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; @@ -11,6 +15,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; + @RequiredArgsConstructor @Service @Transactional(readOnly = true) @@ -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); + } + +} \ No newline at end of file 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 42caa3a..d44c7b9 100644 --- a/src/main/java/com/finfellows/domain/policyinfo/domain/PolicyInfo.java +++ b/src/main/java/com/finfellows/domain/policyinfo/domain/PolicyInfo.java @@ -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; @@ -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; @@ -77,4 +99,5 @@ public PolicyInfo(String polyBizSjNm, String polyItcnCn, String sporCn, String b this.rqutUrla = rqutUrla; this.pstnPaprCn = pstnPaprCn; } + } diff --git a/src/main/java/com/finfellows/domain/policyinfo/dto/PolicyUpdateReq.java b/src/main/java/com/finfellows/domain/policyinfo/dto/PolicyUpdateReq.java new file mode 100644 index 0000000..7222614 --- /dev/null +++ b/src/main/java/com/finfellows/domain/policyinfo/dto/PolicyUpdateReq.java @@ -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; + +} diff --git a/src/main/java/com/finfellows/domain/policyinfo/exception/InvalidPolicyInfoException.java b/src/main/java/com/finfellows/domain/policyinfo/exception/InvalidPolicyInfoException.java new file mode 100644 index 0000000..596ce0b --- /dev/null +++ b/src/main/java/com/finfellows/domain/policyinfo/exception/InvalidPolicyInfoException.java @@ -0,0 +1,9 @@ +package com.finfellows.domain.policyinfo.exception; + +public class InvalidPolicyInfoException extends RuntimeException { + + public InvalidPolicyInfoException() { + super("정책 정보가 올바르지 않습니다."); + } + +} diff --git a/src/main/java/com/finfellows/domain/policyinfo/presentation/PolicyInfoController.java b/src/main/java/com/finfellows/domain/policyinfo/presentation/PolicyInfoController.java index 895bd21..e374e4c 100644 --- a/src/main/java/com/finfellows/domain/policyinfo/presentation/PolicyInfoController.java +++ b/src/main/java/com/finfellows/domain/policyinfo/presentation/PolicyInfoController.java @@ -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; @@ -55,4 +56,31 @@ public ResponseCustom 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 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 updatePolicy( + @Parameter(description = "정책 ID를 입력해 주세요") @PathVariable("policy-id") Long policyId, + @Parameter(description = "PolicyUpdateReq Schema를 참고해 주세요.") @RequestBody PolicyUpdateReq policyInfoUpdateReq + ) { + this.policyInfoServiceImpl.updatePolicy(policyId, policyInfoUpdateReq); + return ResponseCustom.OK(); + } + }