-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pkl0912
committed
Oct 25, 2024
1 parent
131da33
commit 54f0c09
Showing
6 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/main/java/server/poptato/policy/api/PolicyController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package server.poptato.policy.api; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import server.poptato.global.response.BaseResponse; | ||
import server.poptato.policy.application.PolicyService; | ||
import server.poptato.policy.domain.entity.Policy; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class PolicyController { | ||
private final PolicyService policyService; | ||
|
||
@GetMapping("/policy") | ||
public BaseResponse<Policy> getTodayList(){ | ||
Policy policy = policyService.getPrivacyPolicy(); | ||
return new BaseResponse<>(policy); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/server/poptato/policy/application/PolicyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package server.poptato.policy.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import server.poptato.policy.domain.entity.Policy; | ||
import server.poptato.policy.domain.repository.PolicyRepository; | ||
import server.poptato.policy.exception.PolicyException; | ||
|
||
import static server.poptato.policy.exception.errorcode.PolicyExceptionErrorCode.POLICY_NOT_FOUND_EXCEPTION; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PolicyService { | ||
private final PolicyRepository policyRepository; | ||
public Policy getPrivacyPolicy() { | ||
return policyRepository.findTopByOrderByCreatedAtDesc() | ||
.orElseThrow(() -> new PolicyException(POLICY_NOT_FOUND_EXCEPTION)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/server/poptato/policy/exception/PolicyException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package server.poptato.policy.exception; | ||
|
||
import lombok.Getter; | ||
import server.poptato.global.response.status.ResponseStatus; | ||
|
||
@Getter | ||
public class PolicyException extends RuntimeException{ | ||
private final ResponseStatus exceptionStatus; | ||
|
||
public PolicyException(ResponseStatus exceptionStatus) { | ||
super(exceptionStatus.getMessage()); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/server/poptato/policy/exception/errorcode/PolicyExceptionErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package server.poptato.policy.exception.errorcode; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import server.poptato.global.response.status.ResponseStatus; | ||
|
||
@RequiredArgsConstructor | ||
public enum PolicyExceptionErrorCode implements ResponseStatus { | ||
|
||
/** | ||
* 7000: Policy 도메인 오류 | ||
*/ | ||
|
||
POLICY_NOT_FOUND_EXCEPTION(7000, HttpStatus.NOT_FOUND.value(), "개인정보처리방침이 존재하지 않습니다"); | ||
|
||
|
||
private final int code; | ||
private final int status; | ||
private final String message; | ||
|
||
|
||
@Override | ||
public int getCode() { | ||
return code; | ||
} | ||
|
||
@Override | ||
public int getStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/server/poptato/policy/exception/handler/PolicyExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package server.poptato.policy.exception.handler; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
import server.poptato.global.response.BaseErrorResponse; | ||
import server.poptato.policy.exception.PolicyException; | ||
|
||
@Slf4j | ||
@Order(1) | ||
@RestControllerAdvice | ||
public class PolicyExceptionHandler { | ||
@ResponseStatus(HttpStatus.NOT_FOUND) | ||
@ExceptionHandler(PolicyException.class) | ||
public BaseErrorResponse handlePolicyException(PolicyException e) { | ||
log.error("[PolicyException: handle_PolicyException 호출]", e); | ||
return new BaseErrorResponse(e.getExceptionStatus(), e.getMessage()); | ||
} | ||
} |