File tree Expand file tree Collapse file tree 6 files changed +35
-28
lines changed
src/main/java/com/moplus/moplus_server/global Expand file tree Collapse file tree 6 files changed +35
-28
lines changed Original file line number Diff line number Diff line change @@ -70,11 +70,8 @@ private void addResponseBodyWrapperSchemaExample(Operation operation) {
7070
7171 private Schema <?> wrapSchema (Schema <?> originalSchema ) {
7272 final Schema <?> wrapperSchema = new Schema <>();
73-
7473 wrapperSchema .addProperty ("data" , originalSchema );
75- wrapperSchema .addProperty ("message" , new Schema <>().type ("string" ).example ("오류 메세지" ));
76- wrapperSchema .addProperty ("status" , new Schema <>().type ("string" ).example (HttpStatus .NOT_FOUND .name ()));
77-
74+ wrapperSchema .setRequired (List .of ("data" ));
7875 return wrapperSchema ;
7976 }
8077}
Original file line number Diff line number Diff line change 11package com .moplus .moplus_server .global .error ;
22
33import com .moplus .moplus_server .global .error .exception .ErrorCode ;
4+ import jakarta .validation .constraints .NotNull ;
45import lombok .AccessLevel ;
56import lombok .Getter ;
67import lombok .NoArgsConstructor ;
910@ Getter
1011@ NoArgsConstructor (access = AccessLevel .PROTECTED )
1112public class ErrorResponse {
12-
13+ @ NotNull
1314 private String message ;
15+ @ NotNull
1416 private HttpStatus status ;
1517
1618 private ErrorResponse (final ErrorCode code ) {
Original file line number Diff line number Diff line change 1+ package com .moplus .moplus_server .global .response ;
2+
3+ import com .moplus .moplus_server .global .error .ErrorResponse ;
4+ import jakarta .validation .constraints .NotNull ;
5+ import org .springframework .http .HttpStatus ;
6+
7+ public record FailResponseDto (
8+ @ NotNull
9+ String message ,
10+ @ NotNull
11+ HttpStatus status
12+ ) {
13+ public static FailResponseDto fail (ErrorResponse errorResponse ) {
14+ return new FailResponseDto (errorResponse .getMessage (), errorResponse .getStatus ());
15+ }
16+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ public class ResponseDtoAdvice implements ResponseBodyAdvice<Object> {
1717
1818 @ Override
1919 public boolean supports (MethodParameter returnType , Class converterType ) {
20- return !(returnType .getParameterType () == ResponseDto .class )
20+ return !(returnType .getParameterType () == SuccessResponseDto .class )
2121 && MappingJackson2HttpMessageConverter .class .isAssignableFrom (converterType );
2222 }
2323
@@ -31,8 +31,8 @@ public Object beforeBodyWrite(
3131 ServerHttpResponse response
3232 ) {
3333 if (body instanceof ErrorResponse ) {
34- return ResponseDto .fail ((ErrorResponse ) body );
34+ return FailResponseDto .fail ((ErrorResponse ) body );
3535 }
36- return ResponseDto .success (body );
36+ return SuccessResponseDto .success (body );
3737 }
3838}
Original file line number Diff line number Diff line change 1+ package com .moplus .moplus_server .global .response ;
2+
3+ import jakarta .validation .constraints .NotNull ;
4+
5+ public record SuccessResponseDto <T >(
6+ @ NotNull
7+ T data
8+ ) {
9+ public static <T > SuccessResponseDto <T > success (final T data ) {
10+ return new SuccessResponseDto <>(data );
11+ }
12+ }
You can’t perform that action at this time.
0 commit comments