source: Git/src/main/java/com/wediscussmovies/project/web/controller/rest/MovieRestController.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: 2.0 KB
Line 
1package com.wediscussmovies.project.web.controller.rest;
2
3import com.wediscussmovies.project.LoggedUser;
4import com.wediscussmovies.project.ajaxmodels.Grade;
5import com.wediscussmovies.project.service.MovieService;
6import org.springframework.http.ResponseEntity;
7import org.springframework.web.bind.annotation.*;
8
9@RestController
10@RequestMapping("/api/movies")
11public class MovieRestController {
12
13 private final MovieService movieService;
14
15
16 public MovieRestController(MovieService movieService) {
17 this.movieService = movieService;
18 }
19
20 @DeleteMapping("/delete/{id}")
21 public ResponseEntity deleteById(@PathVariable Integer id){
22 try {
23 this.movieService.deleteById(id);
24 return ResponseEntity.ok(true);
25 }
26 catch (RuntimeException exception){
27 return ResponseEntity.ok(false);
28
29 }
30 }
31 @GetMapping("/like/{movieId}")
32 public ResponseEntity likeMovie(@PathVariable Integer movieId, @RequestParam Integer userId){
33 try {
34 this.movieService.likeMovie(movieId,userId);
35 return ResponseEntity.ok(true);
36 }
37 catch (RuntimeException exception){
38 return ResponseEntity.ok(false);
39 }
40 }
41 @GetMapping("/unlike/{movieId}")
42 public ResponseEntity unlikeMovie(@PathVariable Integer movieId, @RequestParam Integer userId){
43 try {
44 this.movieService.unlikeMovie(movieId,userId);
45 return ResponseEntity.ok(true);
46 }
47 catch (RuntimeException exception){
48 return ResponseEntity.ok(false);
49 }
50 }
51 @PostMapping("/grade/{movieId}")
52 public ResponseEntity addGrade(@PathVariable Integer movieId, @RequestBody Grade grade){
53 try {
54 this.movieService.addGradeMovie(movieId, LoggedUser.getLoggedUser(),grade);
55 return ResponseEntity.ok(true);
56 }
57 catch (RuntimeException exception){
58 return ResponseEntity.ok(false);
59 }
60
61 }
62
63}
Note: See TracBrowser for help on using the repository browser.