source: Git/src/main/java/com/wediscussmovies/project/web/controller/rest/MovieRestController.java@ c02189f

main
Last change on this file since c02189f was c02189f, checked in by Petar Partaloski <ppartaloski@…>, 2 years ago

Added new core functionalities, fixed bugs and improved visual clarity

  • Property mode set to 100644
File size: 2.1 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 if(grade.getRating() < 5)
55 grade.setRating(5);
56 else if(grade.getRating()>10)
57 grade.setRating(10);
58 this.movieService.addGradeMovie(movieId, LoggedUser.getLoggedUser(),grade);
59 return ResponseEntity.ok(true);
60 }
61 catch (RuntimeException exception){
62 return ResponseEntity.ok(false);
63 }
64
65 }
66
67}
Note: See TracBrowser for help on using the repository browser.