1
1
package servie .track_servie .controller ;
2
2
3
- import java .util .List ;
4
3
import org .springframework .beans .factory .annotation .Autowired ;
4
+ import org .springframework .http .HttpStatus ;
5
+ import org .springframework .http .ResponseEntity ;
5
6
import org .springframework .security .core .annotation .AuthenticationPrincipal ;
6
7
import org .springframework .security .core .userdetails .UserDetails ;
7
- import org .springframework .stereotype .Controller ;
8
8
import org .springframework .ui .Model ;
9
9
import org .springframework .web .bind .annotation .GetMapping ;
10
10
import org .springframework .web .bind .annotation .PathVariable ;
11
+ import org .springframework .web .bind .annotation .PutMapping ;
11
12
import org .springframework .web .bind .annotation .RequestMapping ;
12
13
import org .springframework .web .bind .annotation .RequestParam ;
14
+ import org .springframework .web .bind .annotation .RestController ;
13
15
import org .springframework .web .util .UriComponentsBuilder ;
14
16
import servie .track_servie .enums .ServieType ;
15
- import servie .track_servie .payload .dtos .operationsImage . Image ;
17
+ import servie .track_servie .payload .dtos .SeasonPageDtos . SeasonDto ;
16
18
import servie .track_servie .repository .UserRepository ;
17
19
import servie .track_servie .service .EpisodeService ;
18
20
import servie .track_servie .service .SeasonService ;
19
21
20
- @ Controller
21
- @ RequestMapping ("/track-servie/ servies/{tmdbId}/Season/{seasonNo}" )
22
+ @ RestController
23
+ @ RequestMapping ("servies/{tmdbId}/Season/{seasonNo}" )
22
24
public class SeasonController
23
25
{
24
26
@ Autowired
@@ -28,32 +30,21 @@ public class SeasonController
28
30
@ Autowired
29
31
private UserRepository userRepository ;
30
32
31
- // Toggles the watch button of multiple Episodes located on SeasonPage
32
- @ GetMapping ("toggleepisodes" )
33
- public String toggleMultipleEpisodeWatch (@ PathVariable Integer tmdbId ,
34
- @ PathVariable Integer seasonNo ,
35
- @ RequestParam (value = "watch" , required = true ) String watch ,
36
- @ RequestParam (value = "fromEpisodeNumber" , required = true ) String fromEpisodeNumber ,
37
- @ RequestParam (value = "toEpisodeNumber" , required = true ) String toEpisodeNumber ,
38
- @ AuthenticationPrincipal UserDetails userDetails )
33
+ // Returns SeasonPage containing selected Season from SeriesPage
34
+ @ GetMapping ("" )
35
+ public ResponseEntity <SeasonDto > getSeason (@ PathVariable Integer tmdbId , @ PathVariable Integer seasonNo )
39
36
{
40
- Integer userId = userRepository .findByUsername (userDetails .getUsername ()).get ().getId ();
41
- Integer episodeNoInt = Integer .parseInt (fromEpisodeNumber );
42
- Integer toEpisodeNumberInt = Integer .parseInt (toEpisodeNumber );
43
- boolean watchValue = Boolean .parseBoolean (watch );
44
- episodeService .toggleMultipleEpisodeWatch (userId , tmdbId , seasonNo , episodeNoInt , toEpisodeNumberInt , watchValue );
45
- return "redirect:/track-servie/servies/" +tmdbId +"/Season/" +seasonNo ;
37
+ Integer userId = userRepository .findByUsername ("Aakkiieezz" ).get ().getId ();
38
+ SeasonDto season = seasonService .getSeason (userId , tmdbId , seasonNo );
39
+ return new ResponseEntity <SeasonDto >(season , null , HttpStatus .OK );
46
40
}
47
41
48
- // Returns ImageSearchSeasonPage containing list of Posters(for specific Season)
49
- @ GetMapping ("posters" )
50
- public String getSeasonImages (@ PathVariable Integer tmdbId , @ PathVariable Integer seasonNo , Model model )
42
+ @ PutMapping ("toggle" )
43
+ public ResponseEntity <HttpStatus > toggleWatch (@ PathVariable Integer tmdbId , @ PathVariable Integer seasonNo )
51
44
{
52
- List <Image > images = seasonService .getSeasonImages (tmdbId , seasonNo );
53
- model .addAttribute ("images" , images );
54
- model .addAttribute ("tmdbId" , tmdbId );
55
- model .addAttribute ("seasonNo" , seasonNo );
56
- return "ImageSearchSeasonPage" ;
45
+ Integer userId = userRepository .findByUsername ("Aakkiieezz" ).get ().getId ();
46
+ seasonService .toggleSeasonWatch (userId , tmdbId , seasonNo );
47
+ return ResponseEntity .status (HttpStatus .OK ).build ();
57
48
}
58
49
59
50
// Redirects to SeasonPage with changed Season Poster
@@ -67,4 +58,41 @@ public String changeImage(@PathVariable Integer tmdbId, @PathVariable Integer se
67
58
.queryParam ("type" , ServieType .SERIES .toString ());
68
59
return builder .buildAndExpand (tmdbId ).toUriString ();
69
60
}
61
+ // // Toggles the watch button of multiple Episodes located on SeasonPage
62
+ // @GetMapping("toggleepisodes")
63
+ // public String toggleMultipleEpisodeWatch(@PathVariable Integer tmdbId,
64
+ // @PathVariable Integer seasonNo,
65
+ // @RequestParam(value = "watch", required = true) String watch,
66
+ // @RequestParam(value = "fromEpisodeNumber", required = true) String fromEpisodeNumber,
67
+ // @RequestParam(value = "toEpisodeNumber", required = true) String toEpisodeNumber,
68
+ // @AuthenticationPrincipal UserDetails userDetails)
69
+ // {
70
+ // Integer userId = userRepository.findByUsername(userDetails.getUsername()).get().getId();
71
+ // Integer episodeNoInt = Integer.parseInt(fromEpisodeNumber);
72
+ // Integer toEpisodeNumberInt = Integer.parseInt(toEpisodeNumber);
73
+ // boolean watchValue = Boolean.parseBoolean(watch);
74
+ // episodeService.toggleMultipleEpisodeWatch(userId, tmdbId, seasonNo, episodeNoInt, toEpisodeNumberInt, watchValue);
75
+ // return "redirect:/track-servie/servies/"+tmdbId+"/Season/"+seasonNo;
76
+ // }
77
+ // // Returns ImageSearchSeasonPage containing list of Posters(for specific Season)
78
+ // @GetMapping("posters")
79
+ // public String getSeasonImages(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, Model model)
80
+ // {
81
+ // List<Image> images = seasonService.getSeasonImages(tmdbId, seasonNo);
82
+ // model.addAttribute("images", images);
83
+ // model.addAttribute("tmdbId", tmdbId);
84
+ // model.addAttribute("seasonNo", seasonNo);
85
+ // return "ImageSearchSeasonPage";
86
+ // }
87
+ // // Redirects to SeasonPage with changed Season Poster
88
+ // @GetMapping("posterChange")
89
+ // public String changeImage(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @RequestParam(value = "filePath", defaultValue = "") String filePath, Model model, @AuthenticationPrincipal UserDetails userDetails)
90
+ // {
91
+ // Integer userId = userRepository.findByUsername(userDetails.getUsername()).get().getId();
92
+ // seasonService.changeImage(userId, tmdbId, seasonNo, filePath);
93
+ // // return "redirect:/track-servie/servies/"+tmdbId;
94
+ // UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("redirect:/track-servie/servies/{tmdbId}")
95
+ // .queryParam("type", ServieType.SERIES.toString());
96
+ // return builder.buildAndExpand(tmdbId).toUriString();
97
+ // }
70
98
}
0 commit comments