generated from pricelees/issue-pr-template
refactor: API / 에러 응답 객체 Swagger Schema 제거 및 코드 간소화
This commit is contained in:
parent
98b9655a2f
commit
a876516296
@ -2,26 +2,16 @@ package roomescape.common.dto.response
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema
|
||||
|
||||
@Schema(description = "API 응답 시에 사용합니다.")
|
||||
@Schema(name = "API 성공 응답")
|
||||
@JvmRecord
|
||||
data class RoomescapeApiResponse<T>(
|
||||
@field:Schema(description = "응답 메시지", defaultValue = SUCCESS_MESSAGE)
|
||||
val message: String,
|
||||
|
||||
@field:Schema(description = "응답 바디")
|
||||
val data: T? = null
|
||||
) {
|
||||
companion object {
|
||||
private const val SUCCESS_MESSAGE = "요청이 성공적으로 수행되었습니다."
|
||||
@JvmStatic
|
||||
fun <T> success(data: T): RoomescapeApiResponse<T> = RoomescapeApiResponse(data)
|
||||
|
||||
@JvmStatic
|
||||
fun <T> success(data: T): RoomescapeApiResponse<T> {
|
||||
return RoomescapeApiResponse(SUCCESS_MESSAGE, data)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun success(): RoomescapeApiResponse<Void> {
|
||||
return RoomescapeApiResponse(SUCCESS_MESSAGE, null)
|
||||
}
|
||||
fun success(): RoomescapeApiResponse<Void> = RoomescapeApiResponse(null)
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,19 +3,16 @@ package roomescape.common.dto.response
|
||||
import io.swagger.v3.oas.annotations.media.Schema
|
||||
import roomescape.common.exception.ErrorType
|
||||
|
||||
@Schema(name = "예외 응답", description = "예외 발생 시 응답에 사용됩니다.")
|
||||
@Schema(name = "API 에러 응답")
|
||||
@JvmRecord
|
||||
data class RoomescapeErrorResponse(
|
||||
@field:Schema(description = "발생한 예외의 종류", example = "INVALID_REQUEST_DATA")
|
||||
val errorType: ErrorType,
|
||||
|
||||
@field:Schema(description = "예외 메시지", example = "요청 데이터 값이 올바르지 않습니다.")
|
||||
val message: String
|
||||
) {
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun of(errorType: ErrorType, message: String): RoomescapeErrorResponse {
|
||||
return RoomescapeErrorResponse(errorType, message)
|
||||
}
|
||||
fun of(errorType: ErrorType, message: String? = null): RoomescapeErrorResponse =
|
||||
RoomescapeErrorResponse(errorType, message ?: errorType.description)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user