Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

inho-kit

Spring Boot 프로젝트를 위한 공통 라이브러리입니다.

의존성 추가

Gradle

repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.github.inhooo00:inho-kit:v0.0.1'
}

Gradle (Kotlin DSL)

repositories {
    mavenCentral()
    maven { url = uri("https://jitpack.io") }
}

dependencies {
    implementation("com.github.inhooo00:inho-kit:v0.0.1")
}

제공 기능

1. 전역 예외 처리 (ControllerAdvice)

의존성 추가만 하면 자동으로 활성화됩니다.

예외 HTTP 상태
InvalidGroupException 400 Bad Request
AuthGroupException 401 Unauthorized
AccessDeniedGroupException 403 Forbidden
NotFoundGroupException 404 Not Found
ConflictGroupException 409 Conflict

2. 커스텀 예외 정의

제공되는 예외 클래스를 상속받아 사용합니다.

public class UserNotFoundException extends NotFoundGroupException {
    public UserNotFoundException() {
        super("사용자를 찾을 수 없습니다.");
    }
}
// 사용
throw new UserNotFoundException();

응답 예시:

{
  "type": "errors",
  "title": "사용자를 찾을 수 없습니다.",
  "status": 404,
  "timestamp": "2025-02-27T12:00:00+09:00"
}

3. 응답 템플릿 (RspTemplate)

@GetMapping("/users/{id}")
public ResponseEntity<RspTemplate<UserResponse>> getUser(@PathVariable Long id) {
    UserResponse user = userService.findById(id);

    return RspTemplate.<UserResponse>builder()
            .statusCode(HttpStatus.OK)
            .message("사용자 조회 성공")
            .data(user)
            .build()
            .toResponseEntity();
}

응답 예시:

{
  "statusCode": 200,
  "message": "사용자 조회 성공",
  "data": {
    "id": 1,
    "name": "홍길동"
  }
}

요구사항

  • Java 17+
  • Spring Boot 3.x

라이센스

MIT License

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages