From 6a35589b931abf09f29cf276ac2de24a74739d48 Mon Sep 17 00:00:00 2001 From: chloe Date: Fri, 6 Mar 2026 18:01:47 +0000 Subject: [PATCH] Saving recipe update --- .../Controllers/RecipeController.cs | 14 ++++ Seasoned.Frontend/app/pages/gallery.vue | 65 ++++++++++++------- Seasoned.Frontend/app/pages/index.vue | 13 ++++ 3 files changed, 70 insertions(+), 22 deletions(-) diff --git a/Seasoned.Backend/Controllers/RecipeController.cs b/Seasoned.Backend/Controllers/RecipeController.cs index 9753ac9..981ede3 100644 --- a/Seasoned.Backend/Controllers/RecipeController.cs +++ b/Seasoned.Backend/Controllers/RecipeController.cs @@ -61,4 +61,18 @@ public class RecipeController : ControllerBase return Ok(new { message = "Recipe saved to your collection!" }); } + [Authorize] + [HttpGet("my-collection")] + public async Task>> GetMyRecipes() + { + var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); + + var myRecipes = await _context.Recipes + .Where(r => r.UserId == userId) + .OrderByDescending(r => r.CreatedAt) + .ToListAsync(); + + return Ok(myRecipes); + } + } \ No newline at end of file diff --git a/Seasoned.Frontend/app/pages/gallery.vue b/Seasoned.Frontend/app/pages/gallery.vue index 43252b8..70dfe79 100644 --- a/Seasoned.Frontend/app/pages/gallery.vue +++ b/Seasoned.Frontend/app/pages/gallery.vue @@ -20,7 +20,14 @@ Back to Recipe Upload - + + + +

Opening the Ledger...

+
+
+ +

Your collection is empty.

+ Return to kitchen to add some
@@ -60,28 +68,41 @@ + \ No newline at end of file diff --git a/Seasoned.Frontend/app/pages/index.vue b/Seasoned.Frontend/app/pages/index.vue index 5feb046..01c97e1 100644 --- a/Seasoned.Frontend/app/pages/index.vue +++ b/Seasoned.Frontend/app/pages/index.vue @@ -186,16 +186,29 @@ const uploadImage = async () => { const saveToCollection = async () => { if (!recipe.value || hasSaved.value) return; + // 1. Get the token (same logic as gallery) + const token = useCookie('seasoned_token').value + || (import.meta.client ? localStorage.getItem('token') : null) + + if (!token) { + alert("Please sign in to save recipes.") + return navigateTo('/login') + } + saving.value = true; try { await $fetch(`${config.public.apiBase}api/recipe/save`, { method: 'POST', + headers: { + 'Authorization': `Bearer ${token}` + }, body: recipe.value }); hasSaved.value = true; } catch (error) { console.error("Save failed:", error); + alert("Could not save recipe. Your session might have expired.") } finally { saving.value = false; }