From d2f6fbd8866d62ab364582f45afa9a4f37e952f8 Mon Sep 17 00:00:00 2001 From: jessikitty Date: Tue, 27 Jan 2026 22:21:28 +1100 Subject: [PATCH] Add chore service API --- frontend/src/api/chores.ts | 72 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 frontend/src/api/chores.ts diff --git a/frontend/src/api/chores.ts b/frontend/src/api/chores.ts new file mode 100644 index 0000000..f42c85e --- /dev/null +++ b/frontend/src/api/chores.ts @@ -0,0 +1,72 @@ +import api from './axios'; + +export interface Chore { + id: number; + title: string; + description: string; + room: string; + frequency: 'daily' | 'weekly' | 'monthly' | 'once'; + status: 'pending' | 'in_progress' | 'completed' | 'skipped'; + assigned_to?: number; + assigned_user?: { + id: number; + username: string; + full_name: string; + }; + due_date?: string; + completed_at?: string; + created_at: string; + updated_at: string; +} + +export interface CreateChoreRequest { + title: string; + description?: string; + room: string; + frequency: 'daily' | 'weekly' | 'monthly' | 'once'; + assigned_to?: number; + due_date?: string; +} + +export interface UpdateChoreRequest { + title?: string; + description?: string; + room?: string; + frequency?: 'daily' | 'weekly' | 'monthly' | 'once'; + status?: 'pending' | 'in_progress' | 'completed' | 'skipped'; + assigned_to?: number; + due_date?: string; +} + +export const choreService = { + async getChores(): Promise { + const response = await api.get('/api/v1/chores'); + return response.data; + }, + + async getChore(id: number): Promise { + const response = await api.get(`/api/v1/chores/${id}`); + return response.data; + }, + + async createChore(chore: CreateChoreRequest): Promise { + const response = await api.post('/api/v1/chores', chore); + return response.data; + }, + + async updateChore(id: number, chore: UpdateChoreRequest): Promise { + const response = await api.put(`/api/v1/chores/${id}`, chore); + return response.data; + }, + + async deleteChore(id: number): Promise { + await api.delete(`/api/v1/chores/${id}`); + }, + + async completeChore(id: number): Promise { + const response = await api.put(`/api/v1/chores/${id}`, { + status: 'completed', + }); + return response.data; + }, +};