diff --git a/apps/frontend-mobile/services/products.ts b/apps/frontend-mobile/services/products.ts new file mode 100644 index 0000000..32faab7 --- /dev/null +++ b/apps/frontend-mobile/services/products.ts @@ -0,0 +1,53 @@ +import api from './api'; + +export interface Product { + id: string; + source: 'cima' | 'openfoodfacts'; + name: string; + brand: string; + category: string; + image_url: string | null; + active_ingredient?: string; + dosage?: string; + form?: string; + prescription?: string; + commercialized?: boolean; + photos?: { tipo: string; url: string }[]; + docs?: { tipo: number; url: string }[]; + nutriscore?: string; + ingredients?: string; + nova_group?: number; + eco_score?: string; +} + +export interface ProductSearchResponse { + results: Product[]; + total: number; + sources: { + cima: number; + openfoodfacts: number; + }; +} + +export async function searchProducts(query: string): Promise { + if (!query || query.trim().length < 2) return []; + try { + const { data } = await api.get('/products/search', { + params: { q: query } + }); + return data.results || []; + } catch (error) { + console.error('[Products] Search error:', error); + return []; + } +} + +export async function getProduct(source: string, id: string): Promise { + try { + const { data } = await api.get(`/products/${source}/${id}`); + return data; + } catch (error) { + console.error('[Products] Detail error:', error); + return null; + } +}