Skip to content

Added Some Features #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions apps/backend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions apps/web/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -43,6 +44,12 @@ export default async function DashboardPage() {
>
Train<span className="md:block hidden pl-1">Model</span>
</TabsTrigger>
<TabsTrigger
value="saved"
className="data-[state=active]:bg-pink-500/70 backdrop-blur-sm data-[state=active]:text-pink-50 cursor-pointer px-3 py-1.5"
>
Saved
</TabsTrigger>
</TabsList>

<div className="mt-8 bg-card rounded-lg">
Expand Down Expand Up @@ -70,6 +77,12 @@ export default async function DashboardPage() {
>
<Train />
</TabsContent>
<TabsContent
value="saved"
className="mt-0 focus-visible:outline-none"
>
<Saved />
</TabsContent>
</div>
</Tabs>
</div>
Expand Down
2 changes: 2 additions & 0 deletions apps/web/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -44,6 +45,7 @@ export default function RootLayout({
<Appbar />
<main className="flex-1">{children}</main>
<Footer />
<Toaster position="bottom-right" richColors closeButton />
</div>
</Providers>
</body>
Expand Down
Loading