-
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
23 changed files
with
411 additions
and
55 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
springFirstSeminar/src/main/java/org/sopt/springFirstSeminar/common/ApiResponseUtil.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 org.sopt.springFirstSeminar.common; | ||
|
||
|
||
import org.sopt.springFirstSeminar.common.dto.ErrorMessage; | ||
import org.sopt.springFirstSeminar.common.dto.SuccessMessage; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
public interface ApiResponseUtil { | ||
|
||
static ResponseEntity<BaseResponse<?>> success(SuccessMessage successMessage) { | ||
return ResponseEntity | ||
.status(successMessage.getStatus()) | ||
.body(BaseResponse.of(successMessage)); | ||
} | ||
|
||
static <T> ResponseEntity<BaseResponse<?>> success(SuccessMessage successMessage, T data) { | ||
return ResponseEntity | ||
.status((successMessage.getStatus())) | ||
.body(BaseResponse.of(successMessage, data)); | ||
} | ||
|
||
static ResponseEntity<BaseResponse<?>> fail(ErrorMessage errorMessage) { | ||
return ResponseEntity | ||
.status(errorMessage.getStatus()) | ||
.body(BaseResponse.of(errorMessage)); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
springFirstSeminar/src/main/java/org/sopt/springFirstSeminar/common/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,45 @@ | ||
package org.sopt.springFirstSeminar.common; | ||
|
||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import org.sopt.springFirstSeminar.common.dto.ErrorMessage; | ||
import org.sopt.springFirstSeminar.common.dto.SuccessMessage; | ||
import org.sopt.springFirstSeminar.common.dto.SuccessStatusResponse; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
public class BaseResponse<T> { | ||
private final int status; | ||
private final String message; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
private final T data; | ||
|
||
public static BaseResponse<?> of(SuccessMessage successMessage) { | ||
return builder() | ||
.status(successMessage.getStatus()) | ||
.message(successMessage.getMessage()) | ||
.build(); | ||
} | ||
|
||
public static <T> BaseResponse<?> of(SuccessMessage successMessage, T data) { | ||
return builder() | ||
.status(successMessage.getStatus()) | ||
.message(successMessage.getMessage()) | ||
.data(data) | ||
.build(); | ||
} | ||
|
||
public static BaseResponse<?> of(ErrorMessage errorMessage) { | ||
return builder() | ||
.status(errorMessage.getStatus()) | ||
.message(errorMessage.getMessage()) | ||
.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
30 changes: 30 additions & 0 deletions
30
...stSeminar/src/main/java/org/sopt/springFirstSeminar/common/dto/SuccessStatusResponse.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,30 @@ | ||
package org.sopt.springFirstSeminar.common.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
public record SuccessStatusResponse<T>( | ||
int status, | ||
String message, | ||
@JsonInclude(value = JsonInclude.Include.NON_NULL) //이거붙이니까 data없는 곳은 response에 안뜸(공부해야됨)!! | ||
T data | ||
) { | ||
|
||
public static SuccessStatusResponse<?> of(SuccessMessage successMessage) { | ||
return builder() | ||
.status(successMessage.getStatus()) | ||
.message(successMessage.getMessage()) | ||
.build(); | ||
} | ||
|
||
public static <T> SuccessStatusResponse<?> of(SuccessMessage successMessage, T data) { | ||
return builder() | ||
.status(successMessage.getStatus()) | ||
.message(successMessage.getMessage()) | ||
.data(data) | ||
.build(); | ||
} | ||
|
||
} |
12 changes: 0 additions & 12 deletions
12
...tSeminar/src/main/java/org/sopt/springFirstSeminar/common/dto/SuccesttStatusResponse.java
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
springFirstSeminar/src/main/java/org/sopt/springFirstSeminar/common/util/DateFormatUtil.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,18 @@ | ||
package org.sopt.springFirstSeminar.common.util; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class DateFormatUtil { | ||
|
||
private static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; | ||
|
||
public static String format(LocalDateTime dateTime) { | ||
return format(dateTime, DEFAULT_DATE_FORMAT); | ||
} | ||
|
||
public static String format(LocalDateTime dateTime, String pattern) { | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); | ||
return dateTime.format(formatter); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,8 +7,4 @@ | |
|
||
@EnableJpaAuditing | ||
@Configuration | ||
public class JpaAuditingConfig { | ||
|
||
|
||
|
||
} | ||
public class JpaAuditingConfig { } |
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
51 changes: 51 additions & 0 deletions
51
springFirstSeminar/src/main/java/org/sopt/springFirstSeminar/controller/PostController.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,51 @@ | ||
package org.sopt.springFirstSeminar.controller; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.springFirstSeminar.common.ApiResponseUtil; | ||
import org.sopt.springFirstSeminar.common.BaseResponse; | ||
import org.sopt.springFirstSeminar.common.dto.SuccessMessage; | ||
import org.sopt.springFirstSeminar.common.dto.SuccessStatusResponse; | ||
import org.sopt.springFirstSeminar.service.PostService; | ||
import org.sopt.springFirstSeminar.service.dto.BlogAllContentResponseDTO; | ||
import org.sopt.springFirstSeminar.service.dto.BlogContentRequestDTO; | ||
import org.sopt.springFirstSeminar.service.dto.BlogContentResponseDTO; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1") | ||
@RequiredArgsConstructor | ||
public class PostController { | ||
|
||
private final PostService postService; | ||
|
||
@PostMapping("/post/{blogId}") | ||
public ResponseEntity<BaseResponse<?>> postBlogContent( | ||
@RequestHeader(name = "memberId") final Long memberId, | ||
@PathVariable final Long blogId, | ||
@Valid @RequestBody final BlogContentRequestDTO blogContentRequestDTO | ||
) { | ||
postService.postContent(memberId, blogId, blogContentRequestDTO); | ||
return ApiResponseUtil.success(SuccessMessage.BLOG_CONTENT_CREATE_SUCCESS); | ||
} | ||
|
||
@GetMapping("/post/{postId}") | ||
public ResponseEntity<BaseResponse<?>> getPostContent( | ||
@PathVariable final Long postId | ||
) { | ||
final BlogContentResponseDTO response = postService.getBlogContent(postId); | ||
return ApiResponseUtil.success(SuccessMessage.GET_BLOG_CONTENT_SUCCESS, response); | ||
} | ||
|
||
@GetMapping("/post/blog/{blogId}") | ||
public ResponseEntity<BaseResponse<?>> getAllPostContent( | ||
@PathVariable final Long blogId | ||
) { | ||
final List<BlogAllContentResponseDTO> response = postService.getBlogAllContent(blogId); | ||
return ApiResponseUtil.success(SuccessMessage.GET_BLOG_CONTENT_SUCCESS, response); | ||
} | ||
} |
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
2 changes: 2 additions & 0 deletions
2
...ngFirstSeminar/src/main/java/org/sopt/springFirstSeminar/exception/BusinessException.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
8 changes: 8 additions & 0 deletions
8
springFirstSeminar/src/main/java/org/sopt/springFirstSeminar/repository/PostRepository.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,8 @@ | ||
package org.sopt.springFirstSeminar.repository; | ||
|
||
import org.sopt.springFirstSeminar.domain.Post; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface PostRepository extends JpaRepository<Post, Long> { | ||
|
||
} |
Oops, something went wrong.