-
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.
[FEAT] success, error response 추가 #7
- Loading branch information
Showing
15 changed files
with
134 additions
and
26 deletions.
There are no files selected for viewing
4 changes: 0 additions & 4 deletions
4
src/main/java/sopt/univoice/domain/university/entity/CollegeDepartment.java
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
src/main/java/sopt/univoice/domain/university/entity/Department.java
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
src/main/java/sopt/univoice/domain/university/entity/University.java
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
src/main/java/sopt/univoice/domain/universityData/entity/CollegeDepartment.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,4 @@ | ||
package sopt.univoice.domain.universityData.entity; | ||
|
||
public class CollegeDepartment { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/sopt/univoice/domain/universityData/entity/Department.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,4 @@ | ||
package sopt.univoice.domain.universityData.entity; | ||
|
||
public class Department { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/sopt/univoice/domain/universityData/entity/University.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,4 @@ | ||
package sopt.univoice.domain.universityData.entity; | ||
|
||
public class University { | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/sopt/univoice/infra/common/dto/ErrorResponse.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,15 @@ | ||
package sopt.univoice.infra.common.dto; | ||
|
||
import sopt.univoice.infra.common.exception.message.ErrorMessage; | ||
|
||
public record ErrorResponse( | ||
int status, | ||
String message | ||
) { | ||
public static ErrorResponse of(int status, String message) { | ||
return new ErrorResponse(status, message); | ||
} | ||
public static ErrorResponse of(ErrorMessage errorMessage) { | ||
return new ErrorResponse(errorMessage.getStatus(), errorMessage.getMessage()); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/sopt/univoice/infra/common/dto/SuccessMessage.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 sopt.univoice.infra.common.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum SuccessMessage { | ||
|
||
; | ||
private final int status; | ||
private final String message; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/sopt/univoice/infra/common/dto/SuccessStatusResponse.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 sopt.univoice.infra.common.dto; | ||
|
||
public record SuccessStatusResponse<T>( | ||
int status, | ||
String message, | ||
T data | ||
) { | ||
public static <T> SuccessStatusResponse<T> of(SuccessMessage successMessage, T data) { | ||
return new SuccessStatusResponse<>(successMessage.getStatus(), successMessage.getMessage(), data); | ||
} | ||
public static SuccessStatusResponse<Void> of(SuccessMessage successMessage) { | ||
return new SuccessStatusResponse<>(successMessage.getStatus(), successMessage.getMessage(), null); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/sopt/univoice/infra/common/exception/GlobalExceptionHandler.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,23 @@ | ||
package sopt.univoice.infra.common.exception; | ||
|
||
import jakarta.persistence.EntityNotFoundException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
import sopt.univoice.infra.common.dto.ErrorResponse; | ||
import sopt.univoice.infra.common.exception.message.BusinessException; | ||
|
||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { | ||
|
||
@ExceptionHandler(EntityNotFoundException.class) | ||
protected ResponseEntity<ErrorResponse> handleEntityNotFoundException(EntityNotFoundException e) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ErrorResponse.of(HttpStatus.NOT_FOUND.value(), e.getMessage())); | ||
} | ||
|
||
@ExceptionHandler(BusinessException.class) | ||
protected ResponseEntity<ErrorResponse> handleBusinessException(BusinessException e) { | ||
return ResponseEntity.status(HttpStatus.CONFLICT).body(ErrorResponse.of(e.getErrorMessage())); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/sopt/univoice/infra/common/exception/NotFoundException.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,10 @@ | ||
package sopt.univoice.infra.common.exception; | ||
|
||
import sopt.univoice.infra.common.exception.message.BusinessException; | ||
import sopt.univoice.infra.common.exception.message.ErrorMessage; | ||
|
||
public class NotFoundException extends BusinessException { | ||
public NotFoundException(ErrorMessage errorMessage) { | ||
super(errorMessage); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/sopt/univoice/infra/common/exception/message/BusinessException.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,16 @@ | ||
package sopt.univoice.infra.common.exception.message; | ||
|
||
import sopt.univoice.infra.common.exception.message.ErrorMessage; | ||
|
||
public class BusinessException extends RuntimeException { | ||
private ErrorMessage errorMessage; | ||
|
||
public BusinessException(ErrorMessage errorMessage) { | ||
super(errorMessage.getMessage()); | ||
this.errorMessage = errorMessage; | ||
} | ||
|
||
public ErrorMessage getErrorMessage() { | ||
return errorMessage; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/sopt/univoice/infra/common/exception/message/ErrorMessage.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 sopt.univoice.infra.common.exception.message; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public enum ErrorMessage { | ||
|
||
; | ||
private final int status; | ||
private final String message; | ||
} |
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
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