From d0fe8172eb285fde4d612181da7210686434c602 Mon Sep 17 00:00:00 2001 From: Kotamkadi Abhinav Reddy <142340019+mlrit12b5@users.noreply.github.com> Date: Sun, 20 Apr 2025 13:06:52 +0530 Subject: [PATCH 1/2] added some features --- .gitignore | 2 +- apps/backend/.env.example | 13 - apps/backend/index.ts | 83 ++++++ apps/web/app/dashboard/page.tsx | 13 + apps/web/app/layout.tsx | 2 + apps/web/components/Camera.tsx | 268 ++++++++++------- apps/web/components/ImageCard.tsx | 86 ++++-- apps/web/components/PackCard.tsx | 9 +- apps/web/components/Saved.tsx | 273 ++++++++++++++++++ apps/web/components/SavedImageCard.tsx | 69 +++++ apps/web/components/ui/sonner.tsx | 25 ++ apps/web/next.config.js | 3 +- apps/web/package.json | 4 +- bun.lockb | Bin 303848 -> 329824 bytes package.json | 5 +- .../migration.sql | 16 + .../migration.sql | 20 ++ .../migration.sql | 17 ++ packages/db/prisma/schema.prisma | 9 +- 19 files changed, 767 insertions(+), 150 deletions(-) delete mode 100644 apps/backend/.env.example create mode 100644 apps/web/components/Saved.tsx create mode 100644 apps/web/components/SavedImageCard.tsx create mode 100644 apps/web/components/ui/sonner.tsx create mode 100644 packages/db/prisma/migrations/20250415044920_added_liked_model/migration.sql create mode 100644 packages/db/prisma/migrations/20250415092457_modifiedliked_images/migration.sql create mode 100644 packages/db/prisma/migrations/20250415094917_removed_likedmodel/migration.sql diff --git a/.gitignore b/.gitignore index 96fab4fe..6a94a488 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ node_modules .pnp .pnp.js -# Local env files +# # Local env files .env .env.local .env.development.local diff --git a/apps/backend/.env.example b/apps/backend/.env.example deleted file mode 100644 index 0e3b8a02..00000000 --- a/apps/backend/.env.example +++ /dev/null @@ -1,13 +0,0 @@ -FAL_KEY="" -S3_ACCESS_KEY="" -S3_SECRET_KEY="" -BUCKET_NAME="" -ENDPOINT="" -AUTH_JWT_KEY="" -RAZORPAY_KEY_ID="" -RAZORPAY_KEY_SECRET="" -SIGNING_SECRET="" -CLERK_JWT_PUBLIC_KEY="" -SIGNING_SECRET="" -WEBHOOK_BASE_URL="" -FRONTEND_URL="" \ No newline at end of file diff --git a/apps/backend/index.ts b/apps/backend/index.ts index 313b4ea9..cb0fc92f 100644 --- a/apps/backend/index.ts +++ b/apps/backend/index.ts @@ -276,6 +276,89 @@ app.get("/models", authMiddleware, async (req, res) => { }); }); +app.post("/toggle-like", authMiddleware, async (req, res) => { + try { + const { imageId } = req.body; + + if (!imageId) { + res.status(400).json({ + success: false, + error: "Image ID is required", + }); + return; + } + + const image = await prismaClient.outputImages.findUnique({ + where: { id: imageId, userId: req.userId }, + }); + + if (!image) { + res.status(404).json({ + success: false, + error: "Image not found", + }); + return; + } + + const updatedImage = await prismaClient.outputImages.update({ + where: { id: imageId }, + data: { + likedImage: image.likedImage === "like" ? "unlike" : "like", + }, + }); + + res.json({ + success: true, + message: `Image ${updatedImage.likedImage === "like" ? "liked" : "unliked"}`, + likedStatus: updatedImage.likedImage, + }); + } catch (error) { + console.error("Error toggling like:", error); + res.status(500).json({ + success: false, + error: "Failed to toggle like status", + }); + } +}); + +app.get("/liked/bulk", authMiddleware, async (req, res) => { + try { + const likedImages = await prismaClient.outputImages.findMany({ + where: { + userId: req.userId, + likedImage: 'like' + }, + select: { + id: true, + imageUrl: true, + modelId: true, + prompt: true, + likedImage:true, + createdAt: true, + model: { + select: { + name: true + } + } + }, + orderBy: { + createdAt: 'desc' + } + }); + + res.json({ + success: true, + images:likedImages + }); + } catch (error) { + console.error("Error fetching liked images:", error); + res.status(500).json({ + success: false, + error: "Failed to fetch liked images" + }); + } +}); + app.post("/fal-ai/webhook/train", async (req, res) => { console.log("====================Received training webhook===================="); console.log("Received training webhook:", req.body); diff --git a/apps/web/app/dashboard/page.tsx b/apps/web/app/dashboard/page.tsx index 31419879..4c8fc582 100644 --- a/apps/web/app/dashboard/page.tsx +++ b/apps/web/app/dashboard/page.tsx @@ -5,6 +5,7 @@ import { Packs } from "@/components/Packs"; import { Camera } from "@/components/Camera"; import { redirect } from "next/navigation"; import { auth } from "@clerk/nextjs/server"; +import Saved from "@/components/Saved"; export const dynamic = "force-dynamic"; export default async function DashboardPage() { @@ -43,6 +44,12 @@ export default async function DashboardPage() { > TrainModel + + Saved +
@@ -70,6 +77,12 @@ export default async function DashboardPage() { > + + +
diff --git a/apps/web/app/layout.tsx b/apps/web/app/layout.tsx index bf5c6db0..1acd4ea6 100644 --- a/apps/web/app/layout.tsx +++ b/apps/web/app/layout.tsx @@ -5,6 +5,7 @@ import { Appbar } from "@/components/Appbar"; import { Providers } from "@/components/providers/Providers"; import { Footer } from "@/components/Footer"; import Script from "next/script"; +import { Toaster } from "@/components/ui/sonner" const geistSans = localFont({ src: "./fonts/GeistVF.woff", @@ -44,6 +45,7 @@ export default function RootLayout({
{children}