forked from kakao-tech-campus-2nd-step3/Team9_BE
-
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.
- Loading branch information
Showing
26 changed files
with
348 additions
and
91 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
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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/helpmeCookies/global/ApiResponse/ApiResponse.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,29 @@ | ||
package com.helpmeCookies.global.ApiResponse; | ||
|
||
import jakarta.annotation.Nullable; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@RequiredArgsConstructor | ||
public class ApiResponse<T> { | ||
|
||
private final int code; | ||
private final String message; | ||
private T data; | ||
|
||
public static<T> ApiResponse<T> success(SuccessCode successCode, T data) { | ||
return new ApiResponse<T>(successCode.getCode(), successCode.getMessage(),data); | ||
} | ||
|
||
public static ApiResponse<Void> success(SuccessCode successCode) { | ||
return new ApiResponse<>(successCode.getCode(), successCode.getMessage(),null); | ||
} | ||
|
||
public static ApiResponse<Void> error(HttpStatus errorCode, String message) { | ||
return new ApiResponse<>(errorCode.value(), message,null); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/helpmeCookies/global/ApiResponse/SuccessCode.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,16 @@ | ||
package com.helpmeCookies.global.ApiResponse; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public enum SuccessCode { | ||
OK(200, "OK"), | ||
CREATED_SUCCESS(201, "저장에 성공했습니다"); | ||
|
||
private final int code; | ||
private final String message; | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/helpmeCookies/global/config/WebConfig.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,19 @@ | ||
package com.helpmeCookies.global.config; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
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("/**") | ||
.allowedOriginPatterns("*") // 허용할 도메인 (모든 도메인 허용: "*") | ||
.allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE") // 허용할 HTTP 메서드 | ||
.allowedHeaders("*") // 허용할 헤더 | ||
.allowCredentials(true); // 인증 정보 허용 여부 | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/com/helpmeCookies/global/infra/CustomDatabaseHealthIndicator.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,27 @@ | ||
package com.helpmeCookies.global.infra; | ||
|
||
import com.helpmeCookies.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.boot.actuate.health.HealthIndicator; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class CustomDatabaseHealthIndicator implements HealthIndicator { | ||
|
||
private final UserRepository userRepository; | ||
@Override | ||
public Health health() { | ||
try { | ||
// 테이블이 존재하는지 확인하는 쿼리 (Users 테이블 사용) | ||
long count = userRepository.count(); | ||
// 테이블 존재 시 0 이상을 반환 | ||
return Health.up().withDetail("Users table exists, count: ", count).build(); | ||
} catch (Exception e) { | ||
// 테이블이 없거나 데이터베이스 연결에 문제가 있는 경우 | ||
return Health.down(e).withDetail("Users table", "Table missing or database issue") | ||
.build(); | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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
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
Oops, something went wrong.