Files
logisticsAPI/app/Filament/Pages/Articles.php
Marvin bc82299aa6 Enhance API parameter documentation and introduce reusable component
- Added a new Blade component `<x-logistics.param-table>` for displaying API parameter tables across all Filament pages, ensuring consistent styling and reducing HTML duplication.
- Integrated parameter tables for each endpoint in the Articles, Documents, Divers, Journaux, Tiers, and other pages, providing users with clear reference information.
- Updated the documentation to reflect the new structure and details of API parameters, including required fields and descriptions.
- Improved user experience by ensuring that endpoints without parameters do not display empty tables.
- Overall, enhanced the clarity and usability of API interactions within the application.
2026-02-23 13:55:00 +01:00

123 lines
3.8 KiB
PHP

<?php
namespace App\Filament\Pages;
use App\Exceptions\LogisticsApiException;
use App\Services\LogisticsService;
use App\Support\ApiErrorTranslator;
use Filament\Pages\Page;
use Filament\Support\Icons\Heroicon;
class Articles extends Page
{
protected static string|\BackedEnum|null $navigationIcon = Heroicon::OutlinedCube;
protected static ?string $navigationLabel = 'Articles';
protected static ?string $title = 'Articles';
protected static ?int $navigationSort = 2;
protected string $view = 'filament.pages.articles';
public string $mode = 'read';
public string $search = '';
public string $select = 'artid,name1';
public string $barcode = '';
public string $stockArticleId = '';
public array $data = [];
public array $stockData = [];
public ?array $metadata = null;
public ?string $errorMessage = null;
public bool $hasSearched = false;
public bool $hasCheckedStock = false;
/**
* @return array<int, array{name: string, type: string, required: string, description: string}>
*/
public function paramTableArtList(): array
{
return [
['name' => 'search', 'type' => 'string', 'required' => 'Oui', 'description' => 'Filtre de recherche textuel. Recherche dans artid et name1. Obligatoire.'],
['name' => 'select', 'type' => 'string', 'required' => 'Non', 'description' => 'Colonnes a retourner, separees par des virgules (colonnes de la table art).'],
['name' => 'barcode', 'type' => 'string', 'required' => 'Non', 'description' => 'Sans effet observable. Le parametre search reste obligatoire meme si barcode est fourni.'],
];
}
/**
* @return array<int, array{name: string, type: string, required: string, description: string}>
*/
public function paramTableArtGetstk(): array
{
return [
['name' => 'ARTID', 'type' => 'string', 'required' => 'Oui', 'description' => "Identifiant unique de l'article (champ artid de la table art)."],
];
}
public function searchArticles(): void
{
$this->errorMessage = null;
$this->hasSearched = true;
try {
$service = app(LogisticsService::class);
$params = array_filter([
'select' => $this->select,
'search' => $this->search,
'barcode' => $this->barcode,
]);
$response = $service->artList($params);
$this->data = $response['data'] ?? [];
$this->metadata = $response['metadata'] ?? null;
$this->errorMessage = ApiErrorTranslator::translate($response['error'] ?? null);
} catch (LogisticsApiException $e) {
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->data = [];
} catch (\Throwable $e) {
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->data = [];
}
}
public function getStock(): void
{
$this->errorMessage = null;
if (blank($this->stockArticleId)) {
$this->errorMessage = 'Le champ identifiant article (ARTID) est obligatoire pour verifier le stock.';
return;
}
$this->hasCheckedStock = true;
try {
$service = app(LogisticsService::class);
$response = $service->artGetStock($this->stockArticleId);
$this->stockData = $response['data'] ?? [];
$this->errorMessage = ApiErrorTranslator::translate($response['error'] ?? null);
} catch (LogisticsApiException $e) {
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->stockData = [];
} catch (\Throwable $e) {
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->stockData = [];
}
}
}