-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[BE/feat/#22] Post Create api 구현
- Loading branch information
Showing
11 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
.../src/main/java/com/rising/backend/domain/comment/domain/controller/CommentController.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 com.rising.backend.domain.comment.domain.controller; | ||
|
||
import com.rising.backend.domain.comment.dto.request.CommentRequest; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "USER API") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/comments") | ||
public class CommentController { | ||
|
||
|
||
} |
19 changes: 19 additions & 0 deletions
19
backend/src/main/java/com/rising/backend/domain/comment/dto/request/CommentRequest.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.rising.backend.domain.comment.dto.request; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CommentRequest { | ||
|
||
public static class CreateDto { | ||
private Long postId; | ||
|
||
private Long userId; | ||
|
||
private String content; | ||
|
||
private Long parentId; | ||
|
||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/com/rising/backend/domain/comment/repository/CommentRepository.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 com.rising.backend.domain.comment.repository; | ||
|
||
import com.rising.backend.domain.comment.domain.Comment; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CommentRepository extends JpaRepository<Comment, Long> { | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
backend/src/main/java/com/rising/backend/domain/comment/service/CommentService.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,13 @@ | ||
package com.rising.backend.domain.comment.service; | ||
|
||
import com.rising.backend.domain.comment.repository.CommentRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CommentService { | ||
|
||
private final CommentRepository commentRepository; | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
backend/src/main/java/com/rising/backend/domain/post/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,30 @@ | ||
package com.rising.backend.domain.post.controller; | ||
|
||
import com.rising.backend.domain.post.dto.request.PostCreateRequestDto; | ||
import com.rising.backend.domain.post.service.PostService; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "POST API") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("api/v1/posts") | ||
public class PostController { | ||
|
||
private final PostService postService; | ||
|
||
@PostMapping | ||
public ResponseEntity<String> create(@RequestBody PostCreateRequestDto dto) { | ||
postService.createPost(dto); | ||
|
||
return ResponseEntity.status(HttpStatus.CREATED) | ||
.body("글 등록 성공"); | ||
} | ||
|
||
} |
9 changes: 8 additions & 1 deletion
9
backend/src/main/java/com/rising/backend/domain/post/domain/PostType.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 |
---|---|---|
@@ -1,6 +1,13 @@ | ||
package com.rising.backend.domain.post.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
|
||
public enum PostType { | ||
QUESTION, | ||
MENTORING | ||
MENTORING; | ||
|
||
@JsonCreator | ||
public static PostType from(String s) { | ||
return PostType.valueOf(s.toUpperCase()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
backend/src/main/java/com/rising/backend/domain/post/dto/mapper/PostMapper.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,26 @@ | ||
package com.rising.backend.domain.post.dto.mapper; | ||
|
||
import com.rising.backend.domain.post.domain.Post; | ||
import com.rising.backend.domain.post.dto.request.PostCreateRequestDto; | ||
import com.rising.backend.domain.post.repository.PostRepository; | ||
import com.rising.backend.domain.user.service.UserService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class PostMapper { | ||
|
||
private final PostRepository postRepository; | ||
private final UserService userService; | ||
|
||
public Post toPostEntity(PostCreateRequestDto dto) { | ||
return Post.builder() | ||
.user(userService.getUser(dto.getUserId())) | ||
.content(dto.getContent()) | ||
.title(dto.getTitle()) | ||
.memo(null) | ||
.videoUrl(null) | ||
.type(dto.getType()).build(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
backend/src/main/java/com/rising/backend/domain/post/dto/request/PostCreateRequestDto.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,26 @@ | ||
package com.rising.backend.domain.post.dto.request; | ||
|
||
import com.rising.backend.domain.post.domain.PostType; | ||
import lombok.Getter; | ||
import org.hibernate.validator.constraints.Length; | ||
|
||
import javax.validation.constraints.NotEmpty; | ||
|
||
@Getter | ||
public class PostCreateRequestDto { | ||
|
||
@NotEmpty | ||
private Long userId; | ||
|
||
@NotEmpty | ||
@Length(max = 100) | ||
private String title; | ||
|
||
@NotEmpty | ||
private String content; | ||
|
||
@NotEmpty | ||
private PostType type; | ||
|
||
|
||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/com/rising/backend/domain/post/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 com.rising.backend.domain.post.repository; | ||
|
||
import com.rising.backend.domain.post.domain.Post; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface PostRepository extends JpaRepository<Post, Long> { | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
backend/src/main/java/com/rising/backend/domain/post/service/PostService.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,20 @@ | ||
package com.rising.backend.domain.post.service; | ||
|
||
import com.rising.backend.domain.post.domain.Post; | ||
import com.rising.backend.domain.post.dto.mapper.PostMapper; | ||
import com.rising.backend.domain.post.dto.request.PostCreateRequestDto; | ||
import com.rising.backend.domain.post.repository.PostRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PostService { | ||
|
||
private final PostRepository postRepository; | ||
private final PostMapper postMapper; | ||
|
||
public Post createPost(PostCreateRequestDto dto) { | ||
return postRepository.save(postMapper.toPostEntity(dto)); | ||
} | ||
} |
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