Skip to content

Commit 2bbefa9

Browse files
committed
adding new aliases
1 parent da26f18 commit 2bbefa9

File tree

19 files changed

+107
-154
lines changed

19 files changed

+107
-154
lines changed

TODO.md

Lines changed: 0 additions & 32 deletions
This file was deleted.

petclinic-ermodel.png

-69.6 KB
Binary file not shown.

spring-petclinic-reactjs-client/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ export const App = () => (
4343
</Layout>
4444
</BrowserRouter>
4545
</QueryProvider>
46-
);
46+
);

spring-petclinic-reactjs-client/src/Layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ export const Layout = ({ children }: LayoutProps) => (
1010
<NavigationBar />
1111
<div className="container-fluid">{children}</div>
1212
</>
13-
);
13+
);

spring-petclinic-reactjs-client/src/components/ErrorMessage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ export function ErrorMessage({ error, onRetry }: ErrorMessageProps) {
1515
)}
1616
</div>
1717
);
18-
}
18+
}

spring-petclinic-reactjs-client/src/components/Loading.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export interface LoadingProps {
44

55
export function Loading({ message = "Loading..." }: LoadingProps) {
66
return (
7-
<div className="d-flex justify-content-center align-items-center" style={{ minHeight: '200px' }}>
7+
<div className="d-flex justify-content-center align-items-center" style={{ minHeight: "200px" }}>
88
<div className="text-center">
99
<div className="spinner-border" role="status">
1010
<span className="visually-hidden">{message}</span>
@@ -13,4 +13,4 @@ export function Loading({ message = "Loading..." }: LoadingProps) {
1313
</div>
1414
</div>
1515
);
16-
}
16+
}

spring-petclinic-reactjs-client/src/hooks/useApi.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect, useCallback } from 'react';
1+
import { useState, useEffect, useCallback } from "react";
22

33
export interface ApiState<T> {
44
data: T | null;
@@ -18,19 +18,19 @@ export function useApi<T>(
1818
const [state, setState] = useState<ApiState<T>>({
1919
data: null,
2020
loading: options.immediate ?? true,
21-
error: null,
21+
error: null
2222
});
2323

2424
const execute = useCallback(async () => {
25-
setState(prev => ({ ...prev, loading: true, error: null }));
25+
setState((prev) => ({ ...prev, loading: true, error: null }));
2626
try {
2727
const result = await apiCall();
2828
setState({ data: result, loading: false, error: null });
2929
} catch (error) {
30-
setState({
31-
data: null,
32-
loading: false,
33-
error: error instanceof Error ? error.message : 'An error occurred'
30+
setState({
31+
data: null,
32+
loading: false,
33+
error: error instanceof Error ? error.message : "An error occurred"
3434
});
3535
}
3636
}, dependencies);
@@ -43,7 +43,7 @@ export function useApi<T>(
4343

4444
return {
4545
...state,
46-
refetch: execute,
46+
refetch: execute
4747
};
4848
}
4949

@@ -63,12 +63,12 @@ export function useAsyncOperation<T>(): {
6363
setLoading(false);
6464
return result;
6565
} catch (err) {
66-
const errorMessage = err instanceof Error ? err.message : 'An error occurred';
66+
const errorMessage = err instanceof Error ? err.message : "An error occurred";
6767
setError(errorMessage);
6868
setLoading(false);
6969
return null;
7070
}
7171
}, []);
7272

7373
return { execute, loading, error };
74-
}
74+
}
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
1-
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
2-
import { apiService } from '@services/apiService';
3-
import { IApiOwner } from '@models/api/IApiOwner';
4-
import { OwnerFormSchema } from '@models/form/OwnerFormSchema';
1+
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
2+
import { apiService } from "@services/apiService";
3+
import { IApiOwner } from "@models/api/IApiOwner";
4+
import { OwnerFormSchema } from "@models/form/OwnerFormSchema";
55

6-
export const OWNERS_QUERY_KEY = 'owners';
6+
export const OWNERS_QUERY_KEY = "owners";
77

88
export function useOwners(filter?: { lastName?: string }) {
99
return useQuery({
1010
queryKey: [OWNERS_QUERY_KEY, filter],
11-
queryFn: () => apiService.getList<IApiOwner>('owners', { filter }),
12-
enabled: true,
11+
queryFn: () => apiService.getList<IApiOwner>("owners", { filter }),
12+
enabled: true
1313
});
1414
}
1515

1616
export function useOwner(id: number | undefined) {
1717
return useQuery({
1818
queryKey: [OWNERS_QUERY_KEY, id],
19-
queryFn: () => apiService.getOne<IApiOwner>('owners', id!),
20-
enabled: !!id,
19+
queryFn: () => apiService.getOne<IApiOwner>("owners", id!),
20+
enabled: !!id
2121
});
2222
}
2323

2424
export function useCreateOwner() {
2525
const queryClient = useQueryClient();
26-
26+
2727
return useMutation({
28-
mutationFn: (data: OwnerFormSchema) => apiService.create<IApiOwner>('owners', data),
28+
mutationFn: (data: OwnerFormSchema) => apiService.create<IApiOwner>("owners", data),
2929
onSuccess: () => {
3030
queryClient.invalidateQueries({ queryKey: [OWNERS_QUERY_KEY] });
31-
},
31+
}
3232
});
3333
}
3434

3535
export function useUpdateOwner() {
3636
const queryClient = useQueryClient();
37-
37+
3838
return useMutation({
39-
mutationFn: ({ id, data }: { id: number; data: OwnerFormSchema }) =>
40-
apiService.update<IApiOwner>('owners', id, data),
39+
mutationFn: ({ id, data }: { id: number; data: OwnerFormSchema }) =>
40+
apiService.update<IApiOwner>("owners", id, data),
4141
onSuccess: (_, { id }) => {
4242
queryClient.invalidateQueries({ queryKey: [OWNERS_QUERY_KEY] });
4343
queryClient.invalidateQueries({ queryKey: [OWNERS_QUERY_KEY, id] });
44-
},
44+
}
4545
});
4646
}
4747

4848
export function useDeleteOwner() {
4949
const queryClient = useQueryClient();
50-
50+
5151
return useMutation({
52-
mutationFn: (id: number) => apiService.delete('owners', id),
52+
mutationFn: (id: number) => apiService.delete("owners", id),
5353
onSuccess: () => {
5454
queryClient.invalidateQueries({ queryKey: [OWNERS_QUERY_KEY] });
55-
},
55+
}
5656
});
57-
}
57+
}
Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,45 @@
1-
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
2-
import { apiService } from '@services/apiService';
3-
import { IApiPet } from '@models/api/IApiPet';
4-
import { IApiEnumItem } from '@models/api/IApiEnumItem';
5-
import { OWNERS_QUERY_KEY } from './useOwners';
1+
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
2+
import { apiService } from "@services/apiService";
3+
import { IApiEnumItem } from "@models/api/IApiEnumItem";
4+
import { OWNERS_QUERY_KEY } from "./useOwners";
65

7-
export const PET_TYPES_QUERY_KEY = 'petTypes';
6+
export const PET_TYPES_QUERY_KEY = "petTypes";
87

98
export function usePetTypes() {
109
return useQuery({
1110
queryKey: [PET_TYPES_QUERY_KEY],
12-
queryFn: () => apiService.getList<IApiEnumItem>('pettypes'),
11+
queryFn: () => apiService.getList<IApiEnumItem>("pettypes")
1312
});
1413
}
1514

1615
export function usePet(ownerId: number, petId: number | undefined) {
1716
return useQuery({
18-
queryKey: ['pets', ownerId, petId],
17+
queryKey: ["pets", ownerId, petId],
1918
queryFn: () => apiService.getPet(ownerId, petId!),
20-
enabled: !!petId && !!ownerId,
19+
enabled: !!petId && !!ownerId
2120
});
2221
}
2322

2423
export function useCreatePet() {
2524
const queryClient = useQueryClient();
26-
25+
2726
return useMutation({
28-
mutationFn: ({ ownerId, data }: { ownerId: number; data: any }) =>
29-
apiService.createPet(ownerId, data),
27+
mutationFn: ({ ownerId, data }: { ownerId: number; data: any }) => apiService.createPet(ownerId, data),
3028
onSuccess: (_, { ownerId }) => {
3129
queryClient.invalidateQueries({ queryKey: [OWNERS_QUERY_KEY, ownerId] });
32-
},
30+
}
3331
});
3432
}
3533

3634
export function useUpdatePet() {
3735
const queryClient = useQueryClient();
38-
36+
3937
return useMutation({
40-
mutationFn: ({ ownerId, petId, data }: { ownerId: number; petId: number; data: any }) =>
38+
mutationFn: ({ ownerId, petId, data }: { ownerId: number; petId: number; data: any }) =>
4139
apiService.updatePet(ownerId, petId, data),
4240
onSuccess: (_, { ownerId, petId }) => {
4341
queryClient.invalidateQueries({ queryKey: [OWNERS_QUERY_KEY, ownerId] });
44-
queryClient.invalidateQueries({ queryKey: ['pets', ownerId, petId] });
45-
},
42+
queryClient.invalidateQueries({ queryKey: ["pets", ownerId, petId] });
43+
}
4644
});
47-
}
45+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { useQuery } from '@tanstack/react-query';
2-
import { apiService } from '@services/apiService';
3-
import { IApiVeterinarian } from '@models/api/IApiVeterinarian';
1+
import { useQuery } from "@tanstack/react-query";
2+
import { apiService } from "@services/apiService";
3+
import { IApiVeterinarian } from "@models/api/IApiVeterinarian";
44

5-
export const VETERINARIANS_QUERY_KEY = 'veterinarians';
5+
export const VETERINARIANS_QUERY_KEY = "veterinarians";
66

77
export function useVeterinarians() {
88
return useQuery({
99
queryKey: [VETERINARIANS_QUERY_KEY],
10-
queryFn: () => apiService.getList<IApiVeterinarian>('vets'),
10+
queryFn: () => apiService.getList<IApiVeterinarian>("vets")
1111
});
12-
}
12+
}

0 commit comments

Comments
 (0)