-
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
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/main/java/relife/huranit/global/common/BaseTimeEntity.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,22 @@ | ||
package relife.huranit.global.common; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@EntityListeners(AuditingEntityListener.class) | ||
@MappedSuperclass | ||
public abstract class BaseTimeEntity { | ||
@CreatedDate | ||
@Column(updatable = false) | ||
private LocalDateTime createdAt; | ||
@LastModifiedDate | ||
private LocalDateTime updatedAt; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/relife/huranit/global/common/HealthCheckApiController.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 relife.huranit.global.common; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class HealthCheckApiController { | ||
@RequestMapping("/") | ||
public String HuranitServer() { | ||
return "Hello Huranit Server!"; | ||
} | ||
|
||
|
||
@RequestMapping("/example") | ||
public ResponseEntity<SuccessResponse<?>> example() { | ||
return SuccessResponse.ok("example"); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/relife/huranit/global/common/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,23 @@ | ||
package relife.huranit.global.common; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
public enum SuccessCode { | ||
/** | ||
* 200 Ok | ||
*/ | ||
OK(HttpStatus.OK, "요청이 성공했습니다."), | ||
|
||
/** | ||
* 201 Created | ||
*/ | ||
CREATED(HttpStatus.CREATED, "요청이 성공했습니다."); | ||
|
||
private final HttpStatus httpStatus; | ||
private final String message; | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/relife/huranit/global/common/SuccessResponse.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,37 @@ | ||
package relife.huranit.global.common; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Builder | ||
@Getter | ||
public class SuccessResponse<T> { | ||
private int status; | ||
private String message; | ||
private T data; | ||
|
||
public static <T> ResponseEntity<SuccessResponse<?>> ok(T data) { | ||
return ResponseEntity.status(HttpStatus.OK) | ||
.body(SuccessResponse.of(SuccessCode.OK, data)); | ||
} | ||
|
||
public static <T> ResponseEntity<SuccessResponse<?>> created(T data) { | ||
return ResponseEntity.status(HttpStatus.CREATED) | ||
.body(SuccessResponse.of(SuccessCode.CREATED, data)); | ||
} | ||
|
||
|
||
public static <T> SuccessResponse<?> of(SuccessCode successCode, T data) { | ||
return SuccessResponse.builder() | ||
.status(successCode.getHttpStatus().value()) | ||
.message(successCode.getMessage()) | ||
.data(data) | ||
.build(); | ||
} | ||
|
||
} |