import Category from '#models/category';
export default class CategoriesController {
    async index({ view }) {
        const categories = await Category.query().preload('projects');
        return view.render('admin/categories/index', { categories });
    }
    async create({ view }) {
        return view.render('admin/categories/form', { category: null });
    }
    async store({ request, response }) {
        const { name } = request.only(['name']);
        await Category.create({ name });
        return response.redirect('/admin/categories');
    }
    async edit({ view, params, response }) {
        const category = await Category.find(params.id);
        if (!category) {
            return response.notFound();
        }
        return view.render('admin/categories/form', { category });
    }
    async update({ request, params, response }) {
        const category = await Category.find(params.id);
        if (!category) {
            return response.notFound();
        }
        const { name } = request.only(['name']);
        await category.merge({ name }).save();
        return response.redirect('/admin/categories');
    }
    async destroy({ params, response }) {
        const category = await Category.find(params.id);
        if (!category) {
            return response.notFound();
        }
        await category.delete();
        return response.redirect('/admin/categories');
    }
}
//# sourceMappingURL=categories_controller.js.map