Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
149 changes: 43 additions & 106 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -50,90 +50,22 @@ model flow_state {
/// This model contains row level security and requires additional setup for migrations. Visit https://pris.ly/d/row-level-security for more info.
model identities {
provider_id String
user_id String @db.Uuid
user_id String @db.Uuid
identity_data Json
provider String
last_sign_in_at DateTime? @db.Timestamptz(6)
created_at DateTime? @db.Timestamptz(6)
updated_at DateTime? @db.Timestamptz(6)
email String?
id String @id @default(uuid()) @db.Uuid
users auth_users @relation(fields: [user_id], references: [id], onDelete: Cascade, onUpdate: NoAction)
last_sign_in_at DateTime? @db.Timestamptz(6)
created_at DateTime? @db.Timestamptz(6)
updated_at DateTime? @db.Timestamptz(6)
email String?
id String @id @default(uuid()) @db.Uuid
users users @relation(fields: [user_id], references: [id], onDelete: Cascade, onUpdate: NoAction)

@@unique([provider_id, provider], map: "identities_provider_id_provider_unique")
@@index([email])
@@index([user_id])
@@schema("auth")
}

model UserProfile {
userId String @id @db.Uuid
username String?
preferredLanguages String[] @default([])
preferredCategories String[] @default([])
Comment on lines -69 to -73

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the auth tests are failing because you deleted the schema, can you revert this change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could change this locally but I'm curious how to solve this in a permanent way. Every time I run the docker script they're getting rewritten because it's pulling from the prod DB.

favoriteMovies String[] @default([])

reviews Rating[] @relation("UserReviews")
comments Comment[] @relation("UserComments")

followers UserFollow[] @relation("Followers")
following UserFollow[] @relation("Following")

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Post Post[]

@@schema("public")
}

model UserFollow {
id String @id @default(uuid())
followerId String @db.Uuid
followingId String @db.Uuid

follower UserProfile @relation("Followers", fields: [followerId], references: [userId])
following UserProfile @relation("Following", fields: [followingId], references: [userId])

@@unique([followerId, followingId])
@@schema("public")
}

model Comment {
id String @id @default(uuid())
userId String @db.Uuid
ratingId String?
postId String?
content String
createdAt DateTime @default(now())

user UserProfile @relation("UserComments", fields: [userId], references: [userId])
rating Rating? @relation("RatingComments", fields: [ratingId], references: [id])
post Post? @relation("PostComments", fields: [postId], references: [id])

@@schema("public")
}

model Post {
id String @id @default(uuid())
userId String @db.Uuid
content String
type PostType
votes Int @default(0)
createdAt DateTime @default(now())

user UserProfile @relation(fields: [userId], references: [userId])
comments Comment[] @relation("PostComments")

@@schema("public")
}

enum PostType {
SHORT
LONG

@@schema("public")
}

/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
/// This model contains row level security and requires additional setup for migrations. Visit https://pris.ly/d/row-level-security for more info.
model instances {
Expand Down Expand Up @@ -192,7 +124,7 @@ model mfa_factors {
web_authn_credential Json?
web_authn_aaguid String? @db.Uuid
mfa_challenges mfa_challenges[]
users auth_users @relation(fields: [user_id], references: [id], onDelete: Cascade, onUpdate: NoAction)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we changing auth_users to users at all of these places?

users users @relation(fields: [user_id], references: [id], onDelete: Cascade, onUpdate: NoAction)

@@unique([user_id, phone], map: "unique_phone_factor_per_user")
@@index([user_id, created_at], map: "factor_id_created_at_idx")
Expand Down Expand Up @@ -230,7 +162,7 @@ model one_time_tokens {
relates_to String
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @default(now()) @db.Timestamp(6)
users auth_users @relation(fields: [user_id], references: [id], onDelete: Cascade, onUpdate: NoAction)
users users @relation(fields: [user_id], references: [id], onDelete: Cascade, onUpdate: NoAction)

@@unique([user_id, token_type])
@@index([relates_to], map: "one_time_tokens_relates_to_hash_idx", type: Hash)
Expand Down Expand Up @@ -324,7 +256,7 @@ model sessions {
tag String?
mfa_amr_claims mfa_amr_claims[]
refresh_tokens refresh_tokens[]
users auth_users @relation(fields: [user_id], references: [id], onDelete: Cascade, onUpdate: NoAction)
users users @relation(fields: [user_id], references: [id], onDelete: Cascade, onUpdate: NoAction)

@@index([not_after(sort: Desc)])
@@index([user_id])
Expand Down Expand Up @@ -370,7 +302,7 @@ model sso_providers {
/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
/// This model contains row level security and requires additional setup for migrations. Visit https://pris.ly/d/row-level-security for more info.
/// This model contains an expression index which requires additional setup for migrations. Visit https://pris.ly/d/expression-indexes for more info.
model auth_users {
model users {
instance_id String? @db.Uuid
id String @id @db.Uuid
aud String? @db.VarChar(255)
Expand All @@ -397,7 +329,7 @@ model auth_users {
phone_change String? @default("")
phone_change_token String? @default("") @db.VarChar(255)
phone_change_sent_at DateTime? @db.Timestamptz(6)
confirmed_at DateTime? @db.Timestamptz(6)
confirmed_at DateTime? @db.Timestamptz(6)
email_change_token_current String? @default("") @db.VarChar(255)
email_change_confirm_status Int? @default(0) @db.SmallInt
banned_until DateTime? @db.Timestamptz(6)
Expand All @@ -413,45 +345,43 @@ model auth_users {

@@index([instance_id])
@@index([is_anonymous])
@@map("users")
@@schema("auth")
}

model Rating {
id String @id @default(uuid())
userId String @db.Uuid
movieId String
stars Int
comment String?
tags String[] @default([])
date DateTime
votes Int @default(0)

user UserProfile @relation("UserReviews", fields: [userId], references: [userId])
threadedComments Comment[] @relation("RatingComments")
model bootcamp {
id BigInt @id @default(autoincrement())
created_at DateTime @default(now()) @db.Timestamptz(6)
name String?
fav_food Json? @db.Json

@@schema("public")
}

/// This model contains row level security and requires additional setup for migrations. Visit https://pris.ly/d/row-level-security for more info.
model movie {
movieId String @id
localRating String?
imdbRating BigInt?
languages Json?
title String?
description String?
numRatings String?
model local_event {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I think when you rebased you nuked all the changes to the schema besides yours that happened since you opened your branch, can you undo this?

id String @id(map: "local_events_pkey") @default(uuid()) @db.Uuid
title String
time DateTime? @default(dbgenerated("(now() AT TIME ZONE 'utc'::text)")) @db.Timestamptz(6)
description String
genre String
cost Float? @db.Real
occasion String?
languages String[]
lat Float?
lon Float?

@@schema("public")
}

model public_users {
user_id String @id @default(uuid()) @db.Uuid
username String?
created_at DateTime? @default(now()) @db.Timestamptz(6)
model movie {
movieId String @id @db.Uuid
localRating Int
imdbRating Int
languages String[]
title String
description String
numRatings Int

@@map("users")
@@schema("public")
}

Expand Down Expand Up @@ -502,3 +432,10 @@ enum one_time_token_type {

@@schema("auth")
}

enum PostType {
SHORT_POST
LONG_POST

@@schema("public")
}
161 changes: 161 additions & 0 deletions backend/src/controllers/local-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import type { Request, Response } from "express";
import { prisma } from "../services/db.js";

type LocalEvent = {
id: string;
title: string;
time: Date;
description: string;
genre: string;
languages: string[];
occasion: string;
cost: number;
lat: number;
lon: number;
};

export const getLocalEvent = async (req: Request, res: Response) => {
const { id } = req.params;
if (!id) return res.status(400).json({ message: "Event ID is required." });

try {
const event = await prisma.local_event.findUnique({ where: { id } });
if (!event) return res.status(404).json({ message: "Local event not found." });

const data: LocalEvent = {
id: event.id,
title: event.title,
time: event.time,
description: event.description,
genre: event.genre,
languages: event.languages,
occasion: event.occasion,
cost: event.cost,
lat: event.lat,
lon: event.lon,
};

res.status(200).json({ message: "Local event retrieved.", data });
} catch (err) {
res.status(404).json({ message: "Local event not found." });
}
};

export const createLocalEvent = async (req: Request, res: Response) => {
const { title, time, description, genre, languages, cost, occasion, lat, lon } = req.body;

if (
!title ||
!time ||
!description ||
!genre ||
!languages ||
cost == null ||
!occasion ||
lat == null ||
lon == null
) {
return res.status(400).json({ message: "Missing required event fields." });
}

try {
const event = await prisma.local_event.create({
data: {
title,
time: new Date(time),
description,
genre,
languages,
occasion,
cost,
lat,
lon,
},
});

res.status(201).json({
message: "Local event created.",
data: {
id: event.id,
title: event.title,
time: event.time,
description: event.description,
genre: event.genre,
languages: event.languages,
occasion: event.occasion,
cost: event.cost,
lat: event.lat,
lon: event.lon,
},
});
} catch (err) {
res.status(500).json({
message: "Failed to create local event.",
error: err instanceof Error ? err.message : "Unknown error",
});
}
};

export const updateLocalEvent = async (req: Request, res: Response) => {
const { id } = req.params;
const { title, time, description, genre, languages, cost, occasion, lat, lon } = req.body;

if (!id) return res.status(400).json({ message: "Event ID is required." });

try {
const existing = await prisma.local_event.findUnique({ where: { id } });
if (!existing) {
return res.status(404).json({ message: "Local event not found." });
}

const updated = await prisma.local_event.update({
where: { id },
data: {
title: title ?? existing.title,
time: time ? new Date(time) : existing.time,
description: description ?? existing.description,
genre: genre ?? existing.genre,
languages: languages ?? existing.languages,
cost: cost ?? existing.cost,
occasion: occasion ?? existing.occasion,
lat: lat ?? existing.lat,
lon: lon ?? existing.lon,
},
});

res.status(200).json({
message: "Local event updated.",
data: {
id: updated.id,
title: updated.title,
time: updated.time,
description: updated.description,
genre: updated.genre,
languages: updated.languages,
cost: updated.cost,
occasion: updated.occasion,
lat: updated.lat,
lon: updated.lon,
},
});
} catch (err) {
res.status(404).json({ message: "Local event not found." });
}
};

export const deleteLocalEvent = async (req: Request, res: Response) => {
const { id } = req.params;
if (!id) return res.status(400).json({ message: "Event ID is required." });

try {
const existing = await prisma.local_event.findUnique({ where: { id } });
if (!existing) {
return res.status(404).json({ message: "Local event not found." });
}

await prisma.local_event.delete({ where: { id } });
res.status(200).json({ message: "Local event deleted successfully." });
} catch (err) {
res.status(404).json({ message: "Local event not found." });
}
};
Loading