fix(backend): include EpisodeSeen in season episodes and add entry credits endpoint
- Add getEntryCredits service method returning all cast + crew with People, ordered by cast_type, order, episode_count - Add getEntryCredits controller method - Add GET /entries/:id/credits route in entry.routes.js - Include EpisodeSeen association in getSeasonEpisodes so seen dates are returned to frontend
This commit is contained in:
1 parent
e460290b9b
commit
22d111ef71
7 files changed
+50
-2
No files matched your search
@@ -99,6 +99,13 @@ class EntryController {
|
|||||||
res.status(200).json(seasons);
|
res.status(200).json(seasons);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// * GET - Get ALL credits (cast + crew) for an entry
|
||||||
|
getEntryCredits = asyncWrapper(async (req, res) => {
|
||||||
|
const { id } = req.params;
|
||||||
|
const credits = await _entryService.getEntryCredits(id);
|
||||||
|
res.status(200).json(credits);
|
||||||
|
});
|
||||||
|
|
||||||
// * PUT - REQUEST ENTRY REFRECH
|
// * PUT - REQUEST ENTRY REFRECH
|
||||||
refrechEntry = asyncWrapper(async (req, res, next) => {
|
refrechEntry = asyncWrapper(async (req, res, next) => {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const Episode = require("../models/Episode");
|
const Episode = require("../models/Episode");
|
||||||
|
const EpisodeSeen = require("../models/EpisodeSeen");
|
||||||
const Season = require("../models/Season");
|
const Season = require("../models/Season");
|
||||||
|
|
||||||
|
|
||||||
@@ -53,7 +54,12 @@ class SeasonController {
|
|||||||
const episodes = await Episode.findAll({
|
const episodes = await Episode.findAll({
|
||||||
where: {
|
where: {
|
||||||
season_id: req.params.id
|
season_id: req.params.id
|
||||||
}
|
},
|
||||||
|
include: [{ model: EpisodeSeen }],
|
||||||
|
order: [
|
||||||
|
['episode_number', 'ASC'],
|
||||||
|
[EpisodeSeen, 'date_seen', 'ASC'],
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (episodes) {
|
if (episodes) {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ entryRouter.put('/:id/ids', entryController.updateEntryIds);
|
|||||||
entryRouter.delete('/:id', entryController.deleteEntry);
|
entryRouter.delete('/:id', entryController.deleteEntry);
|
||||||
|
|
||||||
entryRouter.get('/:id/seasons', entryController.getEntrySeasons);
|
entryRouter.get('/:id/seasons', entryController.getEntrySeasons);
|
||||||
|
entryRouter.get('/:id/credits', entryController.getEntryCredits);
|
||||||
entryRouter.put('/:id/refresh', entryController.refrechEntry);
|
entryRouter.put('/:id/refresh', entryController.refrechEntry);
|
||||||
entryRouter.put('/:id/fetch-collection', entryController.fetchEntryCollection);
|
entryRouter.put('/:id/fetch-collection', entryController.fetchEntryCollection);
|
||||||
|
|
||||||
|
|||||||
@@ -118,6 +118,36 @@ class EntryService {
|
|||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves ALL credits (cast + crew) for an entry with associated people.
|
||||||
|
* Used by the Cast & Crew page to lazy-render large credit lists.
|
||||||
|
*
|
||||||
|
* @param {number} id - The entry ID.
|
||||||
|
* @returns {Promise<Array>} Array of plain credit objects with `people` populated.
|
||||||
|
*/
|
||||||
|
async getEntryCredits(id) {
|
||||||
|
if (!id) {
|
||||||
|
throw new BadRequestError("Entry id not provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
const entry = await Entry.findByPk(id, { attributes: ['id'] });
|
||||||
|
if (!entry) {
|
||||||
|
throw new NotFoundError("Entry with the provided id was not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
const credits = await Credit.findAll({
|
||||||
|
where: { entry_id: id },
|
||||||
|
include: [{ model: People, as: 'person' }],
|
||||||
|
order: [
|
||||||
|
['cast_type', 'ASC'],
|
||||||
|
['order', 'ASC'],
|
||||||
|
['episode_count', 'DESC'],
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
return credits.map(c => c.get({ plain: true }));
|
||||||
|
}
|
||||||
|
|
||||||
async createEntry(data, plain = true) {
|
async createEntry(data, plain = true) {
|
||||||
// creating the object
|
// creating the object
|
||||||
var is_tvseries = data.release_date == null ? true : false;
|
var is_tvseries = data.release_date == null ? true : false;
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ Entry CRUD and management.
|
|||||||
| `refresh(id)` | PUT | `/entries/:id/refresh` |
|
| `refresh(id)` | PUT | `/entries/:id/refresh` |
|
||||||
| `fetchCollection(id)` | PUT | `/entries/:id/fetch-collection` |
|
| `fetchCollection(id)` | PUT | `/entries/:id/fetch-collection` |
|
||||||
| `getSeasons(id)` | GET | `/entries/:id/seasons` |
|
| `getSeasons(id)` | GET | `/entries/:id/seasons` |
|
||||||
|
| `getCredits(id)` | GET | `/entries/:id/credits` |
|
||||||
| `syncSeries()` | GET | `/entries/sync-series` |
|
| `syncSeries()` | GET | `/entries/sync-series` |
|
||||||
| `uploadMedia(id, formData)` | POST | `/entries/:id/media` |
|
| `uploadMedia(id, formData)` | POST | `/entries/:id/media` |
|
||||||
| `setMediaSelected(entryId, mediaId)` | PUT | `/entries/:entryId/media/:mediaId` |
|
| `setMediaSelected(entryId, mediaId)` | PUT | `/entries/:entryId/media/:mediaId` |
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ All endpoints are prefixed with `/api/v1`. See [[Backend]] for server setup.
|
|||||||
| `PUT` | `/entries/:id/ids` | Update external IDs |
|
| `PUT` | `/entries/:id/ids` | Update external IDs |
|
||||||
| `DELETE` | `/entries/:id` | Delete entry and all related data |
|
| `DELETE` | `/entries/:id` | Delete entry and all related data |
|
||||||
| `GET` | `/entries/:id/seasons` | Get all seasons for a TV entry |
|
| `GET` | `/entries/:id/seasons` | Get all seasons for a TV entry |
|
||||||
|
| `GET` | `/entries/:id/credits` | Get ALL credits (cast + crew) for an entry, with associated `person` populated. Used by [[Pages#EntryCastsPage\|EntryCastsPage]] |
|
||||||
| `PUT` | `/entries/:id/refresh` | Force refresh from TMDB |
|
| `PUT` | `/entries/:id/refresh` | Force refresh from TMDB |
|
||||||
| `PUT` | `/entries/:id/fetch-collection` | Fetch/create TMDB collection for entry |
|
| `PUT` | `/entries/:id/fetch-collection` | Fetch/create TMDB collection for entry |
|
||||||
| `GET` | `/entries/sync-series` | Batch refresh all non-ended TV series |
|
| `GET` | `/entries/sync-series` | Batch refresh all non-ended TV series |
|
||||||
|
|||||||
+3
-1
@@ -74,10 +74,12 @@ Sections:
|
|||||||
Full cast & crew grid for an entry. Route: `/entry/:id/cast`. Width: `max-w-4xl`.
|
Full cast & crew grid for an entry. Route: `/entry/:id/cast`. Width: `max-w-4xl`.
|
||||||
|
|
||||||
- Breadcrumb: `Entry Title / Cast & Crew` (Title links back to EntryDetailsPage)
|
- Breadcrumb: `Entry Title / Cast & Crew` (Title links back to EntryDetailsPage)
|
||||||
|
- Loads ALL credits (cast + crew) via `useEntryCredits` (`GET /entries/:id/credits`) — not limited to the 10-cast preview shown on EntryDetailsPage
|
||||||
- Filter: All / Cast / Crew
|
- Filter: All / Cast / Crew
|
||||||
- Sort: Credit Order, Popularity, Name, Birthday, Gender, Episode Count (TV only)
|
- Sort: Credit Order, Popularity, Name, Birthday, Gender, Episodes (TV only)
|
||||||
- Sort direction toggle (asc/desc)
|
- Sort direction toggle (asc/desc)
|
||||||
- Shows role/job label and episode count for TV series
|
- Shows role/job label and episode count for TV series
|
||||||
|
- **Lazy loading**: renders 24 credits per chunk; an `IntersectionObserver` sentinel auto-loads the next chunk on scroll
|
||||||
- Links to [[Pages#PersonDetailsPage|PersonDetailsPage]]
|
- Links to [[Pages#PersonDetailsPage|PersonDetailsPage]]
|
||||||
|
|
||||||
## SeasonPage
|
## SeasonPage
|
||||||
|
|||||||
Reference in new issue
Block a user