diff --git a/src/api/households.ts b/src/api/households.ts index 8ba1412..60d0815 100644 --- a/src/api/households.ts +++ b/src/api/households.ts @@ -1,16 +1,14 @@ -import { api, fetchApi } from '@/api/client' +import { api, fetchApi, getHouseholdSlug } from '@/api/client' import type { components, paths } from '@/api/types' export type Member = components['schemas']['User'] // Prefer typed endpoint if exists, fallback to raw fetch for now export async function listMembers(): Promise { - // Try typed path if openapi exposes it - const hasTyped: boolean = Boolean((api as unknown as { GET?: unknown }).GET) - if (hasTyped) { - // Our OpenAPI file doesn't specify this route yet, so default to raw fetch - } - const resp = await fetchApi('/api/v1/households/members', { method: 'GET' }) + // Temporary raw GET using household slug in query until typed endpoint is available + const slug = getHouseholdSlug() || '' + const path = slug ? `/api/v1/households/${encodeURIComponent(slug)}/members` : '/api/v1/households/members' + const resp = await fetchApi(path, { method: 'GET' }) if (!resp.ok) throw new Error(`${resp.status} ${resp.statusText || 'HTTP error'}`) const data = await resp.json().catch(() => null) const arr = Array.isArray(data) ? data : [] diff --git a/src/api/sdk.ts b/src/api/sdk.ts index 0669525..53299b2 100644 --- a/src/api/sdk.ts +++ b/src/api/sdk.ts @@ -271,7 +271,7 @@ export async function getMeal(id: number | string): Promise { return mapped } -export async function saveMeal(meal: components['schemas']['Meal-Input']): Promise { +export async function saveMeal(meal: components['schemas']['MealIn']): Promise { const hasId = typeof meal.id === 'number' && meal.id >= 0 const householdSlug = requireSlug() if (hasId) { @@ -308,7 +308,13 @@ export async function deleteMeal(mealId: number | string): Promise { } // Shopping -// getMyShoppingList/saveMyShoppingList endpoints removed in v2; not used by UI currently +// getMyShoppingList/saveMyShoppingList endpoints removed in v2; keep temporary stubs for legacy UI +export async function getMyShoppingList(): Promise { + return [] +} +export async function saveMyShoppingList(ingredients: components['schemas']['Ingredient'][]): Promise { + return ingredients +} export async function getShoppingList(id: number | string): Promise { const householdSlug = requireSlug() diff --git a/src/api/types.ts b/src/api/types.ts index 8d21345..c7abc67 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -140,6 +140,23 @@ export interface paths { patch?: never; trace?: never; }; + "/api/v1/households/{householdSlug}/members": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** List Members */ + get: operations["list_members_api_v1_households__householdSlug__members_get"]; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; "/api/v1/households/{householdSlug}/invitations": { parameters: { query?: never; @@ -417,6 +434,15 @@ export interface components { */ status: string; }; + /** HouseholdMember */ + HouseholdMember: { + /** Id */ + id: number; + /** Displayname */ + displayName: string; + /** Role */ + role: string; + }; /** HouseholdResponse */ HouseholdResponse: { /** Id */ @@ -1189,6 +1215,38 @@ export interface operations { }; }; }; + list_members_api_v1_households__householdSlug__members_get: { + parameters: { + query?: never; + header?: never; + path: { + householdSlug: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Successful Response */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": components["schemas"]["HouseholdMember"][]; + }; + }; + 403: components["responses"]["Problem403"]; + /** @description Validation Error */ + 422: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": components["schemas"]["HTTPValidationError"]; + }; + }; + }; + }; create_invitation_api_v1_households__householdSlug__invitations_post: { parameters: { query?: never; diff --git a/src/components/meals/EditMealPage.vue b/src/components/meals/EditMealPage.vue index f70f64a..be62efd 100644 --- a/src/components/meals/EditMealPage.vue +++ b/src/components/meals/EditMealPage.vue @@ -123,7 +123,7 @@ import { toMealInput } from '@/domain/decoders' import { currentUser } from '@/api/auth' import { useAlert } from '@/composables/useAlert' import { parseRouteId } from '@/router/helpers' -import type { Person, Ingredient, Meal, MealRecipe } from '@/domain/types' +import type { Ingredient, Meal, MealRecipe } from '@/domain/types' import { ago } from '@/dateformats' @@ -136,7 +136,7 @@ import CompactParsedIngredient from '../ingredients/CompactParsedIngredient.vue' const showIngredientsIcon = new URL('@/assets/show-ingredients.svg', import.meta.url).toString() const trash = new URL('@/assets/trash.svg', import.meta.url).toString() -function addPersonIfNotExists(list: Person[], person: Person | null | undefined) { +function addPersonIfNotExists(list: T[], person: T | null | undefined) { if (!person) return if (!list.find((p) => p.id === person.id)) { list.push(person) @@ -169,7 +169,7 @@ onBeforeMount(async () => { } else { const self = await currentUser() if (self) { - const me: Person = { id: self.id, name: self.displayName } + const me = { id: self.id, displayName: self.displayName } meal.chefs = [me] meal.consumers = [me] meal.cleanup = [me] @@ -203,12 +203,14 @@ function updateIngredient(ingredient: Ingredient, newIngredient: Ingredient) { meal.extraIngredients = meal.extraIngredients.map((i) => (i === ingredient ? newIngredient : i)) } -function removePerson(list: PeopleKey, person: Person) { +function removePerson(list: PeopleKey, person: { id: number }) { meal[list] = meal[list].filter((p) => p.id !== person.id) } -function addPerson(list: PeopleKey, person: Person) { - addPersonIfNotExists(meal[list], person) +function addPerson(list: PeopleKey, person: { id: number; name?: string; displayName?: string }) { + // Normalize person into MemberRef shape + const normalized = { id: person.id, displayName: (person as any).displayName ?? (person as any).name ?? '' } + addPersonIfNotExists(meal[list], normalized) } async function selectRecipe(recipe: { id: number | string }) { diff --git a/src/components/meals/MealCard.vue b/src/components/meals/MealCard.vue index fec5087..12f0948 100644 --- a/src/components/meals/MealCard.vue +++ b/src/components/meals/MealCard.vue @@ -11,7 +11,7 @@ v-for="(chef, index) in meal.chefs" :key="chef.id" > - {{ chef.name }}{{ englishSeperator(index, meal.chefs) }} + {{ chef.displayName }}{{ englishSeperator(index, meal.chefs) }} somebody?

@@ -21,7 +21,7 @@ v-for="(consumer, index) in meal.consumers" :key="consumer.id" > - {{ consumer.name }}{{ englishSeperator(index, meal.consumers) }} + {{ consumer.displayName }}{{ englishSeperator(index, meal.consumers) }} somebody?

diff --git a/src/components/meals/PersonList.vue b/src/components/meals/PersonList.vue index 93cc2bf..5bd3bf4 100644 --- a/src/components/meals/PersonList.vue +++ b/src/components/meals/PersonList.vue @@ -8,7 +8,7 @@ class="person-circle remove-person" @click="removePerson(person)" > - {{ person.name }} + {{ person.displayName || (person as any).name || '' }} @@ -40,7 +40,7 @@ class="person-circle add-person" @mousedown="addPerson(person)" > - {{ person.name }} + {{ person.displayName || (person as any).name || '' }} @@ -51,16 +51,17 @@