From 6cb503fe35e68107c5dc4bcc20c46eeccb783f54 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 20 Dec 2025 23:01:24 +0000 Subject: [PATCH] feat: Show last updated movies per year Add API and UI to display the last updated movies for the active year. Co-authored-by: mathieumoran1 --- public/js/app_movies.js | 27 +++++++++++++++++++++++++++ routes/movies.js | 5 ++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/public/js/app_movies.js b/public/js/app_movies.js index d7600e5..0b0f13a 100644 --- a/public/js/app_movies.js +++ b/public/js/app_movies.js @@ -11,6 +11,30 @@ window.onload = async function () { } } + async function fetchMoviesLastUpdated(year, token) { + const el = document.getElementById('movies-last-updated'); + if (!el) return; + + try { + const res = await fetch(`/api/movies/last-update?year=${encodeURIComponent(String(year))}`, { + method: 'GET', + headers: { 'Authorization': `Bearer ${token}` }, + }); + if (!res.ok) return; + + const data = await res.json(); + const lastUpdatedIso = data?.lastUpdated; + if (!lastUpdatedIso) return; + + const d = new Date(lastUpdatedIso); + if (Number.isNaN(d.getTime())) return; + + el.textContent = d.toLocaleString('fr-FR', { dateStyle: 'medium', timeStyle: 'short' }); + } catch (_) { + // Keep the default placeholder (—) + } + } + const activeYear = await fetchActiveYear(); document.title = `Pool Oscars ${activeYear} - Films`; const oscarYearEl = document.getElementById('oscar-year'); @@ -46,6 +70,9 @@ window.onload = async function () { window.location.href = '/'; } + // Populate "Dernière mise à jour des films" banner (per active year) + await fetchMoviesLastUpdated(activeYear, token); + const res = await fetch(`/api/movies?year=${encodeURIComponent(String(activeYear))}`, { method: 'GET', headers: { 'Authorization': `Bearer ${token}` }, diff --git a/routes/movies.js b/routes/movies.js index f941274..6099dce 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -73,7 +73,10 @@ router.get("/last-update", async (req, res) => { try { jwt.verify(token, process.env.JWT_SECRET); - const latestMovie = await Movie.findOne().sort({ updatedAt: -1, createdAt: -1, _id: -1 }); + const year = parseOscarYear(req.query.year); + const filter = year ? { year } : {}; + + const latestMovie = await Movie.findOne(filter).sort({ updatedAt: -1, createdAt: -1, _id: -1 }); if (!latestMovie) { return res.status(200).json({ lastUpdated: null }); }