import Experience from '#models/experience';
import { DateTime } from 'luxon';
export default class ExperiencesController {
    async index({ view }) {
        const experiences = await Experience.query().orderBy('start', 'desc');
        return view.render('admin/experiences/index', { experiences });
    }
    async create({ view }) {
        return view.render('admin/experiences/form', { experience: null });
    }
    async store({ request, response }) {
        const { name, start, end, missions, place } = request.only([
            'name',
            'start',
            'end',
            'missions',
            'place',
        ]);
        await Experience.create({
            name,
            start: DateTime.fromISO(start),
            end: end ? DateTime.fromISO(end) : null,
            missions: missions || null,
            place: place || null,
        });
        return response.redirect('/admin/experiences');
    }
    async edit({ view, params, response }) {
        const experience = await Experience.find(params.id);
        if (!experience) {
            return response.notFound();
        }
        return view.render('admin/experiences/form', { experience });
    }
    async update({ request, params, response }) {
        const experience = await Experience.find(params.id);
        if (!experience) {
            return response.notFound();
        }
        const { name, start, end, missions, place } = request.only([
            'name',
            'start',
            'end',
            'missions',
            'place',
        ]);
        await experience
            .merge({
            name,
            start: DateTime.fromISO(start),
            end: end ? DateTime.fromISO(end) : null,
            missions: missions || null,
            place: place || null,
        })
            .save();
        return response.redirect('/admin/experiences');
    }
    async destroy({ params, response }) {
        const experience = await Experience.find(params.id);
        if (!experience) {
            return response.notFound();
        }
        await experience.delete();
        return response.redirect('/admin/experiences');
    }
}
//# sourceMappingURL=experiences_controller.js.map