Backend: Added People rouets, controller and service
This commit is contained in:
1 parent
032d92994d
commit
b5ea25631d
4 files changed
+338
No files matched your search
@@ -0,0 +1,72 @@
|
||||
const express = require('express');
|
||||
const peopleRouter = express.Router();
|
||||
const { peoplePicturesUpload } = require('../services/mutlerStorageLocations');
|
||||
const mediaOptimizerService = require('../services/mediaOptimizerService');
|
||||
const peopleController = require('../controllers/peopleController');
|
||||
|
||||
// ! /people
|
||||
|
||||
// Get all people
|
||||
peopleRouter.get('/', peopleController.getAllPeople);
|
||||
|
||||
// Get popular people
|
||||
peopleRouter.get('/popular', peopleController.getPopularPeople);
|
||||
|
||||
// Search people
|
||||
peopleRouter.get('/search', peopleController.searchPeople);
|
||||
|
||||
// Get person by ID
|
||||
peopleRouter.get('/:id', peopleController.getPersonById);
|
||||
|
||||
// Create a new person
|
||||
peopleRouter.post('/', peopleController.createPerson);
|
||||
|
||||
// Fetch and save person from TMDB
|
||||
peopleRouter.post('/fetch', peopleController.fetchAndSavePersonByTmdbId);
|
||||
|
||||
// Update a person
|
||||
peopleRouter.put('/:id', peopleController.updatePerson);
|
||||
|
||||
// Refresh person data from TMDB
|
||||
peopleRouter.put('/:id/refresh', peopleController.refreshPerson);
|
||||
|
||||
// Delete a person
|
||||
peopleRouter.delete('/:id', peopleController.deletePerson);
|
||||
|
||||
// Get person credits
|
||||
peopleRouter.get('/:id/credits', peopleController.getPersonCredits);
|
||||
|
||||
// Person media upload handler
|
||||
const upload = peoplePicturesUpload.fields([
|
||||
{ name: 'profile', maxCount: 1 }
|
||||
]);
|
||||
|
||||
// Upload person profile picture
|
||||
peopleRouter.post('/:id/media', upload, async (req, res) => {
|
||||
try {
|
||||
const personId = req.params.id;
|
||||
let result = { success: true, files: [] };
|
||||
|
||||
// Handle profile picture
|
||||
if (req.files.profile) {
|
||||
const profileFile = req.files.profile[0];
|
||||
const filePath = profileFile.path;
|
||||
const fileName = profileFile.filename;
|
||||
|
||||
// Generate preview for profile picture
|
||||
const previewPath = await mediaOptimizerService.doGeneratePreview('people', 'profiles', fileName);
|
||||
|
||||
result.files.push({
|
||||
type: 'profile',
|
||||
original: fileName,
|
||||
preview: previewPath ? path.basename(previewPath) : null
|
||||
});
|
||||
}
|
||||
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = peopleRouter;
|
||||
Reference in new issue
Block a user