Skip to content

Commit

Permalink
Edited prisma scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
Sui Zer committed Mar 21, 2024
1 parent 080e905 commit 133753e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 87 deletions.
47 changes: 47 additions & 0 deletions pages/api/locations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
// Handle POST requests - Create a new location
if (req.method === "POST") {
const { lat, lon } = req.body;
try {
// Validate lat and lon are numbers
if (typeof lat !== "number" || typeof lon !== "number") {
return res
.status(400)
.json({ error: "Latitude and longitude must be valid numbers" });
}

const newLocation = await prisma.location.create({
data: {
lat,
lon,
},
});
res.status(200).json(newLocation);
} catch (error) {
console.log(error);
res.status(500).json({ error: "Failed to create location" });
}
}
// Handle GET requests - List all locations
else if (req.method === "GET") {
try {
const locations = await prisma.location.findMany();
res.status(200).json(locations);
} catch (error) {
console.log(error);
res.status(500).json({ error: "Failed to retrieve locations" });
}
}
// Respond with 405 Method Not Allowed if the request method is not supported
else {
res.status(405).json({ error: "Method Not Allowed" });
}
}
68 changes: 0 additions & 68 deletions pages/api/users/index.ts

This file was deleted.

9 changes: 0 additions & 9 deletions prisma/migrations/20240318065941_init/migration.sql

This file was deleted.

3 changes: 0 additions & 3 deletions prisma/migrations/migration_lock.toml

This file was deleted.

12 changes: 5 additions & 7 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@

generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "debian-openssl-3.0.x"]
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id Int @id @default(autoincrement())
name String
pax Int
allergic String
}
model Location {
id Int @id @default(autoincrement())
lat Float
lon Float
}

0 comments on commit 133753e

Please sign in to comment.