api: add get endpoints

This commit is contained in:
Sosokker 2025-05-10 04:48:25 +07:00
parent 090733815b
commit 428714e978
4 changed files with 73 additions and 26 deletions

15
services/data/cooking.ts Normal file
View File

@ -0,0 +1,15 @@
import { supabase } from "@/services/supabase";
import { CookingStep } from "@/types";
import { PostgrestError } from "@supabase/supabase-js";
export const getCookingSteps = async (food_id: string): Promise<{ data: CookingStep[] | null; error: PostgrestError | null }> => {
const { data, error } = await supabase.from("cooking_steps").select(`
id,
created_at,
food_id,
step_order,
title,
description
`).eq("food_id", food_id).order("step_order", { ascending: true });
return { data, error };
};

View File

@ -1,20 +1,7 @@
import { supabase } from "@/services/supabase";
import { Foods, LikedFood, SavedFood } from "@/types";
import { PostgrestError } from "@supabase/supabase-js";
interface Foods {
id: string;
name: string;
description?: string;
time_to_cook_minutes: number;
skill_level: "Easy" | "Medium" | "Hard";
ingredient_count?: number;
calories?: number;
image_url?: string;
is_shared: boolean;
created_by: string;
created_at: string;
}
/**
* Retrieves a list of foods based on the provided filters.
*
@ -58,18 +45,6 @@ export const getFoods = async (
return { data, error };
};
interface SavedFood {
user_id: string;
food_id: string;
created_at: string;
}
interface LikedFood {
user_id: string;
food_id: string;
created_at: string;
}
/**
* Retrieves a list of saved foods for a specific user.
*

21
services/data/forum.ts Normal file
View File

@ -0,0 +1,21 @@
import { supabase } from "@/services/supabase";
export const createLike = async (food_id: string, user_id: string) => {
const { data, error } = await supabase.from("food_likes").insert({ food_id, user_id });
return { data, error };
}
export const createSave = async (food_id: string, user_id: string) => {
const { data, error } = await supabase.from("food_saves").insert({ food_id, user_id });
return { data, error };
}
export const deleteLike = async (food_id: string, user_id: string) => {
const { data, error } = await supabase.from("food_likes").delete().eq("food_id", food_id).eq("user_id", user_id);
return { data, error };
}
export const deleteSave = async (food_id: string, user_id: string) => {
const { data, error } = await supabase.from("food_saves").delete().eq("food_id", food_id).eq("user_id", user_id);
return { data, error };
}

36
types.ts Normal file
View File

@ -0,0 +1,36 @@
interface SavedFood {
user_id: string;
food_id: string;
created_at: string;
}
interface LikedFood {
user_id: string;
food_id: string;
created_at: string;
}
interface Foods {
id: string;
name: string;
description?: string;
time_to_cook_minutes: number;
skill_level: "Easy" | "Medium" | "Hard";
ingredient_count?: number;
calories?: number;
image_url?: string;
is_shared: boolean;
created_by: string;
created_at: string;
}
interface CookingStep {
id: string,
created_at: string,
food_id: string,
step_order: number,
title: string,
description: string
}
export { CookingStep, Foods, LikedFood, SavedFood };