Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select session page (migrated changes) #82

Merged
merged 22 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 5 additions & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ model Payment {
}

model GameSession {
id String @id @default(auto()) @map("_id") @db.ObjectId
bookingClose String
bookingOpen String
dateTime String
id String @id @default(auto()) @map("_id") @db.ObjectId
bookingClose DateTime
bookingOpen DateTime
startTime DateTime
endTime DateTime
location String
maxUsers Int
}
Expand Down
Binary file added public/images/BadmintonRacketLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/app/api/gamesession/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/db";

export const GET = async (req: NextRequest, params: { id: string }) => {
const session = prisma.gameSession.findUnique({
where: {
id: params.id,
},
});

return NextResponse.json(session);
};
20 changes: 20 additions & 0 deletions src/app/api/gamesession/current/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/db";

/**
* Gets game sessions currently available for booking
*/
export const GET = async (req: NextRequest) => {
const sessions = await prisma.gameSession.findMany({
where: {
bookingClose: {
gte: new Date(),
},
bookingOpen: {
lte: new Date(),
},
},
});

return NextResponse.json(sessions);
};
85 changes: 85 additions & 0 deletions src/app/api/gamesession/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/db";
import { Prisma } from "@prisma/client";
import { gameSessionValidator } from "@/lib/validators";

export const GET = async (request: NextRequest) => {
const sessions = await prisma.session.findMany();

return NextResponse.json({ data: sessions });
};

/**
* Creates a new game session
*/
export const POST = async (request: NextRequest) => {
const sessionBody = (await request.json()) as Omit<
Prisma.GameSessionGetPayload<{}>,
"id"
>;

const { success } = gameSessionValidator.safeParse(sessionBody);

if (!success) {
return NextResponse.json(
{
data: {},
msg: "failed, please include all required fields in response with the correct type",
},
{
status: 404,
},
);
}

const session = await prisma.gameSession.create({
data: { ...sessionBody },
});

return NextResponse.json({
data: session,
msg: "success",
});
};

export const PATCH = async (request: NextRequest) => {
const sessionId = request.nextUrl.searchParams.get("id");

if (!sessionId) {
return NextResponse.json(
{ data: {}, msg: "No id provided in the request" },
{ status: 404 },
);
}

const sessionBody = (await request.json()) as Omit<
Prisma.GameSessionGetPayload<{}>,
"id"
>;

const { success } = gameSessionValidator.safeParse(sessionBody);

if (!success) {
return NextResponse.json(
{
data: {},
msg: "failed, please include all required fields in response with the correct type",
},
{
status: 404,
},
);
}

const session = await prisma.gameSession.update({
where: {
id: sessionId,
},
data: { ...sessionBody },
});

return NextResponse.json({
data: session,
msg: "success",
});
};
12 changes: 0 additions & 12 deletions src/app/api/session/route.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/app/confirmation/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import ConfirmationIcon from "@/components/ConfirmationIcon/ConfirmationIcon";
import ConfirmedSessionCard from "@/components/ConfirmedSessionCard/ConfirmedSessionCard";
import { getSession } from "next-auth/react";
import { getServerSession } from "next-auth/next";
import Image from "next/image";
import ConfirmationBannerSVG from "public/images/ConfirmationBannerSVG.svg";

Expand Down Expand Up @@ -33,7 +33,7 @@ export default async function ConfirmationPage() {
// const {data} = useSession();
// console.log(data)

const session = await getSession();
const session = await getServerSession();
console.log(session);
dyzhuu marked this conversation as resolved.
Show resolved Hide resolved

return (
Expand Down
20 changes: 19 additions & 1 deletion src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,26 @@ scroll-shadow {
--scroll-shadow-bottom: linear-gradient(to bottom, transparent 0%, white 18px);
}

.scroll-fade {
-webkit-mask-image: linear-gradient(to top, transparent 0%, black 18px, black calc(100% - 15px), transparent 100%);
mask-image: linear-gradient(to top, transparent 0%, black 18px, black calc(100% - 15px), transparent 100%);
}

.error-shake {
-webkit-animation: shake 0.16s 0s 3;
animation: shake 0.16s 0s 3;
}


@keyframes shake {
0% { -webkit-transform: translateX(0); transform: translateX(0); }
25% { -webkit-transform: translateX(8px); transform: translateX(8px); }
75% { -webkit-transform: translateX(-8px); transform: translateX(-8px); }
100% { -webkit-transform: translateX(0); transform: translateX(0); }
}

/* TODO: Implement in tailwind */
.controls::before {
width: var(--highlight-width);
transform: translateX(var(--highlight-x-pos));
}
}
Loading
Loading