-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
6 changed files
with
43 additions
and
17 deletions.
There are no files selected for viewing
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
8 changes: 6 additions & 2 deletions
8
Server/src/main/java/JGS/CasperEvent/domain/health/api/HealthController.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 |
---|---|---|
@@ -1,16 +1,20 @@ | ||
package JGS.CasperEvent.domain.health.api; | ||
|
||
import JGS.CasperEvent.global.response.CustomResponse; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import static JGS.CasperEvent.global.response.CustomResponse.response; | ||
|
||
@RestController | ||
@RequestMapping("/health") | ||
public class HealthController { | ||
|
||
@GetMapping | ||
public CustomResponse<Boolean> health(){ | ||
return CustomResponse.success(true); | ||
public ResponseEntity<CustomResponse<Boolean>> health(){ | ||
return new ResponseEntity<>(CustomResponse.success(true), HttpStatus.OK); | ||
} | ||
} |
6 changes: 5 additions & 1 deletion
6
Server/src/main/java/JGS/CasperEvent/global/error/exception/CustomException.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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
package JGS.CasperEvent.global.error.exception; | ||
|
||
public class CustomException extends RuntimeException{ | ||
public class CustomException extends RuntimeException { | ||
private final ErrorCode errorCode; | ||
|
||
public CustomException(String message, ErrorCode errorCode) { | ||
super(message); | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public ErrorCode getErrorCode() { | ||
return errorCode; | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
Server/src/main/java/JGS/CasperEvent/global/response/CustomErrorResponse.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,13 @@ | ||
package JGS.CasperEvent.global.response; | ||
|
||
import JGS.CasperEvent.global.error.exception.CustomException; | ||
|
||
public record CustomErrorResponse(String message) { | ||
public static CustomErrorResponse returnError(CustomException e){ | ||
return new CustomErrorResponse(e.getMessage()); | ||
} | ||
|
||
public static CustomErrorResponse returnError(String message){ | ||
return new CustomErrorResponse(message); | ||
} | ||
} |
10 changes: 7 additions & 3 deletions
10
Server/src/main/java/JGS/CasperEvent/global/response/CustomResponse.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 |
---|---|---|
@@ -1,12 +1,16 @@ | ||
package JGS.CasperEvent.global.response; | ||
|
||
public record CustomResponse<T> (int statusCode, String message, T result){ | ||
public record CustomResponse<T>(String message, T result) { | ||
public static <T> CustomResponse<T> response(String message, T result) { | ||
return new CustomResponse<>(message, result); | ||
} | ||
|
||
public static <T> CustomResponse<T> success(T result){ | ||
return new CustomResponse<>(200, "요청에 성공하였습니다.", result); | ||
return new CustomResponse<>("요청에 성공했습니다.", result); | ||
} | ||
|
||
public static <T> CustomResponse<T> create(T result){ | ||
return new CustomResponse<>(201, "생성에 성공하였습니다", result); | ||
return new CustomResponse<>("생성에 성공했습니다.", result); | ||
} | ||
} | ||
|