diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 4802a77..a3262d4 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -778,4 +778,4 @@
-
\ No newline at end of file
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 259a25b..5902764 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,7 @@ Ajouter dans le fichier .env du frontend
* [#316] Admin liste des transporteurs
* [#312] Creation administration listing fournisseurs
* [#315] Creation page admin utilisateur
+* [#317] Admin modification creation transporteur
### Changed
diff --git a/frontend/i18n/locales/fr.json b/frontend/i18n/locales/fr.json
index d00870e..4ea1b99 100644
--- a/frontend/i18n/locales/fr.json
+++ b/frontend/i18n/locales/fr.json
@@ -46,7 +46,11 @@
"list": "Impossible de récupérer la liste des races de bovins."
},
"carrier": {
- "list": "Impossible de récupérer la liste des transporteurs."
+ "list": "Impossible de récupérer la liste des transporteurs.",
+ "fetch": "Impossible de récupérer les données du transporteur",
+ "update": "Impossible de mettre à jour le transporteur",
+ "create": "Impossible de créer le transporteur"
+
},
"driver": {
"list": "Impossible de récupérer la liste des chauffeurs."
@@ -71,6 +75,10 @@
"create": "Utilisateur créé avec succès.",
"login": "Connexion réussie.",
"logout": "Déconnexion réussie."
+ },
+ "carrier": {
+ "update": "Transporteur mis à jour",
+ "create": "Transporteur créé"
}
}
}
diff --git a/frontend/pages/admin/carrier/[[id]].vue b/frontend/pages/admin/carrier/[[id]].vue
new file mode 100644
index 0000000..702a3f7
--- /dev/null
+++ b/frontend/pages/admin/carrier/[[id]].vue
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
diff --git a/frontend/pages/admin/carrier/carrier-list.vue b/frontend/pages/admin/carrier/carrier-list.vue
index 082763b..4423186 100644
--- a/frontend/pages/admin/carrier/carrier-list.vue
+++ b/frontend/pages/admin/carrier/carrier-list.vue
@@ -2,11 +2,11 @@
listes des transporteurs
-
+
@@ -37,8 +37,8 @@ import {getCarrierList} from "~/services/carrier";
const carrierList = ref()
const router = useRouter()
-const goToCarrier = (id: number|null = null) => {
- id !== null ? router.push(`/admin/carrier/${id}`) : router.push(`/admin/carrier`)
+const goToCarrier = (id: number) => {
+ router.push(`/admin/carrier/${id}`)
}
definePageMeta({
diff --git a/frontend/services/carrier.ts b/frontend/services/carrier.ts
index e7cd9c6..2ca3cf4 100644
--- a/frontend/services/carrier.ts
+++ b/frontend/services/carrier.ts
@@ -1,5 +1,5 @@
import { useApi } from '~/composables/useApi'
-import type { CarrierData } from '~/services/dto/carrier-data'
+import type {CarrierData, CarrierPayload} from "~/services/dto/carrier-data";
export type CarrierListResponse =
| CarrierData[]
@@ -21,3 +21,26 @@ export async function getCarrierList(): Promise {
return []
}
+
+export async function getCarrier(id: number) {
+ const api = useApi()
+ return api.get(`carriers/${id}`, {}, {
+ toastErrorKey: 'errors.carrier.fetch'
+ })
+}
+
+export async function updateCarrier(id: number, payload: CarrierPayload) {
+ const api = useApi()
+ return api.patch(`carriers/${id}`, payload, {
+ toastErrorKey: 'errors.carrier.update',
+ toastSuccessKey: 'success.carrier.update'
+ })
+}
+
+export async function createCarrier(payload: CarrierPayload = {}) {
+ const api = useApi()
+ return api.post('carriers', payload, {
+ toastErrorKey: 'errors.carrier.create',
+ toastSuccessKey: 'success.carrier.update'
+ })
+}
diff --git a/frontend/services/dto/carrier-data.ts b/frontend/services/dto/carrier-data.ts
index 59cf5d8..6eb5bdb 100644
--- a/frontend/services/dto/carrier-data.ts
+++ b/frontend/services/dto/carrier-data.ts
@@ -3,3 +3,13 @@ export interface CarrierData {
name: string
code: string
}
+
+export interface CarrierFormData {
+ name: string
+ code: string
+}
+
+export type CarrierPayload = {
+ name?: string | null
+ code?: string
+}
diff --git a/src/Entity/Carrier.php b/src/Entity/Carrier.php
index d9a16a2..b0fa17f 100644
--- a/src/Entity/Carrier.php
+++ b/src/Entity/Carrier.php
@@ -7,6 +7,8 @@ namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
+use ApiPlatform\Metadata\Patch;
+use ApiPlatform\Metadata\Post;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;
@@ -21,6 +23,15 @@ use Symfony\Component\Serializer\Attribute\Groups;
new GetCollection(
normalizationContext: ['groups' => ['carrier:read']],
),
+ new Post(
+ normalizationContext: ['groups' => ['carrier:read']],
+ denormalizationContext: ['groups' => ['carrier:write']],
+ ),
+ new Patch(
+ requirements: ['id' => '\d+'],
+ normalizationContext: ['groups' => ['carrier:read']],
+ denormalizationContext: ['groups' => ['carrier:write']],
+ ),
],
security: "is_granted('ROLE_USER')",
)]
@@ -33,11 +44,11 @@ class Carrier
private ?int $id = null;
#[ORM\Column(length: 180)]
- #[Groups(['carrier:read', 'driver:read', 'vehicle:read', 'reception:read'])]
+ #[Groups(['carrier:read', 'carrier:write', 'driver:read', 'vehicle:read', 'reception:read'])]
private string $name = '';
#[ORM\Column(length: 30, nullable: true)]
- #[Groups(['carrier:read', 'driver:read', 'vehicle:read', 'reception:read'])]
+ #[Groups(['carrier:read', 'carrier:write', 'driver:read', 'vehicle:read', 'reception:read'])]
private ?string $code = null;
public function getId(): ?int