Skip to content

Commit

Permalink
Post controller changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeesou committed Jun 19, 2021
1 parent ebcad39 commit 3fd5e9d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<List<PostModel>> getAllPosts() {
List<PostModel> posts = postService.getAllPosts();
return new ResponseEntity<>(posts, HttpStatus.OK);
}

@GetMapping("/{postid}")
public ResponseEntity<PostModel> getPost() {
PostModel post = postService.getPost();
return new ResponseEntity<>(post, HttpStatus.OK);
}

@PostMapping
public ResponseEntity<PostModel> addPost() {
PostModel post = postService.addPost();
return new ResponseEntity<>(post, HttpStatus.OK);
}

@DeleteMapping("/{postid}")
public ResponseEntity<HttpStatus> deletePost() {
postService.deletePost();
return new ResponseEntity<>(HttpStatus.OK);
}

@PutMapping("/{postid}/like")
public ResponseEntity<HttpStatus> likePost() {
postService.addLike();
return new ResponseEntity<>(HttpStatus.OK);
}

@DeleteMapping("/{postid}/like")
public ResponseEntity<HttpStatus> removeLikePost() {
postService.removeLike();
return new ResponseEntity<>(HttpStatus.OK);
}
}
19 changes: 19 additions & 0 deletions src/main/java/xyz/subho/clone/twitter/service/PostService.java
Original file line number Diff line number Diff line change
@@ -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<PostModel> getAllPosts();

public PostModel getPost();

public PostModel addPost();

public boolean deletePost();

public boolean addLike();

public boolean removeLike();
}

0 comments on commit 3fd5e9d

Please sign in to comment.