[#7] API 응답 형식 재정의 및 Swagger-UI 관련 코드 패키지 분리 #8

Merged
pricelees merged 16 commits from refactor/#7 into main 2025-07-15 05:37:42 +00:00
2 changed files with 8 additions and 21 deletions
Showing only changes of commit a876516296 - Show all commits

View File

@ -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)
}
}

View File

@ -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)
}
}