Files
Showy/backend/controllers/entryController.js
T
Mohammed Abad ab20a5e64f feat: multi-page improvements, bug fixes, and new features
Library:
- Exclude hidden entries from all/movies/tv/favorites tabs (only show in hidden tab)

Entry Details:
- Move favorite, mark watched, and more actions to top-right as icon-only buttons with tooltips
- Fix season card play button — marks next unwatched episode as seen

Seasons Page:
- Fix episode watch button (was a TODO stub, now calls createEpisodeSeen)

Episode Page:
- Fix UI not updating after deleting the last watch record — invalidate season episodes query on delete

Dashboard:
- Fix Top Genres 404 — was calling non-existent GET /statistics, now uses /statistics/watch-time
- Fix TopGenresChart genre counting (Genre objects were wrongly cast as strings)
- Add LibraryGrowthChart (cumulative titles added over time)
- Add MediaTypeChart (Movies vs TV Series donut chart)

Home Page:
- Add TrendingSlider hero at top of page with auto-advance, dots, and prev/next nav
- Fix slider prev/next buttons (stable callbacks via ref, plain buttons, reactive library state)
- Add debounce (400ms) to search input
- Add Top Rated section (movies & TV)
- Add Upcoming section (movies)
- Replace inline "More" expand with link to /discover/:category

Discover Page (new):
- Full-page TMDB browser per category (trending/popular/top-rated/upcoming)
- Movie/TV tab toggle
- IntersectionObserver infinite scroll

Calendar:
- Fix large season numbers — use season.season_number instead of season_id (DB primary key)

Backend:
- Add fetchTopRated() and fetchUpcoming() to tmdbService
- Add GET /entries/tmdb/top-rated/:type and /entries/tmdb/upcoming/movie routes
2026-04-02 03:29:54 +01:00

169 lines
5.1 KiB
JavaScript

const EntryRating = require('../models/EntryRating');
const collectionManager = require('../services/collectionManager');
const entryManager = require('../services/entryManager');
const entryService = require("../services/entryService");
const tmdbService = require('../services/tmdbService');
const asyncWrapper = require('../utils/asyncWrapper');
const _collectionManager = collectionManager;
const _entryManager = entryManager;
const _entryService = entryService;
class EntryController {
constructor() {
if (!EntryController.instance) {
EntryController.instance = this;
}
return EntryController.instance;
}
// * GET ENTRY BY ID
getAllEntries = asyncWrapper(async (req, res) => {
const entries = await _entryService.getAllEntries();
res.status(200).json(entries);
});
// * GET ENTRY BY ID
getEntryById = asyncWrapper(async (req, res) => {
const { id } = req.params;
let entry = await _entryManager.getUpdatedEntry(id);
res.status(200).json(entry);
});
// * POST - FETCH AND CREATE ENTRY USING TMDB ID
fetchAndSaveNewEntry = asyncWrapper(async (req, res) => {
const { tmdb_id, is_tvserie } = req.body;
const createdEntry = await _entryManager.fetchAndSaveNewEntry(tmdb_id, is_tvserie);
res.status(201).json(createdEntry);
});
// * PUT - ENTRY UPDATE
updateEntry = asyncWrapper(async (req, res) => {
const { id } = req.params;
const { entryData } = req.body;
const updatedEntry = await _entryService.updateEntryById(id, entryData, true);
res.status(201).json(updatedEntry);
});
// * PUT - ENTRY Ratings UPDATE
updateEntryRatings = asyncWrapper(async (req, res) => {
const { id } = req.params;
const { entryRatings } = req.body;
const updatedEntryRatings = await _entryService.updateEntryRatings(id, entryRatings);
res.status(200).json(updatedEntryRatings);
});
// * PUT - ENTRY Ratings UPDATE
updateEntryIds = asyncWrapper(async (req, res) => {
const { id } = req.params;
const { entryIds } = req.body;
const updatedEntryIds = await _entryService.updateEntryRatings(id, entryIds);
res.status(200).json(updatedEntryIds);
});
// * DELETE - ENTRY BY ID
deleteEntry = asyncWrapper(async (req, res) => {
const { id } = req.params;
await _entryService.deleteEntryById(id);
res.status(200).json({ message: `Entry with ID ${id} deleted.` });
});
// * GET - SYNC ALL ENTIRES DATA
syncSeries = asyncWrapper(async (req, res, next) => {
const entries = await _entryManager.SyncSeriesData();
res.status(201).json(entries);
});
// * GET - Get seasons of an entry
getEntrySeasons = asyncWrapper(async (req, res) => {
const { id } = req.params;
const seasons = await _entryService.getEntrySeasons(id)
if (seasons.length == 0) {
res.status(204).json({ message: 'Provided entry has no seasons' });
}
res.status(200).json(seasons);
});
// * PUT - REQUEST ENTRY REFRECH
refrechEntry = asyncWrapper(async (req, res, next) => {
const { id } = req.params;
const entry = await _entryManager.refrechEntryById(id)
res.status(201).json(entry);
});
// * PUT - REQUEST COLLECTION REFRECH
fetchEntryCollection = asyncWrapper(async (req, res, next) => {
const { id } = req.params;
const collection = await _collectionManager.fetchCollectionByEntryId(id);
if (collection) {
res.status(201).json(collection);
} else {
res.status(204);
}
});
// * GET - TMDB TRENDING
getTmdbTrending = asyncWrapper(async (req, res) => {
const { type } = req.params;
const { page } = req.query;
const data = await tmdbService.fetchTrending(type, page || 1);
if (!data) return res.status(500).json({ message: 'Failed to fetch trending data' });
res.status(200).json(data);
});
// * GET - TMDB POPULAR
getTmdbPopular = asyncWrapper(async (req, res) => {
const { type } = req.params;
const { page } = req.query;
const data = await tmdbService.fetchPopular(type, page || 1);
if (!data) return res.status(500).json({ message: 'Failed to fetch popular data' });
res.status(200).json(data);
});
// * GET - TMDB SEARCH
getTmdbSearch = asyncWrapper(async (req, res) => {
const { query, page } = req.query;
if (!query) return res.status(400).json({ message: 'Query parameter is required' });
const data = await tmdbService.searchMulti(query, page || 1);
if (!data) return res.status(500).json({ message: 'Failed to search TMDB' });
res.status(200).json(data);
});
// * GET - TMDB TOP RATED
getTmdbTopRated = asyncWrapper(async (req, res) => {
const { type } = req.params;
const { page } = req.query;
const data = await tmdbService.fetchTopRated(type, page || 1);
if (!data) return res.status(500).json({ message: 'Failed to fetch top rated data' });
res.status(200).json(data);
});
// * GET - TMDB UPCOMING
getTmdbUpcoming = asyncWrapper(async (req, res) => {
const { page } = req.query;
const data = await tmdbService.fetchUpcoming(page || 1);
if (!data) return res.status(500).json({ message: 'Failed to fetch upcoming data' });
res.status(200).json(data);
});
}
module.exports = new EntryController();