From 299f566b96dfa2de2c76f08bc1427fefa5d3c7f6 Mon Sep 17 00:00:00 2001 From: Mohammed Abad Date: Sun, 28 Apr 2024 00:26:07 +0100 Subject: [PATCH] add favorit button in entry page --- backend/routes/entryRoutes.js | 75 +++++++++++++------ backend/services/entryService.js | 5 +- .../src/app/core/services/entry.service.ts | 18 +++-- .../entry/entry-page/entry-page.component.css | 37 +++++++-- .../entry-page/entry-page.component.html | 22 ++++-- .../entry/entry-page/entry-page.component.ts | 18 ++++- 6 files changed, 130 insertions(+), 45 deletions(-) diff --git a/backend/routes/entryRoutes.js b/backend/routes/entryRoutes.js index 6c34154..be4a876 100644 --- a/backend/routes/entryRoutes.js +++ b/backend/routes/entryRoutes.js @@ -76,39 +76,70 @@ entryRouter.post('/', async (req, res) => { res.status(201).json(entry); }); -// * PUT - REQUEST ENTRY UPDATE + +// * PUT - ENTRY UPDATE entryRouter.put('/:id', async (req, res) => { const { id } = req.params; + const { favorit, hidden, watchlist } = req.body; - // getting the old entry - const oldEntry = await Entry.findByPk(id, { - include: [ - { model: EntryId, as: 'entryId' }, - { model: EntryRating, as: 'entryRating' }, - { model: EntrySeen, as: 'entrySeen' }, - { - model: Genre, - as: 'genres', - attributes: ['id'], - through: { - attributes: [] - } - } - ] + // ? checking if the provied id is valid + const oldEntry = await Entry.findByPk(id); + + if (!oldEntry) + return res.status(404).json({ message: `Entry with the provided id was not found` }); + + // ? updating + await oldEntry.update({ + favorit: favorit, + watchlist: watchlist, + hidden: hidden }); - if (!oldEntry) { - // TODO 404 error - return; - } - // getting new data from TMDB + // ? returning a new entry with updated values + let includes = [ + { model: EntryId, as: 'entryId' }, + { model: EntryRating, as: 'entryRating' }, + { model: EntrySeen, as: 'entrySeen' }, + { + model: Genre, + as: 'genres', + attributes: ['id'], + through: { + attributes: [] + } + } + ]; + + if (oldEntry.is_tvseries) includes.push({ model: Season, as: 'seasons' }); + + const entry = await Entry.findByPk(id, { + include: includes + }); + + res.status(201).json(entry); +}); + +// * GET - REQUEST ENTRY UPDATE +entryRouter.get('/:id/refrech', async (req, res) => { + const { id } = req.params; + + // ? checking if the provied id is valid + const oldEntry = await Entry.findByPk(id); + + if (!oldEntry) + return res.status(404).json({ message: `Entry id not found` }); + + + // ? getting new data from TMDB const data = await fetchEntryData(oldEntry.entryId.tmdb_id, oldEntry.is_tvseries); if (data == null) return res.status(500).json({ message: `Counldn't fetch data from TMDB` }); - // updating + // ? updating await updateEntry(oldEntry, data); + + // ? returning a new entry with updated values let includes = [ { model: EntryId, as: 'entryId' }, { model: EntryRating, as: 'entryRating' }, diff --git a/backend/services/entryService.js b/backend/services/entryService.js index 37b6883..be94505 100644 --- a/backend/services/entryService.js +++ b/backend/services/entryService.js @@ -9,7 +9,7 @@ const Episode = require('../models/Episode.js'); async function saveEntry(data) { if (data == null) return; - + // creating the object var is_tvseries = data.release_date == null ? true : false; @@ -24,6 +24,7 @@ async function saveEntry(data) { country: data.production_countries.length > 0 ? data.production_countries[0].name : null, is_tvseries: is_tvseries, + watchlist: true, status: data.status, genres: data.genre_ids, @@ -99,6 +100,8 @@ async function saveEntry(data) { episodes.push(savedEpisode); } + // TODO fetch cast + savedSeason.setDataValue('episodes', episodes); seasons.push(savedSeason) } diff --git a/frontend/src/app/core/services/entry.service.ts b/frontend/src/app/core/services/entry.service.ts index 6683009..59ec2b1 100644 --- a/frontend/src/app/core/services/entry.service.ts +++ b/frontend/src/app/core/services/entry.service.ts @@ -30,17 +30,21 @@ export class EntryService { } // update entry - updateEntryById(entry: Entry) { - return this.http.post(`${this.backend_apiUrl}/${this.apiAction}`, { - entry, - }); + updateEntry(entry: Entry) { + return this.http.put( + `${this.backend_apiUrl}/${this.apiAction}/${entry.id}`, + { + favorit: entry.favorit, + watchlist: entry.watchlist, + hidden: entry.hidden, + } + ); } // update entry refrechEntryById(entryId: number) { - return this.http.put( - `${this.backend_apiUrl}/${this.apiAction}/${entryId}`, - [null] + return this.http.get( + `${this.backend_apiUrl}/${this.apiAction}/${entryId}/refrech` ); } diff --git a/frontend/src/app/features/entry/entry-page/entry-page.component.css b/frontend/src/app/features/entry/entry-page/entry-page.component.css index ed3c96e..31eb069 100644 --- a/frontend/src/app/features/entry/entry-page/entry-page.component.css +++ b/frontend/src/app/features/entry/entry-page/entry-page.component.css @@ -67,6 +67,11 @@ margin-top: 200px !important; } +/* ! LEFT PART - SIDE INFO */ +.left-col { + min-width: 240px; +} + .poster { padding: px 10px 0 10px; } @@ -88,22 +93,27 @@ background-color: transparent !important; } -/* ! DESCRIPTION */ +.side-info strong { + color: var(--shz-blue-default); +} + +/* ! RIGHT PART - DESCRIPTION */ .title { color: rgba(0, 0, 0, 0.868); font-weight: bolder; font-size: 2.9rem !important; } - [data-bs-theme=dark] .title { color: white; } +.right-col .entry-actions span { + color: black; +} -.side-info strong { - color: #008cff; - +.right-col .entry-actions span:hover { + color: var(--shz-blue-default); } .btn-icon-only { @@ -121,7 +131,7 @@ color: #008cff; } -.interaction-btns { +/* .interaction-btns { position: absolute; top: 10px; right: 15px; @@ -133,4 +143,19 @@ padding-top: 0; padding-bottom: 0; width: 50px; +} */ + +/* * favorit button */ +.btn-icon-only-favorite { + border: none; + background: none; + cursor: pointer; +} + +.right-col .entry-actions .favorite:hover span { + color: var(--shz-red-danger); +} + +.right-col .entry-actions .favorite span { + color: var(--shz-gold-1); } \ No newline at end of file diff --git a/frontend/src/app/features/entry/entry-page/entry-page.component.html b/frontend/src/app/features/entry/entry-page/entry-page.component.html index c160fb2..1369f35 100644 --- a/frontend/src/app/features/entry/entry-page/entry-page.component.html +++ b/frontend/src/app/features/entry/entry-page/entry-page.component.html @@ -3,7 +3,7 @@
-
+
Movie Poster @@ -33,21 +33,24 @@

-

-
Seen With:
{{seen.seen_with.split(", ").join("\n")}} +
+ Seen With:
+ {{seen.seen_with}}
@@ -61,13 +64,18 @@
-
+
-
+

{{this.entry.title}}

-
+
+ +