-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb96d65
commit 81b174f
Showing
15 changed files
with
189 additions
and
1,481 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ProjectLocationState, RelatedImages } from "../types"; | ||
|
||
const API_URL = process.env.NODE_ENV === "development" ? "http://localhost:3000/api" : import.meta.env.VITE_OPEN_AI_API_URL; | ||
|
||
const fetchApi = async (endpoint: string, method: string = "GET", body?: object) => { | ||
const options = { | ||
method, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: body ? JSON.stringify(body) : undefined, | ||
}; | ||
|
||
const response = await fetch(`${API_URL}${endpoint}`, options); | ||
|
||
if (!response.ok) { | ||
throw new Error("Network response was not ok"); | ||
} | ||
|
||
return await response.json(); | ||
}; | ||
|
||
export const generateProjectIdeas = async (materials: string[], onlySpecified: boolean, difficulty: string, category: string, tools: string[], time: number, budget: number, endPurpose: string) => { | ||
return fetchApi("/v1/generate/idea", "POST", { materials, onlySpecified, difficulty, category, tools, time, budget, endPurpose }); | ||
}; | ||
|
||
export const generateProjectExplanations = async (title: string, materials: string[], tools: string[], time: string, budget: string, description: string) => { | ||
return fetchApi("/v1/generate/explain", "POST", { title, materials, tools, time, budget, description }); | ||
}; | ||
|
||
export const searchImages = async (query: string) => { | ||
return fetchApi(`/v1/image/search?query=${encodeURIComponent(query)}`); | ||
}; | ||
|
||
export const getGuideByPath = async (path: string) => { | ||
return fetchApi(`/v1/guide/${path}`); | ||
}; | ||
|
||
export const getAllGuides = async () => { | ||
return fetchApi("/v1/guide"); | ||
}; | ||
|
||
export const saveShareLinkData = async (projectDetails: ProjectLocationState | null, projectImage: RelatedImages | null, explanation: string | null) => { | ||
return fetchApi("/v1/share", "POST", { projectDetails, projectImage, explanation }); | ||
}; | ||
|
||
export const getShareLinkData = async (id: string) => { | ||
return fetchApi(`/v1/share/${id}`); | ||
}; | ||
|
||
export const getTotalCountOfGeneratedIdea = async () => { | ||
return fetchApi("/v1/counter"); | ||
}; | ||
|
||
export const incrementCounterOfGeneratedIdea = async () => { | ||
return fetchApi("/v1/counter", "POST"); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Request, Response, NextFunction } from "express"; | ||
import { sendSuccess } from "../utils/response-template"; | ||
import { PrismaClient } from "@prisma/client"; | ||
import { getStartOfDay } from "../utils"; | ||
|
||
export const getTotalCountOfGeneratedIdea = async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const prisma = req.app.get("prisma") as PrismaClient; | ||
|
||
const totalCount = await prisma.ideaGenerationCounter.aggregate({ | ||
_sum: { | ||
count: true, | ||
}, | ||
}); | ||
|
||
return sendSuccess(res, { totalCount: totalCount._sum.count ?? 0 }); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export const incrementCounterOfGeneratedIdea = async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const prisma = req.app.get("prisma") as PrismaClient; | ||
|
||
const today = getStartOfDay(new Date()); | ||
|
||
const counter = await prisma.ideaGenerationCounter.findFirst({ | ||
where: { | ||
createdAt: { | ||
gte: today, | ||
lt: new Date(today.getTime() + 24 * 60 * 60 * 1000), | ||
}, | ||
}, | ||
}); | ||
|
||
if (counter) { | ||
await prisma.ideaGenerationCounter.update({ | ||
where: { | ||
id: counter.id, | ||
}, | ||
data: { | ||
count: { | ||
increment: 1, | ||
}, | ||
}, | ||
}); | ||
} else { | ||
await prisma.ideaGenerationCounter.create({ | ||
data: { | ||
count: 1, | ||
createdAt: today, | ||
}, | ||
}); | ||
} | ||
|
||
return sendSuccess(res, {}, 201); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; |
Oops, something went wrong.