V1 avec bugs

This commit is contained in:
2026-04-03 15:27:51 +02:00
parent 9ae8dd93de
commit ec78173e05
10 changed files with 387 additions and 9 deletions

View File

@@ -0,0 +1,70 @@
<?php
namespace App\Domain\Ingredients;
use App\Domain\Controller;
use App\Domain\Ingredients\IngredientRepository;
use App\Domain\Tags\TagRepository;
use App\Helpers\Authentification;
use App\Http\JSONResponse;
use App\Http\Request;
use App\Infrastructure\View;
class IngredientManagementController extends Controller {
public static function defineRoutes(): array
{
return [
self::Route( routeUrl: '/manage/ingredients', routeName: 'manage->ingredients', routeAction: 'index' ),
self::Route( routeUrl: '/ingredients/edit/{int}', routeName: 'ingredients->edit', routeAction: 'edit', routeMethods: [ 'POST' ] ),
self::Route( routeUrl: '/ingredients/delete/{int}', routeName: 'ingredients->delete', routeAction: 'delete' ),
];
}
public function index(){
if( !Authentification::isLoggedIn() )
die( "Not logged in" );
$tags = new IngredientRepository()->getAll();
return new View( 'ingredients/index', [
'ingredients' => $tags,
]);
}
public function edit( int $idIngredient ): never {
if( !Authentification::isLoggedIn() )
die( "Not logged in" );
$ing = new IngredientRepository()->getByID( $idIngredient );
if( !$ing )
die( "Ingredient not found" );
$name = Request::post( 'modif_ingr' );
if( !$name || $name == "" )
JSONResponse::sendError( [ 'error' => 'Name not defined' ] );
$ing->nom_ingredient = $name;
if( !new IngredientRepository()->update( $ing ) )
JSONResponse::sendError( [ 'error' => 'An error occured while updating ingredient' ] );
Request::redirectTo( 'manage->ingredients');
}
public function delete( int $idIngredient ): never {
if( !Authentification::isLoggedIn() )
die( "Not logged in" );
$ing = new IngredientRepository()->getByID( $idIngredient );
if( !$ing )
die( "Tag not found" );
if( !new IngredientRepository()->delete( $ing ) )
JSONResponse::sendError( [ 'error' => 'An error occured while deleting ingredient' ] );
Request::redirectTo( 'manage->ingredients' );
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace App\Domain\Tags;
use App\Domain\Controller;
use App\Domain\Ingredients\IngredientRepository;
use App\Domain\Tags\TagRepository;
use App\Helpers\Authentification;
use App\Http\JSONResponse;
use App\Http\Request;
use App\Infrastructure\View;
class TagManagementController extends Controller {
public static function defineRoutes(): array
{
return [
self::Route( routeUrl: '/manage/tags', routeName: 'manage->tags', routeAction: 'index' ),
self::Route( routeUrl: '/tags/edit/{int}', routeName: 'tags->edit', routeAction: 'edit', routeMethods: [ 'POST' ] ),
self::Route( routeUrl: '/tags/delete/{int}', routeName: 'tags->delete', routeAction: 'delete' ),
];
}
public function index(){
if( !Authentification::isLoggedIn() )
die( "Not logged in" );
$tags = new TagRepository()->getAll();
return new View( 'tags/index', [
'tags' => $tags,
]);
}
public function edit( int $idTag ): never {
if( !Authentification::isLoggedIn() )
die( "Not logged in" );
$tag = new TagRepository()->getByID( $idTag );
if( !$tag )
die( "Tag not found" );
$name = Request::post( 'modif_tag' );
if( !$name || $name == "" )
JSONResponse::sendError( [ 'error' => 'Name not defined' ] );
$tag->nom_tag = $name;
if( !new TagRepository()->update( $tag ) )
JSONResponse::sendError( [ 'error' => 'An error occured while updating tag' ] );
Request::redirectTo( 'manage->tags');
}
public function delete( int $idTag ): never {
if( !Authentification::isLoggedIn() )
die( "Not logged in" );
$tag = new \App\Domain\Tags\TagRepository()->getByID( $idTag );
if( !$tag )
die( "Tag not found" );
if( !new TagRepository()->delete( $tag ) )
JSONResponse::sendError( [ 'error' => 'An error occured while deleting tag' ] );
Request::redirectTo( 'manage->tags' );
}
}