Skip to content

Commit

Permalink
feat: routes différentes pour la dépublication de chaque type de service
Browse files Browse the repository at this point in the history
  • Loading branch information
ocruze committed Nov 24, 2023
1 parent aee90a5 commit cfca7c1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
11 changes: 4 additions & 7 deletions assets/api/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ const getOfferings = (datastoreId: string) => {
return jsonFetch<OfferingListResponseDto[]>(url);
};

/**
* Demande la suppression de l'offering et puis la configuration
*/
const unpublish = (datastoreId: string, offeringId: string) => {
const url = SymfonyRouting.generate("cartesgouvfr_api_service_unpublish", { datastoreId, offeringId });
return jsonFetch(url, {
const unpublishWfs = (datastoreId: string, offeringId: string) => {
const url = SymfonyRouting.generate("cartesgouvfr_api_service_wfs_unpublish", { datastoreId, offeringId });
return jsonFetch<null>(url, {
method: "DELETE",
});
};

const service = { get, getOfferings, unpublish };
const service = { get, getOfferings, unpublishWfs };

export default service;
6 changes: 3 additions & 3 deletions assets/api/wfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ const add = (datastoreId: string, storedDataId: string, formData: FormData | obj
);
};

export default {
add,
};
const wfs = { add };

export default wfs;
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ const ServicesListItem: FC<ServicesListItemProps> = ({ service, datasheetName, d
const queryClient = useQueryClient();

const unpublishServiceMutation = useMutation({
mutationFn: () => api.service.unpublish(datastoreId, service._id),
onSuccess() {
mutationFn: () => {
switch (service.type) {
case "WFS":
return api.service.unpublishWfs(datastoreId, service._id);
default:
console.warn(`Dépublication de service ${service.type} n'a pas encore été implémentée`);
return Promise.reject(`Dépublication de service ${service.type} n'a pas encore été implémentée`);
}
},
onSettled() {
queryClient.refetchQueries({ queryKey: RQKeys.datastore_datasheet(datastoreId, datasheetName) });
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Api/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getOffering(string $datastoreId, string $offeringId): JsonRespon
}
}

#[Route('/{offeringId}', name: 'unpublish', methods: ['DELETE'])]
#[Route('/{offeringId}', name: 'wfs_unpublish', methods: ['DELETE'])]
public function unpublish(string $datastoreId, string $offeringId): Response
{
try {
Expand Down

0 comments on commit cfca7c1

Please sign in to comment.