Skip to content

Commit

Permalink
[refactor] 헤더 response 수정 #29
Browse files Browse the repository at this point in the history
  • Loading branch information
gdakate committed Mar 21, 2023
1 parent 3e55454 commit 6493b32
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 10 deletions.
18 changes: 18 additions & 0 deletions src/main/java/com/SollutionChallenge/HighLight/common/ApiBody.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.SollutionChallenge.HighLight.common;

public class ApiBody <T>{
private T data;
private T msg;

public ApiBody(T data, T msg){
this.data = data;
this.msg = msg;
}

public T getData(){
return data;
}
public T getMsg(){
return msg;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.SollutionChallenge.HighLight.common;

import org.springframework.http.HttpStatus;

public class ApiHeader {
private HttpStatus status;
private String message;

public ApiHeader(HttpStatus status, String message) {
this.status = status;
this.message = message;
}

public HttpStatus getStatus() {
return status;
}

public String getMessage() {
return message;
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
package com.SollutionChallenge.HighLight.common;

import com.SollutionChallenge.HighLight.Folder.FolderResponseDto;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ApiResponse<T> {
private int status;
private T data;
private String message;

private ApiResponse(int status, String message, T data) {
this.status = status;
this.data = data;
this.message = message;
private ApiHeader header;
private ApiBody body;
private static int SUCCESS =200;

// private int status;
// private T data;
// private String message;

// private ApiResponse(int status, String message, T data) {
// this.status = status;
// this.data = data;
// this.message = message;
// }

private ApiResponse(ApiHeader header, ApiBody body){
this.header = header;
this.body=body;
}

public static <T> ApiResponse<T> successCode(Success success, T data){
return new ApiResponse<>(success.getStatus().value(), success.getMessage(),null);
public ApiResponse(ApiHeader header){
this.header = header;
}

// public static <T> ApiResponse<T> successCode(Success success, T data){
// return new ApiResponse<>(success.getStatus().value(), success.getMessage(),null);
// }

public static <T> ApiResponse<T> successCode(Success success, FolderResponseDto response){
return new ApiResponse<T>(new ApiHeader(success.getStatus(), success.getMessage()), new ApiBody(null, success.getMessage()));
}

}
14 changes: 14 additions & 0 deletions src/main/java/com/SollutionChallenge/HighLight/common/Success.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import org.springframework.http.HttpStatus;

import com.google.api.Http;

import lombok.AllArgsConstructor;
import lombok.Getter;

Expand All @@ -17,4 +19,16 @@ public enum Success {

private final HttpStatus status;
private final String message;

// Success(HttpStatus status, String message){
// this.status = status;
// this.message=message;
// }
// public HttpStatus getStatus(){
// return status;
// }
//
// public String getMessage(){
// return message;
// }
}

0 comments on commit 6493b32

Please sign in to comment.