Skip to content

Commit

Permalink
[~] #77 ServiceResult 필드 초기화 메서드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
woody35545 committed Oct 4, 2023
1 parent 478a0d2 commit 0765b9f
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion src/main/java/com/teamseven/MusicVillain/Dto/ServiceResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,58 @@
@AllArgsConstructor
@Builder
public class ServiceResult{

public static final String SUCCESS = "success";
@Schema(example = "fail")
public static final String FAIL = "fail";

public String result;
public String message;
public Object data;

/**
* 외부에서 Constructor 사용할 수 없도록 private으로 선언
* 메서드를 통해 객체 생성하도록 강제
*/

private ServiceResult(){

}
private ServiceResult(String result, String message, Object data){
this.result = result;
this.message = message;
this.data = data;
}


@Deprecated
public static ServiceResult of(String result, String message, Object data){
return new ServiceResult(result, message, data);
}

@Deprecated
public static ServiceResult of(String result, String message){
return new ServiceResult(result, message, null);
}

@Deprecated
public static ServiceResult success(Object data){
return new ServiceResult(SUCCESS, null, data);
}

@Deprecated
public static ServiceResult fail(String message){
return new ServiceResult(FAIL, message, null);
}


public static ServiceResult SUCCESS(){
return new ServiceResult().success();
}

public static ServiceResult FAIL(){
return new ServiceResult().fail();
}

public boolean isSuccessful(){
return this.result.equals(SUCCESS);
}
Expand All @@ -43,4 +71,26 @@ public boolean isFailed(){
return this.result.equals(FAIL);
}

public ServiceResult success(){
this.result = SUCCESS;
this.message = SUCCESS;
return this;
}

public ServiceResult fail(){
this.result = FAIL;
this.message = FAIL;
return this;
}

public ServiceResult message(String message){
this.message = message;
return this;
}

public ServiceResult data(Object data){
this.data = data;
return this;
}

}

0 comments on commit 0765b9f

Please sign in to comment.