Skip to content

Commit

Permalink
feat: adjust for filter search
Browse files Browse the repository at this point in the history
  • Loading branch information
punchanabu committed Feb 19, 2024
1 parent 3339804 commit 38fea00
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
21 changes: 18 additions & 3 deletions src/api/pets.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@

Check failure on line 1 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·⏎⏎`

Check failure on line 1 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·⏎⏎`

import useAuthStore from "@/store/authStore";
import { Meta } from "@/types/common";
import { Pet } from "@/types/pets";
import axios from "axios";


Check failure on line 8 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`

Check failure on line 8 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`
interface PetsResponse {
pets: Pet[];
metadata: Meta;
}

const getPets = async () => {
interface GetPetsFilter {
type?: string;

Check failure on line 15 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`

Check failure on line 15 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
gender?: string;

Check failure on line 16 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`

Check failure on line 16 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
color?: string;

Check failure on line 17 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`

Check failure on line 17 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
minAge?: number;

Check failure on line 18 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`

Check failure on line 18 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
maxAge?: number;

Check failure on line 19 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`

Check failure on line 19 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
}

Check failure on line 20 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`

Check failure on line 20 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`


const getPets = async (filters: GetPetsFilter) => {

Check failure on line 23 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`

Check failure on line 23 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`

const queryParams = new URLSearchParams(filters as any).toString();

Check failure on line 25 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check failure on line 25 in src/api/pets.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

const response = await axios.get<PetsResponse>(
`${import.meta.env.VITE_API_URL}/pets`
`${import.meta.env.VITE_API_URL}/pets${queryParams}`
);
return response.data;
};
Expand Down Expand Up @@ -40,4 +55,4 @@ const postPet = async (data: postPetRequest): Promise<postPetResponse> => {
};

export { getPets, postPet };
export type { PetsResponse, postPetRequest, postPetResponse };
export type { PetsResponse, postPetRequest, postPetResponse, GetPetsFilter };
11 changes: 6 additions & 5 deletions src/hooks/queries/usePetsQuery.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { PetsResponse, getPets } from "@/api/pets";
import { PetsResponse, getPets, GetPetsFilter } from "@/api/pets";
import { useQuery } from "@tanstack/react-query";

const usePetsQuery = () => {

const usePetsQuery = (filters?: GetPetsFilter) => {
return useQuery<PetsResponse>({
queryKey: ["pets"],
queryFn: () => getPets(),
queryKey: ["pets", filters],
queryFn: () => getPets(filters || {}),
enabled: true,
});
};

export { usePetsQuery };
export { usePetsQuery };

0 comments on commit 38fea00

Please sign in to comment.