Some checks failed
build.yaml / feat: Implement project management functionality with CRUD operations and UI integration (push) Failing after 0s
feat: Implement project management functionality with CRUD operations and UI integration - added projects_controller.ts for crud operations- added views Edit-vue , Index.vue and Create.vue - small adaptions in menu.ts additional routes is start/routes.ts for projects
50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
// app/controllers/projects_controller.ts
|
|
import Project from '#models/project';
|
|
import type { HttpContext } from '@adonisjs/core/http';
|
|
|
|
export default class ProjectsController {
|
|
// GET /settings/projects
|
|
public async index({ inertia, auth }: HttpContext) {
|
|
const projects = await Project.all();
|
|
// return inertia.render('Admin/Project/Index', { projects });
|
|
return inertia.render('Admin/Project/Index', {
|
|
projects: projects,
|
|
can: {
|
|
edit: await auth.user?.can(['settings']),
|
|
create: await auth.user?.can(['settings']),
|
|
},
|
|
});
|
|
}
|
|
|
|
// GET /settings/projects/create
|
|
public async create({ inertia }: HttpContext) {
|
|
return inertia.render('Admin/Project/Create');
|
|
}
|
|
|
|
// POST /settings/projects
|
|
public async store({ request, response, session }: HttpContext) {
|
|
const data = request.only(['label', 'name', 'description']);
|
|
|
|
await Project.create(data);
|
|
|
|
session.flash('success', 'Project created successfully');
|
|
return response.redirect().toRoute('settings.project.index');
|
|
}
|
|
|
|
// GET /settings/projects/:id/edit
|
|
public async edit({ params, inertia }: HttpContext) {
|
|
const project = await Project.findOrFail(params.id);
|
|
return inertia.render('Admin/Project/Edit', { project });
|
|
}
|
|
|
|
// PUT /settings/projects/:id
|
|
public async update({ params, request, response, session }: HttpContext) {
|
|
const project = await Project.findOrFail(params.id);
|
|
const data = request.only(['label', 'name', 'description']);
|
|
|
|
await project.merge(data).save();
|
|
|
|
session.flash('success', 'Project updated successfully');
|
|
return response.redirect().toRoute('settings.project.index');
|
|
}
|
|
}
|