Skip to content

Commit 4c549d3

Browse files
committed
many changes over time
1 parent 67c2941 commit 4c549d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1108
-808
lines changed

notes - newLearnings

+17
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,20 @@ profile pic is saved in database, but it slows the application to load from ther
33
therefore will be generating & storing in an external directory,
44
so frontend can access it directly as a resource.
55
External directly - because storing new user uploads or img changes in 'src/resource/' folder is not recommended during runtime, it may work during development, but once it is packaged into a jar, any directory or files inside the src folder are not accessible for runtime operations like file creation or modification.
6+
7+
-> every small change asks demands for best user experience vs
8+
9+
-> making use of @OrderBy("[ColumnName] [SortDir]") on
10+
Hibernate will return the list of seasons sorted by seasonNo in ascending order without requiring any manual sorting in Java or a custom query.
11+
the @OrderBy annotation in JPA can only be applied to collection-based relationships (i.e. @OneToMany or @ManyToMany) that involve a parent-child mapping, such as @OneToMany or @ManyToMany relationships.
12+
13+
-> in this code :
14+
15+
```
16+
@Formula(value = "(SELECT COALESCE(SUM(ep.runtime), 0) FROM episode AS ep"
17+
+" WHERE ep.tmdb_id = tmdb_id"
18+
+" AND ep.season_no > 0)")
19+
private int totalRuntime = 0;
20+
```
21+
22+
the Query in the formula returns a number or null if not used COALESCE, in case it returns null, then int cannot handle it even if it has default set to 0

notes - traktTvNotes

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ Lists can contain : episode/season/series/movie
33
Watch toggling of season
44
when none episodes watched -> marks it as all watched
55
few episodes watched -> options [watch remaining, remove all, nothing]
6-
all eoisodes watched -> options [remove all, nothing]
6+
all eoisodes watched -> options [remove all, nothing]
7+
8+

pom.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@
120120
<artifactId>commons-io</artifactId>
121121
<version>2.16.1</version>
122122
</dependency>
123-
123+
<dependency>
124+
<groupId>com.fasterxml.jackson.core</groupId>
125+
<artifactId>jackson-databind</artifactId>
126+
<version>2.18.1</version>
127+
</dependency>
124128

125129
</dependencies>
126130
<build>

src/main/java/servie/track_servie/config/ApiSecurity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
3030
"src/main/resources/static/css/mystyles.css",
3131
"/track-servie/auth/register",
3232
"/track-servie/auth/login",
33-
"/track-servie/react/servies/**",
33+
"/track-servie/react/**", // temporarily
3434
"/track-servie/user/image/**",
3535
"/profilePics/**")
3636
.permitAll()

src/main/java/servie/track_servie/controller/AuthController.java

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.springframework.security.core.AuthenticationException;
1010
import org.springframework.security.core.userdetails.UserDetails;
1111
import org.springframework.security.crypto.password.PasswordEncoder;
12-
import org.springframework.web.bind.annotation.CrossOrigin;
1312
import org.springframework.web.bind.annotation.PostMapping;
1413
import org.springframework.web.bind.annotation.RequestBody;
1514
import org.springframework.web.bind.annotation.RequestMapping;

src/main/java/servie/track_servie/controller/EpisodeController.java

+33-50
Original file line numberDiff line numberDiff line change
@@ -2,80 +2,63 @@
22

33
import java.util.List;
44
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.http.HttpStatus;
6+
import org.springframework.http.ResponseEntity;
57
import org.springframework.security.core.annotation.AuthenticationPrincipal;
68
import org.springframework.security.core.userdetails.UserDetails;
7-
import org.springframework.stereotype.Controller;
89
import org.springframework.ui.Model;
910
import org.springframework.web.bind.annotation.GetMapping;
1011
import org.springframework.web.bind.annotation.PathVariable;
12+
import org.springframework.web.bind.annotation.PostMapping;
13+
import org.springframework.web.bind.annotation.PutMapping;
1114
import org.springframework.web.bind.annotation.RequestMapping;
1215
import org.springframework.web.bind.annotation.RequestParam;
16+
import org.springframework.web.bind.annotation.RestController;
1317
import servie.track_servie.payload.dtos.episodePageDtos.EpisodeDtoEpisodePage;
1418
import servie.track_servie.payload.dtos.operationsImage.Image;
1519
import servie.track_servie.repository.UserRepository;
1620
import servie.track_servie.service.EpisodeService;
1721

18-
@Controller
19-
@RequestMapping("/track-servie/servies/{tmdbId}/Season/{seasonNo}/Episode/{episodeNo}")
22+
@RestController
23+
@RequestMapping("/track-servie/react/servies/{tmdbId}/Season/{seasonNo}/Episode/{episodeNo}")
2024
public class EpisodeController
2125
{
2226
@Autowired
2327
EpisodeService episodeService;
2428
@Autowired
2529
private UserRepository userRepository;
26-
2730
// Returns EpisodePage containing selected Episode from SeasonPage
28-
@GetMapping("")
29-
public String getEpisode(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @PathVariable Integer episodeNo, Model model)
30-
{
31-
EpisodeDtoEpisodePage episode = episodeService.getEpisode(tmdbId, seasonNo, episodeNo);
32-
model.addAttribute("episode", episode);
33-
return "EpisodePage";
34-
}
35-
// Returns SearchEpisodePage containing selected Episode from SearchSeasonPage
36-
// @GetMapping("search")
37-
// public String searchEpisode(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @PathVariable Integer episodeNo, Model model)
31+
// @GetMapping("")
32+
// public ResponseEntity<EpisodeDtoEpisodePage> getEpisode(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @PathVariable Integer episodeNo)
3833
// {
39-
// EpisodeDtoSearchEpisodePage episodeDto = episodeService.searchEpisode(tmdbId, seasonNo, episodeNo);
40-
// model.addAttribute("episode", episodeDto);
41-
// return "SearchEpisodePage";
34+
// EpisodeDtoEpisodePage episode = episodeService.getEpisode(tmdbId, seasonNo, episodeNo);
35+
// return new ResponseEntity<EpisodeDtoEpisodePage>(episode, null, HttpStatus.OK);
4236
// }
4337

4438
// Toggles the watch button of Episode located on SeasonPage
45-
@GetMapping("toggleback")
46-
public String toggleEpisodeWatch(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @PathVariable Integer episodeNo, @AuthenticationPrincipal UserDetails userDetails)
39+
@PutMapping("toggle")
40+
public ResponseEntity<HttpStatus> toggleEpisodeWatch(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @PathVariable Integer episodeNo)
4741
{
48-
Integer userId = userRepository.findByUsername(userDetails.getUsername()).get().getId();
42+
Integer userId = userRepository.findByUsername("Aakkiieezz").get().getId();
4943
episodeService.toggleEpisodeWatch(userId, tmdbId, seasonNo, episodeNo);
50-
return "redirect:/track-servie/servies/"+tmdbId+"/Season/"+seasonNo;
51-
}
52-
53-
// Toggles the watch button of Episode located on EpisodePage
54-
@GetMapping("toggle")
55-
public String toggleEpWatch(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @PathVariable Integer episodeNo, @AuthenticationPrincipal UserDetails userDetails)
56-
{
57-
Integer userId = userRepository.findByUsername(userDetails.getUsername()).get().getId();
58-
episodeService.toggleEpisodeWatch(userId, tmdbId, seasonNo, episodeNo);
59-
return "redirect:/track-servie/servies/"+tmdbId+"/Season/"+seasonNo+"/Episode/"+episodeNo;
60-
}
61-
62-
// Returns ImageSearchEpisodePage containing list of Stills(for Episode)
63-
@GetMapping("stills")
64-
public String getEpisodeImages(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @PathVariable Integer episodeNo, Model model)
65-
{
66-
List<Image> images = episodeService.getEpisodeImages(tmdbId, seasonNo, episodeNo);
67-
model.addAttribute("images", images);
68-
model.addAttribute("tmdbId", tmdbId);
69-
model.addAttribute("seasonNo", seasonNo);
70-
model.addAttribute("episodeNo", episodeNo);
71-
return "ImageSearchEpisodePage";
72-
}
73-
74-
// Redirects to EpisodePage with changed Episode Still
75-
@GetMapping("stillChange")
76-
public String changeImage(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @PathVariable Integer episodeNo, @RequestParam(value = "filePath", defaultValue = "") String filePath, Model model)
77-
{
78-
episodeService.changeImage(tmdbId, seasonNo, episodeNo, filePath);
79-
return "redirect:/track-servie/servies/"+tmdbId+"/Season/"+seasonNo+"/Episode/"+episodeNo;
44+
return ResponseEntity.status(HttpStatus.OK).build();
8045
}
46+
// // Returns ImageSearchEpisodePage containing list of Stills(for Episode)
47+
// @GetMapping("stills")
48+
// public String getEpisodeImages(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @PathVariable Integer episodeNo, Model model)
49+
// {
50+
// List<Image> images = episodeService.getEpisodeImages(tmdbId, seasonNo, episodeNo);
51+
// model.addAttribute("images", images);
52+
// model.addAttribute("tmdbId", tmdbId);
53+
// model.addAttribute("seasonNo", seasonNo);
54+
// model.addAttribute("episodeNo", episodeNo);
55+
// return "ImageSearchEpisodePage";
56+
// }
57+
// // Redirects to EpisodePage with changed Episode Still
58+
// @GetMapping("stillChange")
59+
// public String changeImage(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @PathVariable Integer episodeNo, @RequestParam(value = "filePath", defaultValue = "") String filePath, Model model)
60+
// {
61+
// episodeService.changeImage(tmdbId, seasonNo, episodeNo, filePath);
62+
// return "redirect:/track-servie/servies/"+tmdbId+"/Season/"+seasonNo+"/Episode/"+episodeNo;
63+
// }
8164
}
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
package servie.track_servie.controller;
22

33
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.http.HttpStatus;
5+
import org.springframework.http.HttpStatusCode;
6+
import org.springframework.http.ResponseEntity;
47
import org.springframework.stereotype.Controller;
58
import org.springframework.ui.Model;
69
import org.springframework.web.bind.annotation.GetMapping;
710
import org.springframework.web.bind.annotation.PathVariable;
811
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.RestController;
913
import servie.track_servie.payload.dtos.personPageDtos.PersonPageResponseDto;
1014
import servie.track_servie.service.PersonService;
1115

12-
@Controller
13-
@RequestMapping("/track-servie/person/{personId}")
16+
@RestController
17+
@RequestMapping("/track-servie/react/person/{personId}")
1418
public class PersonController
1519
{
1620
@Autowired
1721
private PersonService personService;
1822

1923
@GetMapping("")
20-
public String getPerson(@PathVariable Integer personId, Model model)
24+
public ResponseEntity<PersonPageResponseDto> getPerson(@PathVariable Integer personId)
2125
{
2226
PersonPageResponseDto response = personService.getPerson(personId);
23-
model.addAttribute("response", response);
24-
return "PersonPage";
27+
return new ResponseEntity<PersonPageResponseDto>(response, null, HttpStatus.OK);
2528
}
2629
}

src/main/java/servie/track_servie/controller/SeasonController.java

-29
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.springframework.web.bind.annotation.RequestParam;
1313
import org.springframework.web.util.UriComponentsBuilder;
1414
import servie.track_servie.payload.dtos.operationsImage.Image;
15-
import servie.track_servie.payload.dtos.operationsSeasonPageDtos.SeasonDtoSeasonPage;
1615
import servie.track_servie.repository.UserRepository;
1716
import servie.track_servie.service.EpisodeService;
1817
import servie.track_servie.service.SeasonService;
@@ -28,34 +27,6 @@ public class SeasonController
2827
@Autowired
2928
private UserRepository userRepository;
3029

31-
// Returns SeasonPage containing selected Season from SeriesPage
32-
@GetMapping("")
33-
public String getSeason(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, Model model, @AuthenticationPrincipal UserDetails userDetails)
34-
{
35-
Integer userId = userRepository.findByUsername(userDetails.getUsername()).get().getId();
36-
SeasonDtoSeasonPage season = seasonService.getSeason(userId, tmdbId, seasonNo);
37-
model.addAttribute("season", season);
38-
return "SeasonPage";
39-
}
40-
41-
// Toggles the watch button of Season located on SeriesPage
42-
@GetMapping("toggleback")
43-
public String toggleSeasonWatch(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @AuthenticationPrincipal UserDetails userDetails)
44-
{
45-
Integer userId = userRepository.findByUsername(userDetails.getUsername()).get().getId();
46-
seasonService.toggleSeasonWatch(userId, tmdbId, seasonNo);
47-
return "redirect:/track-servie/servies/"+tmdbId+"?type=tv";
48-
}
49-
50-
// Toggles the watch button of Season located on SeasonPage
51-
@GetMapping("toggle")
52-
public String toggleSeWatch(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @AuthenticationPrincipal UserDetails userDetails)
53-
{
54-
Integer userId = userRepository.findByUsername(userDetails.getUsername()).get().getId();
55-
seasonService.toggleSeasonWatch(userId, tmdbId, seasonNo);
56-
return "redirect:/track-servie/servies/"+tmdbId+"/Season/"+seasonNo;
57-
}
58-
5930
// Toggles the watch button of multiple Episodes located on SeasonPage
6031
@GetMapping("toggleepisodes")
6132
public String toggleMultipleEpisodeWatch(@PathVariable Integer tmdbId,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package servie.track_servie.controller;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.http.HttpStatus;
5+
import org.springframework.http.ResponseEntity;
6+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
7+
import org.springframework.security.core.userdetails.UserDetails;
8+
import org.springframework.ui.Model;
9+
import org.springframework.web.bind.annotation.GetMapping;
10+
import org.springframework.web.bind.annotation.PathVariable;
11+
import org.springframework.web.bind.annotation.PutMapping;
12+
import org.springframework.web.bind.annotation.RequestMapping;
13+
import org.springframework.web.bind.annotation.RequestParam;
14+
import org.springframework.web.bind.annotation.RestController;
15+
import org.springframework.web.util.UriComponentsBuilder;
16+
import servie.track_servie.payload.dtos.SeasonPageDtos.SeasonDto;
17+
import servie.track_servie.repository.UserRepository;
18+
import servie.track_servie.service.EpisodeService;
19+
import servie.track_servie.service.SeasonService;
20+
21+
@RestController
22+
@RequestMapping("/track-servie/react/servies/{tmdbId}/Season/{seasonNo}")
23+
public class SeasonControllerReact
24+
{
25+
@Autowired
26+
SeasonService seasonService;
27+
@Autowired
28+
EpisodeService episodeService;
29+
@Autowired
30+
private UserRepository userRepository;
31+
32+
// Returns SeasonPage containing selected Season from SeriesPage
33+
@GetMapping("")
34+
public ResponseEntity<SeasonDto> getSeason(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo)
35+
{
36+
Integer userId = userRepository.findByUsername("Aakkiieezz").get().getId();
37+
SeasonDto season = seasonService.getSeason(userId, tmdbId, seasonNo);
38+
return new ResponseEntity<SeasonDto>(season, null, HttpStatus.OK);
39+
}
40+
41+
@PutMapping("toggle")
42+
public ResponseEntity<HttpStatus> toggleWatch(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo)
43+
{
44+
Integer userId = userRepository.findByUsername("Aakkiieezz").get().getId();
45+
seasonService.toggleSeasonWatch(userId, tmdbId, seasonNo);
46+
return ResponseEntity.status(HttpStatus.OK).build();
47+
}
48+
49+
// Redirects to SeasonPage with changed Season Poster
50+
@GetMapping("posterChange")
51+
public String changeImage(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @RequestParam(value = "filePath", defaultValue = "") String filePath, Model model, @AuthenticationPrincipal UserDetails userDetails)
52+
{
53+
Integer userId = userRepository.findByUsername(userDetails.getUsername()).get().getId();
54+
seasonService.changeImage(userId, tmdbId, seasonNo, filePath);
55+
// return "redirect:/track-servie/servies/"+tmdbId;
56+
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("redirect:/track-servie/servies/{tmdbId}")
57+
.queryParam("type", "tv");
58+
return builder.buildAndExpand(tmdbId).toUriString();
59+
}
60+
}

0 commit comments

Comments
 (0)