Replace api.ts with auto-generated API.

All the slices will come later.
This commit is contained in:
Dan Albert
2022-03-06 17:40:28 -08:00
parent 2310ef0f80
commit 30aebf2546
4 changed files with 35 additions and 57 deletions

View File

@@ -1,40 +0,0 @@
import { HTTP_URL } from "./backend";
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
import { LatLng } from "leaflet";
// TODO: We should be auto-generating this from FastAPI's openapi.json.
export const apiSlice = createApi({
reducerPath: "api",
baseQuery: fetchBaseQuery({ baseUrl: HTTP_URL }),
tagTypes: ["ControlPoint"],
endpoints: (builder) => ({
getCommitBoundaryForFlight: builder.query<LatLng[], string>({
query: (flightId) => `flights/${flightId}/commit-boundary`,
providesTags: ["ControlPoint"],
}),
setControlPointDestination: builder.mutation<
void,
{ id: number; destination: LatLng }
>({
query: ({ id, destination }) => ({
url: `control-points/${id}/destination`,
method: "PUT",
body: { lat: destination.lat, lng: destination.lng },
invalidatesTags: ["ControlPoint"],
}),
}),
controlPointCancelTravel: builder.mutation<void, number>({
query: (id) => ({
url: `control-points/${id}/cancel-travel`,
method: "PUT",
invalidatesTags: ["ControlPoint"],
}),
}),
}),
});
export const {
useGetCommitBoundaryForFlightQuery,
useSetControlPointDestinationMutation,
useControlPointCancelTravelMutation,
} = apiSlice;