-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Kusitms-29th-Hackathon-C/feat/setting
응답코드 및 CORS관련 세팅
- Loading branch information
Showing
5 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.back.kukertonc.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class WebConfig implements WebMvcConfigurer { | ||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping("/**") | ||
.allowedOrigins("https://kusithms-29th-hackathon-c-front.vercel.app") | ||
.allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH") | ||
.allowCredentials(true); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/back/kukertonc/reponse/BaseErrorResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.back.kukertonc.reponse; | ||
|
||
import com.back.kukertonc.reponse.status.ResponseStatus; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@JsonPropertyOrder({"code", "status", "message", "timestamp"}) | ||
public class BaseErrorResponse implements ResponseStatus { | ||
private final int code; | ||
private final int status; | ||
private final String message; | ||
private final LocalDateTime timestamp; | ||
|
||
public BaseErrorResponse(ResponseStatus status) { | ||
this.code = status.getCode(); | ||
this.status = status.getStatus(); | ||
this.message = status.getMessage(); | ||
this.timestamp = LocalDateTime.now(); | ||
} | ||
|
||
public BaseErrorResponse(ResponseStatus status, String message) { | ||
this.code = status.getCode(); | ||
this.status = status.getStatus(); | ||
this.message = message; | ||
this.timestamp = LocalDateTime.now(); | ||
} | ||
|
||
public BaseErrorResponse(int code, int status, String message){ | ||
this.code = code; | ||
this.status = status; | ||
this.message = message; | ||
this.timestamp = LocalDateTime.now(); | ||
} | ||
|
||
@Override | ||
public int getCode() { | ||
return code; | ||
} | ||
|
||
@Override | ||
public int getStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/back/kukertonc/reponse/BaseResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.back.kukertonc.reponse; | ||
|
||
import com.back.kukertonc.reponse.status.ResponseStatus; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import lombok.Getter; | ||
|
||
import static com.back.kukertonc.reponse.status.BaseExceptionStatus.SUCCESS; | ||
|
||
|
||
@Getter | ||
@JsonPropertyOrder({"code", "status", "message", "result"}) | ||
public class BaseResponse<T> implements ResponseStatus { | ||
|
||
private final int code; | ||
private final int status; | ||
private final String message; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
private final T result; | ||
|
||
public BaseResponse(T result) { | ||
this.code = SUCCESS.getCode(); | ||
this.status = SUCCESS.getStatus(); | ||
this.message = SUCCESS.getMessage(); | ||
this.result = result; | ||
} | ||
|
||
@Override | ||
public int getCode() { | ||
return code; | ||
} | ||
|
||
@Override | ||
public int getStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/back/kukertonc/reponse/status/BaseExceptionStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.back.kukertonc.reponse.status; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
||
|
||
@RequiredArgsConstructor | ||
public enum BaseExceptionStatus implements ResponseStatus{ | ||
/** | ||
* 1000: 요청 성공 (OK) | ||
*/ | ||
SUCCESS(1000, HttpStatus.OK.value(), "요청에 성공하였습니다."); | ||
|
||
|
||
private final int code; | ||
private final int status; | ||
private final String message; | ||
@Override | ||
public int getCode() { | ||
return code; | ||
} | ||
|
||
@Override | ||
public int getStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/back/kukertonc/reponse/status/ResponseStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.back.kukertonc.reponse.status; | ||
|
||
public interface ResponseStatus { | ||
int getCode(); | ||
|
||
int getStatus(); | ||
|
||
String getMessage(); | ||
} |