diff --git a/src/main/java/relife/huranit/global/common/BaseTimeEntity.java b/src/main/java/relife/huranit/global/common/BaseTimeEntity.java new file mode 100644 index 0000000..f90dcce --- /dev/null +++ b/src/main/java/relife/huranit/global/common/BaseTimeEntity.java @@ -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; +} \ No newline at end of file diff --git a/src/main/java/relife/huranit/global/common/HealthCheckApiController.java b/src/main/java/relife/huranit/global/common/HealthCheckApiController.java new file mode 100644 index 0000000..ba2d8cb --- /dev/null +++ b/src/main/java/relife/huranit/global/common/HealthCheckApiController.java @@ -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> example() { + return SuccessResponse.ok("example"); + } +} \ No newline at end of file diff --git a/src/main/java/relife/huranit/global/common/SuccessCode.java b/src/main/java/relife/huranit/global/common/SuccessCode.java new file mode 100644 index 0000000..9279b0a --- /dev/null +++ b/src/main/java/relife/huranit/global/common/SuccessCode.java @@ -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; +} \ No newline at end of file diff --git a/src/main/java/relife/huranit/global/common/SuccessResponse.java b/src/main/java/relife/huranit/global/common/SuccessResponse.java new file mode 100644 index 0000000..2c3ce3d --- /dev/null +++ b/src/main/java/relife/huranit/global/common/SuccessResponse.java @@ -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 { + private int status; + private String message; + private T data; + + public static ResponseEntity> ok(T data) { + return ResponseEntity.status(HttpStatus.OK) + .body(SuccessResponse.of(SuccessCode.OK, data)); + } + + public static ResponseEntity> created(T data) { + return ResponseEntity.status(HttpStatus.CREATED) + .body(SuccessResponse.of(SuccessCode.CREATED, data)); + } + + + public static SuccessResponse of(SuccessCode successCode, T data) { + return SuccessResponse.builder() + .status(successCode.getHttpStatus().value()) + .message(successCode.getMessage()) + .data(data) + .build(); + } + +} \ No newline at end of file