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

Google Calendar Integration #183

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
stub out crud and add middlewares to events API
  • Loading branch information
PokeJofeJr4th committed Oct 20, 2024
commit 43e1cd1c7f89093c8196a2bd433646f56bab2297
24 changes: 24 additions & 0 deletions next/app/api/calendar/[event_id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { NextRequest } from "next/server";
import { getToken } from "../../../../lib/calendar";

/**
* HTTP GET to /api/calendar/[event_id]
*
* List all of the events in the calendar
*
* @param request
* @returns
*/
export async function GET(
request: NextRequest,
{ params: { id } }: { params: { id: string } }
) {
const gcal_token = await getToken();
// TODO: Where do we get this?
const calendar_id = 0;

// TODO: Where does the token go?
return await fetch(
`https://calendar.google.com/calendars/${calendar_id}/events/${id}`
);
}
96 changes: 96 additions & 0 deletions next/app/api/calendar/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { NextRequest } from "next/server";
import { getToken } from "../../../lib/calendar";

/**
* HTTP GET to /api/calendar
*
* List all of the events in the calendar
*
* @param request
* @returns
*/
export async function GET(request: NextRequest) {
const gcal_token = await getToken();
// TODO: Where do we get this?
const calendar_id = 0;

// TODO: Where does the token go?
return await fetch(
`https://calendar.google.com/calendars/${calendar_id}/events`
);
}

/**
* HTTP POST to /api/calendar
*
* Creates a new event
*
* @param request
* @returns
*/
export async function POST(request: NextRequest) {
const gcal_token = await getToken();
// TODO: Where do we get this?
const calendar_id = 0;

// TODO: Where does the token go?
// TODO: Request Body
return await fetch(
`https://calendar.google.com/calendars/${calendar_id}/events`,
{ method: "POST" }
);
}

/**
* HTTP PUT to /api/calendar
*
* Edits an event
*
* @param request
* @returns
*/
export async function PUT(request: NextRequest) {
const gcal_token = await getToken();
// TODO: Where do we get this?
const calendar_id = 0;

// TODO: Where does the token go?
// TODO: Request Body
return await fetch(
`https://calendar.google.com/calendars/${calendar_id}/events`,
{ method: "PUT" }
);
}

/**
* HTTP DELETE to /api/calendar
*
* Deletes an event
*
* @param request
* @returns
*/
export async function DELETE(request: NextRequest) {
let body;
try {
body = await request.json();
} catch {
return new Response("Invalid JSON", { status: 422 });
}

// verify the id is included
if (!("id" in body)) {
return new Response("ID must be included", { status: 422 });
}
const id = body.id;

const gcal_token = await getToken();
// TODO: Where do we get this?
const calendar_id = 0;

// TODO: Where does the token go?
return await fetch(
`https://calendar.google.com/calendars/${calendar_id}/events/${id}`,
{ method: "DELETE" }
);
}
1 change: 1 addition & 0 deletions next/lib/middlewares/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const ROUTES: { [key: string]: AuthVerifier } = {
course: nonGetOfficerVerifier,
courseTaken: nonGetMentorVerifier,
departments: nonGetOfficerVerifier,
events: nonGetOfficerVerifier,
golinks: goLinkVerifier,
hourBlocks: nonGetOfficerVerifier,
mentor: nonGetOfficerVerifier,
Expand Down