diff --git a/client/src/lib/api.ts b/client/src/lib/api.ts new file mode 100644 index 0000000..e4fceec --- /dev/null +++ b/client/src/lib/api.ts @@ -0,0 +1,54 @@ +const BASE_URL = '/'; + +export async function fetchItems(resource: 'users' | 'vehicles' | 'jobs'): Promise { + try { + const response = await fetch(`${BASE_URL}${resource}`); + if (!response.ok) throw new Error(`Failed to fetch ${resource}`); + return await response.json(); + } catch (error) { + console.error(error); + throw error; + } +} + +export async function createItem(resource: 'users' | 'vehicles' | 'jobs', data: any): Promise { + try { + const response = await fetch(`${BASE_URL}${resource}`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(data), + }); + if (!response.ok) throw new Error(`Failed to create ${resource}`); + return await response.json(); + } catch (error) { + console.error(error); + throw error; + } +} + +export async function updateItem(resource: 'users' | 'vehicles' | 'jobs', id: number, data: any): Promise { + try { + const response = await fetch(`${BASE_URL}${resource}/${id}`, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(data), + }); + if (!response.ok) throw new Error(`Failed to update ${resource}`); + return await response.json(); + } catch (error) { + console.error(error); + throw error; + } +} + +export async function deleteItem(resource: 'users' | 'vehicles' | 'jobs', id: number): Promise { + try { + const response = await fetch(`${BASE_URL}${resource}/${id}`, { + method: 'DELETE', + }); + if (!response.ok) throw new Error(`Failed to delete ${resource}`); + } catch (error) { + console.error(error); + throw error; + } +} diff --git a/client/src/lib/index.ts b/client/src/lib/index.ts deleted file mode 100644 index 856f2b6..0000000 --- a/client/src/lib/index.ts +++ /dev/null @@ -1 +0,0 @@ -// place files you want to import through the `$lib` alias in this folder. diff --git a/client/src/lib/types.ts b/client/src/lib/types.ts new file mode 100644 index 0000000..c560c10 --- /dev/null +++ b/client/src/lib/types.ts @@ -0,0 +1,27 @@ +export interface Job { + id: number; + clientName: string; + pickup: string; + dropoff: string; + vehicleId: number; + dateCreated: Date; + lastUpdated?: Date; +} + +export interface User { + id: number; + username: string; + password?: string; + displayName: string; + dateCreated: Date; + lastUpdated?: Date; +} + +export interface Vehicle { + id: number; + make: string; + model: string; + year: number; + dateCreated: Date; + lastUpdated?: Date; +} diff --git a/client/src/routes/+layout.svelte b/client/src/routes/+layout.svelte index 9cebde5..e66fe28 100644 --- a/client/src/routes/+layout.svelte +++ b/client/src/routes/+layout.svelte @@ -1,11 +1,24 @@ - + -{@render children()} + +
+ {@render children()} +
+
+ + diff --git a/client/src/routes/+page.svelte b/client/src/routes/+page.svelte index cc88df0..abe3861 100644 --- a/client/src/routes/+page.svelte +++ b/client/src/routes/+page.svelte @@ -1,2 +1,67 @@ -

Welcome to SvelteKit

-

Visit svelte.dev/docs/kit to read the documentation

+
+

Test Web

+ + +
+ + diff --git a/client/src/routes/jobs/+page.svelte b/client/src/routes/jobs/+page.svelte new file mode 100644 index 0000000..f84de94 --- /dev/null +++ b/client/src/routes/jobs/+page.svelte @@ -0,0 +1,163 @@ + + +

Job Management

+ +
+

Add New Job

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+ +
+

Existing Jobs

+ {#if query.error} +
+ {query.error} +
+ {/if} + {#if query.isLoading} +

Loading...

+ {:else} + + + + + + + + + + {#each query.data || [] as row} + + + + + + + {/each} + +
IDMakeModel
{row.clientName}{row.pickup}{row.dropoff}{row.vehicleId}
+ {/if} +
+ + diff --git a/client/src/routes/users/+page.svelte b/client/src/routes/users/+page.svelte new file mode 100644 index 0000000..f495e42 --- /dev/null +++ b/client/src/routes/users/+page.svelte @@ -0,0 +1,166 @@ + + +
+

User Management

+ +
+

Add New User

+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+ +
+

Existing Users

+ {#if query.error} +
+ {query.error} +
+ {/if} + {#if query.isLoading} +

Loading...

+ {:else} + + + + + + + + + + + {#each query.data || [] as row} + + + + + + + {/each} + +
IDUsernamePasswordDisplayName
{row.id}{row.username}{row.password}{row.displayName}
+ {/if} +
+
+ + diff --git a/client/src/routes/vehicles/+page.svelte b/client/src/routes/vehicles/+page.svelte new file mode 100644 index 0000000..e0478ea --- /dev/null +++ b/client/src/routes/vehicles/+page.svelte @@ -0,0 +1,163 @@ + + +
+

Vehicle Management

+
+

Add New Vehicle

+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+ +
+

Existing Vehicles

+ {#if query.error} +
+ {query.error} +
+ {/if} + {#if query.isLoading} +

Loading...

+ {:else} + + + + + + + + + + {#each query.data || [] as row} + + + + + + {/each} + +
IDMakeModel
{row.id}{row.make}{row.model}
+ {/if} +
+
+ +