source: Git/src/main/java/com/wediscussmovies/project/web/controller/rest/DiscussionRestController.java@ 5b447b0

main
Last change on this file since 5b447b0 was 5b447b0, checked in by Test <matonikolov77@…>, 2 years ago

Adding models and resources

  • Property mode set to 100644
File size: 1.6 KB
Line 
1package com.wediscussmovies.project.web.controller.rest;
2
3import com.wediscussmovies.project.service.DiscussionService;
4import org.springframework.http.ResponseEntity;
5import org.springframework.web.bind.annotation.*;
6
7@RestController
8@RequestMapping("api/discussions")
9public 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}
Note: See TracBrowser for help on using the repository browser.