Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post controller changes #13

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}