diff --git a/src/main/java/com/dnd/snappy/common/dto/ErrorResponseDto.java b/src/main/java/com/dnd/snappy/common/dto/ErrorResponseDto.java index 899acd3..d4c81b6 100644 --- a/src/main/java/com/dnd/snappy/common/dto/ErrorResponseDto.java +++ b/src/main/java/com/dnd/snappy/common/dto/ErrorResponseDto.java @@ -3,10 +3,10 @@ import com.dnd.snappy.common.error.ErrorCodeInterface; import org.springframework.http.ResponseEntity; -public record ErrorResponseDto(int status, String code, String message) { +public record ErrorResponseDto(String code, String message) { public static ErrorResponseDto from(ErrorCodeInterface errorCode) { - return new ErrorResponseDto(errorCode.getStatus().value(), errorCode.getErrorResponseCode(), errorCode.getMessage()); + return new ErrorResponseDto(errorCode.getErrorResponseCode(), errorCode.getMessage()); } public static ResponseEntity toResponseEntity(ErrorCodeInterface errorCode) { diff --git a/src/main/java/com/dnd/snappy/common/dto/ResponseDto.java b/src/main/java/com/dnd/snappy/common/dto/ResponseDto.java index eb928ce..402bb36 100644 --- a/src/main/java/com/dnd/snappy/common/dto/ResponseDto.java +++ b/src/main/java/com/dnd/snappy/common/dto/ResponseDto.java @@ -1,38 +1,38 @@ package com.dnd.snappy.common.dto; import com.dnd.snappy.common.error.ErrorCodeInterface; +import com.fasterxml.jackson.annotation.JsonInclude; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; public record ResponseDto( - boolean success, + int status, T data, - ErrorResponseDto error + @JsonInclude(JsonInclude.Include.NON_NULL) ErrorResponseDto error ) { public static ResponseEntity> ok(T data) { - ResponseDto responseDto = new ResponseDto<>(true, data, null); return ResponseEntity - .ok(responseDto); + .ok(new ResponseDto<>(HttpStatus.OK.value(), data, null)); } public static ResponseEntity> ok() { - ResponseDto responseDto = new ResponseDto<>(true, null, null); return ResponseEntity - .ok(responseDto); + .ok(new ResponseDto<>(HttpStatus.OK.value(), null, null)); } public static ResponseEntity> created(T data) { - ResponseDto responseDto = new ResponseDto<>(true, data, null); + ResponseDto responseDto = new ResponseDto<>(HttpStatus.CREATED.value(), data, null); return ResponseEntity .status(HttpStatus.CREATED) .body(responseDto); } public static ResponseEntity> fail(ErrorCodeInterface errorCode) { - ResponseDto responseDto = new ResponseDto<>(false, null, ErrorResponseDto.from(errorCode)); + ResponseDto responseDto = new ResponseDto<>(errorCode.getStatus().value(), null, ErrorResponseDto.from(errorCode)); return ResponseEntity .status(errorCode.getStatus()) .body(responseDto); } } + diff --git a/src/main/java/com/dnd/snappy/controller/v1/participant/ParticipantController.java b/src/main/java/com/dnd/snappy/controller/v1/participant/ParticipantController.java index 81d3e72..d168921 100644 --- a/src/main/java/com/dnd/snappy/controller/v1/participant/ParticipantController.java +++ b/src/main/java/com/dnd/snappy/controller/v1/participant/ParticipantController.java @@ -8,6 +8,7 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -42,7 +43,7 @@ public ResponseEntity> participateMeeting( return ResponseEntity.ok() .header(HttpHeaders.SET_COOKIE, cookie) .body(new ResponseDto<>( - true, + HttpStatus.OK.value(), new ParticipationResponse(response.participantId(), response.accessToken()), null )); diff --git a/src/test/java/com/dnd/snappy/controller/v1/meeting/MeetingControllerTest.java b/src/test/java/com/dnd/snappy/controller/v1/meeting/MeetingControllerTest.java index 80b051f..47d3743 100644 --- a/src/test/java/com/dnd/snappy/controller/v1/meeting/MeetingControllerTest.java +++ b/src/test/java/com/dnd/snappy/controller/v1/meeting/MeetingControllerTest.java @@ -67,7 +67,7 @@ void findByMeetingLink() throws Exception { parameterWithName("meetingLink").description("모임 링크") ), responseFields( - fieldWithPath("success").type(JsonFieldType.BOOLEAN).description("성공 여부"), + fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("data").type(JsonFieldType.OBJECT).description("모임"), fieldWithPath("data.meetingId").type(JsonFieldType.NUMBER).description("모임 id"), fieldWithPath("data.name").type(JsonFieldType.STRING).description("모임 이름"), @@ -76,8 +76,7 @@ void findByMeetingLink() throws Exception { fieldWithPath("data.symbolColor").type(JsonFieldType.STRING).description("모임 상징 색"), fieldWithPath("data.startDate").type(JsonFieldType.STRING).attributes(getDateTimeFormat()).description("모임 시작일"), fieldWithPath("data.endDate").type(JsonFieldType.STRING).attributes(getDateTimeFormat()).description("모임 종료일"), - fieldWithPath("data.status").type(JsonFieldType.STRING).description("모임 링크 상태"), - fieldWithPath("error").type(JsonFieldType.NULL).description("에러") + fieldWithPath("data.status").type(JsonFieldType.STRING).description("모임 링크 상태") ) ) ); @@ -97,10 +96,9 @@ void findByMeetingLink_notFound() throws Exception { parameterWithName("meetingLink").description("모임 링크") ), responseFields( - fieldWithPath("success").type(JsonFieldType.BOOLEAN).description("성공 여부"), + fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("data").type(JsonFieldType.NULL).description("모임"), fieldWithPath("error").type(JsonFieldType.OBJECT).description("에러"), - fieldWithPath("error.status").type(JsonFieldType.NUMBER).description("상태코드"), fieldWithPath("error.code").type(JsonFieldType.STRING).description("에러코드"), fieldWithPath("error.message").type(JsonFieldType.STRING).description("에러 메세지") ) @@ -146,9 +144,8 @@ void validateMeetingPassword() throws Exception { fieldWithPath("password").type(JsonFieldType.STRING).description("모임 비밀번호") ), responseFields( - fieldWithPath("success").type(JsonFieldType.BOOLEAN).description("성공 여부"), - fieldWithPath("data").type(JsonFieldType.NULL).description("데이터"), - fieldWithPath("error").type(JsonFieldType.NULL).description("에러") + fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), + fieldWithPath("data").type(JsonFieldType.NULL).description("데이터") ) ) ); @@ -191,10 +188,9 @@ void validateMeetingPassword_invalidatePassword() throws Exception { fieldWithPath("password").type(JsonFieldType.STRING).description("모임 비밀번호") ), responseFields( - fieldWithPath("success").type(JsonFieldType.BOOLEAN).description("성공 여부"), + fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("data").type(JsonFieldType.NULL).description("데이터"), fieldWithPath("error").type(JsonFieldType.OBJECT).description("에러"), - fieldWithPath("error.status").type(JsonFieldType.NUMBER).description("상태코드"), fieldWithPath("error.code").type(JsonFieldType.STRING).description("에러코드"), fieldWithPath("error.message").type(JsonFieldType.STRING).description("에러 메세지") ) @@ -242,9 +238,8 @@ void validateMeetingLeaderAuthKey() throws Exception { fieldWithPath("leaderAuthKey").type(JsonFieldType.STRING).description("관리자 인증키") ), responseFields( - fieldWithPath("success").type(JsonFieldType.BOOLEAN).description("성공 여부"), - fieldWithPath("data").type(JsonFieldType.NULL).description("데이터"), - fieldWithPath("error").type(JsonFieldType.NULL).description("에러") + fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), + fieldWithPath("data").type(JsonFieldType.NULL).description("데이터") ) ) ); @@ -289,10 +284,9 @@ void validateMeetingLeaderAuthKey_invalidatePassword() throws Exception { fieldWithPath("leaderAuthKey").type(JsonFieldType.STRING).description("관리자 인증키") ), responseFields( - fieldWithPath("success").type(JsonFieldType.BOOLEAN).description("성공 여부"), + fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("data").type(JsonFieldType.NULL).description("데이터"), fieldWithPath("error").type(JsonFieldType.OBJECT).description("에러"), - fieldWithPath("error.status").type(JsonFieldType.NUMBER).description("상태코드"), fieldWithPath("error.code").type(JsonFieldType.STRING).description("에러코드"), fieldWithPath("error.message").type(JsonFieldType.STRING).description("에러 메세지") ) @@ -339,10 +333,9 @@ void validateMeetingLeaderAuthKey_invalidateLeaderAuthKey() throws Exception { fieldWithPath("leaderAuthKey").type(JsonFieldType.STRING).description("관리자 인증키") ), responseFields( - fieldWithPath("success").type(JsonFieldType.BOOLEAN).description("성공 여부"), + fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("data").type(JsonFieldType.NULL).description("데이터"), fieldWithPath("error").type(JsonFieldType.OBJECT).description("에러"), - fieldWithPath("error.status").type(JsonFieldType.NUMBER).description("상태코드"), fieldWithPath("error.code").type(JsonFieldType.STRING).description("에러코드"), fieldWithPath("error.message").type(JsonFieldType.STRING).description("에러 메세지") ) @@ -383,10 +376,9 @@ void createMeeting() throws Exception { partWithName("thumbnail").optional().description("모임 썸네일 (선택)") ), responseFields( - fieldWithPath("success").type(JsonFieldType.BOOLEAN).description("성공 여부"), + fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("data").type(JsonFieldType.OBJECT).description("생성된 모임 정보"), - fieldWithPath("data.meetingLink").type(JsonFieldType.STRING).description("생성된 모임 링크"), - fieldWithPath("error").type(JsonFieldType.NULL).description("에러") + fieldWithPath("data.meetingLink").type(JsonFieldType.STRING).description("생성된 모임 링크") ) ) ); @@ -425,10 +417,9 @@ void createMeeting_BAD_REQUEST_startDate() throws Exception { partWithName("thumbnail").optional().description("모임 썸네일 (선택)") ), responseFields( - fieldWithPath("success").type(JsonFieldType.BOOLEAN).description("성공 여부"), + fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("data").type(JsonFieldType.NULL).description("생성된 모임 정보 (실패 시 null)"), fieldWithPath("error").type(JsonFieldType.OBJECT).description("오류 정보"), - fieldWithPath("error.status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("error.code").type(JsonFieldType.STRING).description("에러 코드"), fieldWithPath("error.message").type(JsonFieldType.STRING).optional().description("에러 메시지") ) @@ -469,10 +460,9 @@ void createMeeting_BAD_REQUEST_endDate() throws Exception { partWithName("thumbnail").optional().description("모임 썸네일 (선택)") ), responseFields( - fieldWithPath("success").type(JsonFieldType.BOOLEAN).description("성공 여부"), + fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("data").type(JsonFieldType.NULL).description("생성된 모임 정보 (실패 시 null)"), fieldWithPath("error").type(JsonFieldType.OBJECT).description("오류 정보"), - fieldWithPath("error.status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("error.code").type(JsonFieldType.STRING).description("에러 코드"), fieldWithPath("error.message").type(JsonFieldType.STRING).optional().description("에러 메시지") ) @@ -509,10 +499,9 @@ void createMeeting_VALIDATION_ERROR() throws Exception { partWithName("thumbnail").optional().description("모임 썸네일 (선택)") ), responseFields( - fieldWithPath("success").type(JsonFieldType.BOOLEAN).description("요청 성공 여부"), + fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("data").type(JsonFieldType.NULL).description("응답 데이터 (실패 시 null)"), fieldWithPath("error").type(JsonFieldType.OBJECT).description("에러 정보"), - fieldWithPath("error.status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("error.code").type(JsonFieldType.STRING).description("에러 코드"), fieldWithPath("error.message").type(JsonFieldType.STRING).optional().description("에러 메시지") ) @@ -550,9 +539,8 @@ void getShareableMeetingLink_Success() throws Exception { restDocs.document( pathParameters(parameterWithName("meetingId").description("모임 ID")), responseFields( - fieldWithPath("success").type(JsonFieldType.BOOLEAN).description("성공 여부"), - fieldWithPath("data.meetingLink").type(JsonFieldType.STRING).description("모임 링크"), - fieldWithPath("error").type(JsonFieldType.NULL).description("에러") + fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), + fieldWithPath("data.meetingLink").type(JsonFieldType.STRING).description("모임 링크") ) ) ); @@ -575,10 +563,9 @@ void findByMeetingIdOrThrow_MEETING_NOT_FOUND() throws Exception { parameterWithName("meetingId").description("모임 ID") ), responseFields( - fieldWithPath("success").type(JsonFieldType.BOOLEAN).description("성공 여부"), + fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("data").type(JsonFieldType.NULL).description("공유 가능한 모임 링크"), fieldWithPath("error").type(JsonFieldType.OBJECT).description("에러"), - fieldWithPath("error.status").type(JsonFieldType.NUMBER).description("상태코드"), fieldWithPath("error.code").type(JsonFieldType.STRING).description("에러코드"), fieldWithPath("error.message").type(JsonFieldType.STRING).description("에러 메세지") ) diff --git a/src/test/java/com/dnd/snappy/controller/v1/participant/ParticipantControllerTest.java b/src/test/java/com/dnd/snappy/controller/v1/participant/ParticipantControllerTest.java index 30a0bd4..4feb08d 100644 --- a/src/test/java/com/dnd/snappy/controller/v1/participant/ParticipantControllerTest.java +++ b/src/test/java/com/dnd/snappy/controller/v1/participant/ParticipantControllerTest.java @@ -61,11 +61,10 @@ void participateMeeting() throws Exception { fieldWithPath("role").type(JsonFieldType.STRING).description("모임의 권한 (LEADER | PARTICIPANT)") ), responseFields( - fieldWithPath("success").type(JsonFieldType.BOOLEAN).description("성공 여부"), + fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("data").type(JsonFieldType.OBJECT).description("데이터"), fieldWithPath("data.participantId").type(JsonFieldType.NUMBER).description("참여자 id"), - fieldWithPath("data.accessToken").type(JsonFieldType.STRING).description("인증에 사용하는 accessToken"), - fieldWithPath("error").type(JsonFieldType.NULL).description("에러") + fieldWithPath("data.accessToken").type(JsonFieldType.STRING).description("인증에 사용하는 accessToken") ), responseCookies( cookieWithName("REFRESH_TOKEN_" +meeting.getId()).description("accessToken 재발급을 위한 refreshToken") @@ -140,10 +139,9 @@ void join_finish_meeting_throw_exception() throws Exception { private ResponseFieldsSnippet getErrorResponseFields() { return responseFields( - fieldWithPath("success").type(JsonFieldType.BOOLEAN).description("성공 여부"), + fieldWithPath("status").type(JsonFieldType.NUMBER).description("HTTP 상태 코드"), fieldWithPath("data").type(JsonFieldType.NULL).description("데이터"), fieldWithPath("error").type(JsonFieldType.OBJECT).description("에러"), - fieldWithPath("error.status").type(JsonFieldType.NUMBER).description("상태코드"), fieldWithPath("error.code").type(JsonFieldType.STRING).description("에러코드"), fieldWithPath("error.message").type(JsonFieldType.STRING).description("에러 메세지") );