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