Skip to content

Commit

Permalink
create feature request methods
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanBonsignori committed Feb 19, 2024
1 parent 35ce1d4 commit ed2d7b2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
42 changes: 42 additions & 0 deletions src/api/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
FeatureRequestCreateRequest,
FeatureRequestCreateResponse,
FeatureRequestGetResponse,
} from "./generated";

export const getFeatureRequests = (): Promise<FeatureRequestGetResponse[]> =>
fetch(`${import.meta.env.VITE_API_ROOT}/api/v1/feature-request`).then((res) =>
res.json()
);

export const createFeatureRequest = (
featureRequest: FeatureRequestCreateRequest
): Promise<FeatureRequestCreateResponse> =>
fetch(`${import.meta.env.VITE_API_ROOT}/api/v1/feature-request`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(featureRequest),
}).then((res) => res.json());

export const updateFeatureRequest = (
id: string,
featureRequest: FeatureRequestCreateRequest
): Promise<FeatureRequestCreateResponse> =>
fetch(`${import.meta.env.VITE_API_ROOT}/api/v1/feature-request/${id}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(featureRequest),
}).then((res) => res.json());

export const deleteFeatureRequest = (id: string): Promise<void> => {
return fetch(
`${import.meta.env.VITE_API_ROOT}/api/v1/feature-request/${id}`,
{
method: "DELETE",
}
).then((res) => res.json());
};
9 changes: 2 additions & 7 deletions src/routes/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ import { Box, LinearProgress } from "@mui/material";
import Grid from "@mui/material/Grid";
import { useQuery } from "@tanstack/react-query";
import { FC } from "react";
import { FeatureRequestGetResponse } from "../api/generated";
import { getFeatureRequests } from "../api/api";
import FeatureRequest from "../components/FeatureRequest";
import Layout from "../components/Layout";

const Root: FC = () => {
const featureRequestsQuery = (): Promise<FeatureRequestGetResponse[]> =>
fetch(`${import.meta.env.VITE_API_ROOT}/api/v1/feature-request`).then(
(res) => res.json()
);

const { isLoading, error, data } = useQuery({
queryKey: ["feature-requests"],
queryFn: featureRequestsQuery,
queryFn: getFeatureRequests,
});

if (isLoading)
Expand Down

0 comments on commit ed2d7b2

Please sign in to comment.