initial commit

This commit is contained in:
Arno Kaimbacher 2023-03-03 16:54:28 +01:00
commit 4fc3bb0a01
202 changed files with 41729 additions and 0 deletions

41
start/inertia.ts Normal file
View file

@ -0,0 +1,41 @@
/*
|--------------------------------------------------------------------------
| Inertia Preloaded File
|--------------------------------------------------------------------------
|
| Any code written inside this file will be executed during the application
| boot.
|
*/
import Inertia from '@ioc:EidelLev/Inertia';
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
Inertia.share({
errors: (ctx) => {
return ctx.session.flashMessages.get('errors');
},
flash: (ctx) => {
return {
message: ctx.session.flashMessages.get('message'),
};
},
// params: ({ params }) => params,
authUser: ({ auth }: HttpContextContract) => {
if (auth.user) {
return auth.user;
// {
// 'id': auth.user.id,
// 'login': auth.user.login,
// };
} else {
return null;
}
},
}).version(() => Inertia.manifestFile('public/assets/manifest.json'));
// 'flash' => [
// 'message' => fn () => $request->session()->get('message'),
// ],

55
start/kernel.ts Normal file
View file

@ -0,0 +1,55 @@
/*
|--------------------------------------------------------------------------
| Application middleware
|--------------------------------------------------------------------------
|
| This file is used to define middleware for HTTP requests. You can register
| middleware as a `closure` or an IoC container binding. The bindings are
| preferred, since they keep this file clean.
|
*/
import Server from '@ioc:Adonis/Core/Server';
/*
|--------------------------------------------------------------------------
| Global middleware
|--------------------------------------------------------------------------
|
| An array of global middleware, that will be executed in the order they
| are defined for every HTTP requests.
|
*/
Server.middleware.register([
() => import('@ioc:Adonis/Core/BodyParser'),
() => import('@ioc:EidelLev/Inertia/Middleware'),
// () => import('ioc:EidelLev/Stardust/Middleware'),
() => import('@eidellev/adonis-stardust/build/middleware/Stardust'),
// () => import('adonis-acl/src/Middlewares/Init'),
]);
/*
|--------------------------------------------------------------------------
| Named middleware
|--------------------------------------------------------------------------
|
| Named middleware are defined as key-value pair. The value is the namespace
| or middleware function and key is the alias. Later you can use these
| alias on individual routes. For example:
|
| { auth: () => import('App/Middleware/Auth') }
|
| and then use it as follows
|
| Route.get('dashboard', 'UserController.dashboard').middleware('auth')
|
*/
Server.middleware.registerNamed({
auth: 'App/Middleware/Auth',
// is: () => import('App/Middleware/Is'),
// can: () => import('App/Middleware/Can'),
// is: "Adonis/Acl/Is",
// can: "Adonis/Acl/Can"
is: () => import('App/Middleware/Role'),
can: () => import('App/Middleware/Can'),
});

125
start/routes.ts Normal file
View file

@ -0,0 +1,125 @@
/*
|--------------------------------------------------------------------------
| Routes
|--------------------------------------------------------------------------
|
| This file is dedicated for defining HTTP routes. A single file is enough
| for majority of projects, however you can define routes in different
| files and just make sure to import them inside this file. For example
|
| Define routes in following two files
| start/routes/cart.ts
| start/routes/customer.ts
|
| and then import them inside `start/routes.ts` as follows
|
| import './routes/cart'
| import './routes/customer''
|
*/
import Route from '@ioc:Adonis/Core/Route';
// import Inertia from '@ioc:EidelLev/Inertia';
import AuthValidator from 'App/Validators/AuthValidator';
import HealthCheck from '@ioc:Adonis/Core/HealthCheck';
import User from 'App/Models/User';
// import AuthController from 'App/Controllers/Http/Auth/AuthController';
import './routes/api';
Route.get('health', async ({ response }) => {
const report = await HealthCheck.getReport();
return report.healthy ? response.ok(report) : response.badRequest(report);
});
Route.get('/', async ({ view }) => {
return view.render('welcome');
}).as('dashboard2');
// Route.inertia('/about', 'App');
Route.group(() => {
Route.get('/', async ({ inertia }) => {
const users = await User.query().orderBy('login');
return inertia.render('App', {
testing: 'this is a test',
users: users,
});
}).as('index');
// Route.get('/login', async ({ inertia }) => {
// return inertia.render('Auth/Login');
// }).as('login.show');
Route.get('/register', async ({ inertia }) => {
return inertia.render('register-view/register-view-component');
}).as('register.show');
Route.post('/register', async ({ request, response }) => {
console.log({
registerBody: request.body(),
});
const data = await request.validate(AuthValidator);
console.log({ data });
return response.redirect().toRoute('app.index');
}).as('register.store');
})
.prefix('app')
.as('app');
Route.get('/dashboard', async ({ inertia }) => {
return inertia.render('Dashboard');
})
.as('dashboard')
.middleware('auth');
// Route.on("/login").render("signin");
Route.get('/app/login', async ({ inertia }) => {
return inertia.render('Auth/Login');
}).as('app.login.show');
// Route.post("/login", "Users/AuthController.login");
Route.post('/app/login', 'Auth/AuthController.login').as('login.store');
// Route.on("/signup").render("signup");
// Route.post("/signup", "AuthController.signup");
Route.post('/signout', 'Auth/AuthController.logout').as('logout');
Route.group(() => {
Route.get('/settings', async ({ inertia }) => {
return inertia.render('Admin/Settings');
}).as('settings');
Route.get('/user', 'UsersController.index').as('user.index');
Route.get('/user/create', 'UsersController.create').as('user.create');
Route.post('/user/store', 'UsersController.store').as('user.store');
Route.get('/user/:id', 'UsersController.show').as('user.show').where('id', Route.matchers.number());
Route.get('/user/:id/edit', 'UsersController.edit').as('user.edit').where('id', Route.matchers.number());
Route.put('/user/:id/update', 'UsersController.update').as('user.update').where('id', Route.matchers.number());
Route.delete('/user/:id', 'UsersController.destroy').as('user.destroy').where('id', Route.matchers.number());
// Route.resource('user', 'UsersController');
Route.get('/role', 'RoleController.index').as('role.index');
Route.get('/role/create', 'RoleController.create').as('role.create');
Route.post('/role/store', 'RoleController.store').as('role.store');
Route.get('/role/:id', 'RoleController.show').as('role.show').where('id', Route.matchers.number());
Route.get('/role/:id/edit', 'RoleController.edit').as('role.edit').where('id', Route.matchers.number());
Route.put('/role/:id/update', 'RoleController.update').as('role.update').where('id', Route.matchers.number());
Route.delete('/role/:id', 'RoleController.destroy').as('role.destroy').where('id', Route.matchers.number());
})
.namespace('App/Controllers/Http/Admin')
.prefix('admin')
// .middleware(['auth', 'can:dataset-list,dataset-publish']);
.middleware(['auth', 'is:administrator,moderator']);
Route.get('/edit-account-info', 'UsersController.accountInfo')
.as('admin.account.info')
.namespace('App/Controllers/Http/Admin')
.middleware(['auth']);
Route.post('/edit-account-info/store/:id', 'UsersController.accountInfoStore')
.as('admin.account.info.store')
.where('id', Route.matchers.number())
.namespace('App/Controllers/Http/Admin')
.middleware(['auth']);
// Route::post('change-password', 'UserController@changePasswordStore')->name('admin.account.password.store');

18
start/routes/api.ts Normal file
View file

@ -0,0 +1,18 @@
import Route from '@ioc:Adonis/Core/Route';
// API
Route.group(() => {
// Route.post("register", "AuthController.register");
// Route.post("login", "AuthController.login");
Route.group(() => {
Route.get('authors', 'AuthorsController.index').as('author.index');
Route.get('datasets', 'DatasetController.index').as('dataset.index');
// Route.get("author/:id", "TodosController.show");
// Route.put("author/update", "TodosController.update");
// Route.post("author", "TodosController.store");
});
// .middleware("auth:api");
})
.namespace('App/Controllers/Http/Api')
.prefix('api');