Add specific episode-seen

This commit is contained in:
X4Lo committed 2024-05-19 17:03:38 +01:00
1 parent 728dae4e59
commit 29d6e3f503
13 files changed
+323 -22

No files matched your search

+47 -3
View File
@@ -1,15 +1,18 @@
const express = require('express');
const entryRouter = express.Router();
const { fetchEntryData } = require('../services/tmdbService');
const { saveEntry, refrechEntry } = require('../services/entryService');
const { bulkImportMovies, bulkImportTmdb, bulkImportEpisodes } = require('../services/importerService');
const Entry = require('../models/Entry');
const EntryId = require('../models/EntryId');
const EntryRating = require('../models/EntryRating');
const Genre = require('../models/Genre');
const EntrySeen = require('../models/EntrySeen');
const { saveEntry, refrechEntry } = require('../services/entryService');
const Season = require('../models/Season');
const { bulkImportMovies, bulkImportTmdb, bulkImportEpisodes } = require('../services/importerService');
const Media = require('../models/Media');
const entryRouter = express.Router();
const Episode = require('../models/Episode');
// ! /entries
// * GET - ALL ENTRIES
@@ -85,6 +88,47 @@ entryRouter.get('/:id', async (req, res) => {
console.log(error);
}
});
// * GET - Get seasons of an entry
entryRouter.get('/:id/seasons', async (req, res) => {
try {
const { id } = req.params;
if (id == null) { // ! entry id not provided
res.status(404).json({ message: 'Entry id not provided' });
}
const entry = await Entry.findByPk(id);
if (!entry) {
res.status(404).json({ message: 'Entry not found' });
}
const seasons = await Season.findAll({
where: {
entry_id: id
},
attributes: ['id', 'season_number'],
include: [
{ model: Episode, as: 'episodes', attributes: ['id', 'episode_number'], }
],
order: [
['season_number', 'ASC'],
[{ model: Episode, as: 'episodes' }, 'episode_number', 'ASC'],
]
})
if (seasons.length == 0) { // ! no content
res.status(404).json({ message: 'No seasons' });
}
res.status(200).json(seasons);
} catch (error) {
res.status(500).json({ error: error.message });
console.log(error);
}
});
// ! POST
// * POST - CREATE ENTRY
entryRouter.post('/', async (req, res) => {
+6 -5
View File
@@ -4,7 +4,7 @@ const Episode = require('../models/Episode');
const seasonRouter = express.Router();
// ! /seasons
// POST /seasons - Create a new season
// * POST - Create a new season
seasonRouter.post('/', async (req, res) => {
try {
const season = await Season.create(req.body);
@@ -14,7 +14,7 @@ seasonRouter.post('/', async (req, res) => {
}
});
// GET /seasons - Retrieve all seasons
// * GET - Retrieve all seasons
seasonRouter.get('/', async (req, res) => {
try {
const seasons = await Season.findAll();
@@ -24,7 +24,7 @@ seasonRouter.get('/', async (req, res) => {
}
});
// GET /seasons/:id - Retrieve a specific season by id
// * GET - Retrieve a specific season by id
seasonRouter.get('/:id', async (req, res) => {
try {
const season = await Season.findByPk(req.params.id, {
@@ -44,6 +44,7 @@ seasonRouter.get('/:id', async (req, res) => {
}
});
// * GET - Retrieve episodes of a season
seasonRouter.get('/:id/episodes', async (req, res) => {
try {
const episodes = await Episode.findAll({
@@ -62,7 +63,7 @@ seasonRouter.get('/:id/episodes', async (req, res) => {
}
});
// PUT /seasons/:id - Update a season
// * PUT - Update a season
seasonRouter.put('/:id', async (req, res) => {
try {
const [updated] = await Season.update(req.body, {
@@ -79,7 +80,7 @@ seasonRouter.put('/:id', async (req, res) => {
}
});
// DELETE /seasons/:id - Delete a season
// * DELETE - Delete a season
seasonRouter.delete('/:id', async (req, res) => {
try {
const deleted = await Season.destroy({