Add season refresh, rating display, and actions dropdown to SeasonPage
Backend: Added PUT /seasons/:id/refresh endpoint that fetches updated TMDB data for a single season. Frontend: - New SeasonRatingDialog for rating seasons via StarRating - useRefreshSeason and useUpdateSeason hooks with query invalidation - SeasonPage now shows inline season rating (user + TMDB) - Mark Watched, Rate, and Refresh actions moved under a dropdown menu
This commit is contained in:
1 parent
1aa0a84f4d
commit
4d88747649
6 files changed
+247
-13
No files matched your search
@@ -1,6 +1,9 @@
|
||||
const Episode = require("../models/Episode");
|
||||
const EpisodeSeen = require("../models/EpisodeSeen");
|
||||
const Season = require("../models/Season");
|
||||
const Entry = require("../models/Entry");
|
||||
const EntryId = require("../models/EntryId");
|
||||
const { fetchSeasonData } = require("../services/tmdbService");
|
||||
|
||||
class SeasonController {
|
||||
constructor() {
|
||||
@@ -88,6 +91,48 @@ class SeasonController {
|
||||
}
|
||||
}
|
||||
|
||||
async refreshSeason(req, res) {
|
||||
try {
|
||||
const season = await Season.findByPk(req.params.id, {
|
||||
include: [
|
||||
{
|
||||
model: Entry,
|
||||
as: "entry",
|
||||
include: [{ model: EntryId, as: "entryId" }],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
if (!season) {
|
||||
return res.status(404).send("Season not found");
|
||||
}
|
||||
|
||||
const tmdbTvId = season.entry?.entryId?.tmdb_id;
|
||||
if (!tmdbTvId) {
|
||||
return res.status(400).send("Entry has no TMDB ID");
|
||||
}
|
||||
|
||||
const seasonData = await fetchSeasonData(tmdbTvId, season.season_number);
|
||||
if (!seasonData) {
|
||||
return res.status(500).send("Couldn't fetch data from TMDB");
|
||||
}
|
||||
|
||||
await season.update({
|
||||
name: seasonData.name,
|
||||
overview: seasonData.overview,
|
||||
episode_count: seasonData.episodes?.length ?? season.episode_count,
|
||||
air_date: seasonData.air_date,
|
||||
tmdb_rating: seasonData.vote_average,
|
||||
poster_path: seasonData.poster_path,
|
||||
});
|
||||
|
||||
const refreshedSeason = await Season.findByPk(req.params.id);
|
||||
res.send(refreshedSeason);
|
||||
} catch (error) {
|
||||
res.status(500).send(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async deleteSeason(req, res) {
|
||||
try {
|
||||
const deleted = await Season.destroy({
|
||||
|
||||
@@ -19,6 +19,9 @@ seasonRouter.get("/:id/episodes", seasonController.getSeasonEpisodes);
|
||||
// * PUT - Update a season
|
||||
seasonRouter.put("/:id", seasonController.updateSeason);
|
||||
|
||||
// * PUT - Refresh a season from TMDB
|
||||
seasonRouter.put("/:id/refresh", seasonController.refreshSeason);
|
||||
|
||||
// * DELETE - Delete a season
|
||||
seasonRouter.delete("/:id", seasonController.deleteSeason);
|
||||
|
||||
|
||||
Reference in new issue
Block a user