feat: add stock database with prisma for portfolio persistence
- Initialize Prisma with SQLite and Stock model - Create database service layer with singleton client - Add API routes for stock CRUD operations - Integrate database with analyze page to persist ticker entries - Add Playwright tests for stock database functionality
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { db } from "../../../lib/db.server";
|
||||
|
||||
export async function loader() {
|
||||
const stocks = await db.stock.findMany({
|
||||
orderBy: { ticker: "asc" },
|
||||
});
|
||||
return Response.json(stocks);
|
||||
}
|
||||
|
||||
export async function action({ request }: { request: Request }) {
|
||||
const formData = await request.formData();
|
||||
const ticker = formData.get("ticker")?.toString().toUpperCase();
|
||||
|
||||
if (!ticker) {
|
||||
return Response.json({ error: "Ticker is required" }, { status: 400 });
|
||||
}
|
||||
|
||||
const stock = await db.stock.create({
|
||||
data: { ticker },
|
||||
});
|
||||
return Response.json(stock);
|
||||
}
|
||||
Reference in New Issue
Block a user