0% found this document useful (0 votes)
2 views1 page

Admin Genre Indexjs

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Admin Genre Indexjs

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import dbConnect from '@/lib/db/connect';

import Genre from '@/models/genre/genre';

export default async function handler(req, res) {


await dbConnect();

const { method } = req;

switch (method) {
case 'GET':
try {
const genres = await Genre.find({});
res.status(200).json({ success: true, data: genres });
} catch (error) {
res.status(400).json({ success: false, message: error.message });
}
break;

case 'POST':
try {
const { name, subGenres } = req.body;
const newGenre = new Genre({ name, subGenres });
await newGenre.save();
res.status(201).json({ success: true, data: newGenre });
} catch (error) {
res.status(400).json({ success: false, message: error.message });
}
break;

default:
res.status(405).json({ success: false, message: 'Method not allowed' });
}
}

You might also like