Skip to content

Commit

Permalink
Created API
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjung1998 committed Jan 17, 2024
1 parent 352e643 commit 2d9a1ed
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import express, { Express } from "express";
import cors from "cors";
import { PORT } from "./config/config.js";

import errorHandler from "./middlewares/error.middleware.js";

import algorithmRouter from "./routes/algorithm.routes.js";

import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
export const app: Express = express();

app.use(express.json());
Expand All @@ -14,6 +15,32 @@ app.use(cors());

app.use("/api/v1/algorithm", algorithmRouter);

app.post("/product", async (request, response) => {
const {title, size, color, description, gender, category, price, imageUrl} = request.body
const newProduct = await prisma.product.create({
data: {
title, size, color, description, gender, category, price, imageUrl
}
})
response.json(newProduct)
})

app.get("/products", async (request, response) => {
//add filtering
const prods = await prisma.product.findMany();

response.json(prods);
});

app.get("/product/:id", async (request, response) => {
let prodID = request.params.id;
const product = await prisma.product.findUnique({
where: {id: prodID}
})

response.json(product);
});

app.use(errorHandler);

app.listen(PORT, () => {
Expand Down

0 comments on commit 2d9a1ed

Please sign in to comment.