[3c0f9a9] | 1 | package com.wediscussmovies.project.web.controller.rest;
|
---|
| 2 |
|
---|
| 3 | import com.wediscussmovies.project.service.DiscussionService;
|
---|
| 4 | import com.wediscussmovies.project.service.GenreService;
|
---|
| 5 | import org.springframework.http.ResponseEntity;
|
---|
| 6 | import org.springframework.web.bind.annotation.*;
|
---|
| 7 |
|
---|
| 8 | @RestController
|
---|
| 9 | @RequestMapping("api/genres")
|
---|
| 10 | public class GenreRestController {
|
---|
| 11 | private final GenreService genreService;
|
---|
| 12 |
|
---|
| 13 | public GenreRestController(GenreService genreService) {
|
---|
| 14 | this.genreService = genreService;
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | @GetMapping("/like/{genreId}")
|
---|
| 18 | public ResponseEntity likeGenre(@PathVariable Integer genreId, @RequestParam Integer userId){
|
---|
| 19 | try {
|
---|
| 20 | this.genreService.likeGenre(genreId,userId);
|
---|
| 21 | return ResponseEntity.ok(true);
|
---|
| 22 | }
|
---|
| 23 | catch (RuntimeException exception){
|
---|
| 24 | return ResponseEntity.ok(false);
|
---|
| 25 | }
|
---|
| 26 | }
|
---|
| 27 | @GetMapping("/unlike/{genreId}")
|
---|
| 28 | public ResponseEntity unlikeGenre (@PathVariable Integer genreId, @RequestParam Integer userId){
|
---|
| 29 | try {
|
---|
| 30 | this.genreService.unlikeGenre(genreId,userId);
|
---|
| 31 | return ResponseEntity.ok(true);
|
---|
| 32 | }
|
---|
| 33 | catch (RuntimeException exception){
|
---|
| 34 | System.out.println(exception.getMessage());
|
---|
| 35 | return ResponseEntity.ok(false);
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
| 38 | }
|
---|