[5b447b0] | 1 | package com.wediscussmovies.project.web.controller.rest;
|
---|
| 2 |
|
---|
| 3 | import com.wediscussmovies.project.model.primarykeys.ReplyPK;
|
---|
| 4 | import com.wediscussmovies.project.service.ReplyService;
|
---|
| 5 | import org.springframework.http.ResponseEntity;
|
---|
| 6 | import org.springframework.web.bind.annotation.*;
|
---|
| 7 |
|
---|
| 8 | @RestController
|
---|
| 9 | @RequestMapping("api/replies")
|
---|
| 10 | public class ReplyRestController {
|
---|
| 11 |
|
---|
| 12 | private final ReplyService replyService;
|
---|
| 13 |
|
---|
| 14 | public ReplyRestController(ReplyService replyService) {
|
---|
| 15 | this.replyService = replyService;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | @PostMapping("/delete/{discussionId}")
|
---|
| 19 | public ResponseEntity deleteById(@RequestParam Integer replyId,@PathVariable Integer discussionId){
|
---|
| 20 | try {
|
---|
| 21 | this.replyService.delete(discussionId,replyId);
|
---|
| 22 | return ResponseEntity.ok(true);
|
---|
| 23 | }
|
---|
| 24 | catch (RuntimeException exception){
|
---|
| 25 | return ResponseEntity.ok(false);
|
---|
| 26 |
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
| 29 | @GetMapping("/like/{replyId}")
|
---|
| 30 | public ResponseEntity likeReply(@PathVariable Integer replyId,
|
---|
| 31 | @RequestParam Integer userId){
|
---|
| 32 | try {
|
---|
| 33 | this.replyService.likeReply(replyId,userId);
|
---|
| 34 | return ResponseEntity.ok(true);
|
---|
| 35 | }
|
---|
| 36 | catch (RuntimeException exception){
|
---|
| 37 | return ResponseEntity.ok(false);
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 | @GetMapping("/unlike/{replyId}")
|
---|
| 41 | public ResponseEntity unlikeReply(@PathVariable Integer replyId,
|
---|
| 42 | @RequestParam Integer userId){
|
---|
| 43 | try {
|
---|
| 44 | this.replyService.unlikeReply(replyId,userId);
|
---|
| 45 | return ResponseEntity.ok(true);
|
---|
| 46 | }
|
---|
| 47 | catch (RuntimeException exception){
|
---|
| 48 | return ResponseEntity.ok(false);
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | }
|
---|