-
Notifications
You must be signed in to change notification settings - Fork 38
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
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/main/java/xyz/subho/clone/twitter/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,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
19
src/main/java/xyz/subho/clone/twitter/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,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(); | ||
} |