diff --git a/src/main/java/xyz/subho/clone/twitter/controller/PostController.java b/src/main/java/xyz/subho/clone/twitter/controller/PostController.java new file mode 100644 index 0000000..357015f --- /dev/null +++ b/src/main/java/xyz/subho/clone/twitter/controller/PostController.java @@ -0,0 +1,58 @@ +package xyz.subho.clone.twitter.controller; + +import java.util.List; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import xyz.subho.clone.twitter.model.PostModel; +import xyz.subho.clone.twitter.service.PostService; + +@RestController +@RequestMapping("/post") +@Slf4j +public class PostController { + + private PostService postService; + + @GetMapping + public ResponseEntity> getAllPosts() { + List posts = postService.getAllPosts(); + return new ResponseEntity<>(posts, HttpStatus.OK); + } + + @GetMapping("/{postid}") + public ResponseEntity getPost() { + PostModel post = postService.getPost(); + return new ResponseEntity<>(post, HttpStatus.OK); + } + + @PostMapping + public ResponseEntity addPost() { + PostModel post = postService.addPost(); + return new ResponseEntity<>(post, HttpStatus.OK); + } + + @DeleteMapping("/{postid}") + public ResponseEntity deletePost() { + postService.deletePost(); + return new ResponseEntity<>(HttpStatus.OK); + } + + @PutMapping("/{postid}/like") + public ResponseEntity likePost() { + postService.addLike(); + return new ResponseEntity<>(HttpStatus.OK); + } + + @DeleteMapping("/{postid}/like") + public ResponseEntity removeLikePost() { + postService.removeLike(); + return new ResponseEntity<>(HttpStatus.OK); + } +} diff --git a/src/main/java/xyz/subho/clone/twitter/service/PostService.java b/src/main/java/xyz/subho/clone/twitter/service/PostService.java new file mode 100644 index 0000000..be027bd --- /dev/null +++ b/src/main/java/xyz/subho/clone/twitter/service/PostService.java @@ -0,0 +1,19 @@ +package xyz.subho.clone.twitter.service; + +import java.util.List; +import xyz.subho.clone.twitter.model.PostModel; + +public interface PostService { + + public List getAllPosts(); + + public PostModel getPost(); + + public PostModel addPost(); + + public boolean deletePost(); + + public boolean addLike(); + + public boolean removeLike(); +}