-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[week1] 1차 세미나 과제 #2
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다~!
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
public class BaseResponse<T> { | ||
|
||
private final int code; | ||
|
||
private final String status; | ||
|
||
private final boolean success; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
private T data; | ||
|
||
// 데이터 반환하지 않을 때 | ||
public static BaseResponse success() { | ||
return new BaseResponse<>(SuccessCode.OK.getStatusCode(), SuccessCode.OK.getStatus(), true); | ||
} | ||
|
||
// 데이터 반환할 때 | ||
public static <T> BaseResponse<T> success(T data) { | ||
return new BaseResponse<>(SuccessCode.OK.getStatusCode(), SuccessCode.OK.getStatus(), true, data); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
깔끔하게 설계하셨네요~!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코드보면서 새로운 것들 많이 배워갑니다~! 과제하느라 수고 많으셨습니당🥰
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p5;
.gitignore에 .DS_Store 추가해줘도 좋을 것 같아요~!
@GetMapping("/v8") | ||
public ResponseEntity<BaseResponse> healthCheckV8() { | ||
return ResponseEntity.status(SuccessCode.OK.getStatusCode()) | ||
.body(BaseResponse.success()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p5;
이런 방법도 있군요! 배워갑니다~!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저랑 다른 방법들도 많이 배워가요!!
|
||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public enum SuccessCode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p5;
enum으로 관리하는거 좋은 방법인 것 같아요! 공부해서 제 코드에도 적용해볼게요~!!
return ResponseEntity.ok(response); | ||
} | ||
|
||
@GetMapping("/v5") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P5 : 깔끔해요~ 많이 배워갑니다!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아이고 줄 선택이 잘못되었네요...ㅋㅋ큐ㅠㅠ 과제부분으로 봐주세요~
📌 관련 이슈
closed #1
✨ 과제 내용
1. 기본 과제
2. 심화 과제
BaseResponse
BaseResponse
로 다른 API의 응답 객체로 활용 가능하게 생성함. (데이터 반환하지 않을 때/데이터 반환할 때)@JsonInclude
어노테이션을 이용해 data값이 null일 때는 응답에 포함되지 않게 설정함. (데이터 반환하지 않을 때)access = AccessLevel.PRIVATE
으로 클래스의 내부에서만 접근 가능하게 함.HealthCheckController
3. 생각 과제
🐥 총 정리
ResponseEntity를 가지고 어떤 형식의 응답을 취해야 할지에 대해 고민해보는 시간이었다.
ResponseEntity를 사용하지 않고 커스텀한 객체만 반환하면, 단순한 형태의 코드가 되지만 헤더의 HTTP Status Code를 설정하지 못한다는 문제점이 있다는 사실을 알게 되었다.