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
work on the calendar API routes
PokeJofeJr4th committed Oct 20, 2024
commit e01b183b8738b8c458c7c96a88001aa215d2e4d3
2 changes: 1 addition & 1 deletion next/app/api/calendar/[event_id]/route.ts
Original file line number Diff line number Diff line change
@@ -19,6 +19,6 @@ export async function GET(

// TODO: Where does the token go?
return await fetch(
`https://calendar.google.com/calendars/${calendar_id}/events/${id}`
`https://www.googleapis.com/calendar/v3/calendars/${calendar_id}/events/${id}`
);
}
32 changes: 27 additions & 5 deletions next/app/api/calendar/route.ts
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ export async function GET(request: NextRequest) {

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

@@ -29,14 +29,34 @@ export async function GET(request: NextRequest) {
* @returns
*/
export async function POST(request: NextRequest) {
let body;
try {
body = await request.json();
} catch {
return new Response("Invalid JSON", { status: 422 });
}

// verify the id is included
if (
!(
"summary" in body &&
"description" in body &&
"location" in body &&
"start" in body &&
"end" in body
)
) {
return new Response("ID must be included", { status: 422 });
}

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`,
`https://www.googleapis.com/calendar/v3/calendars/${calendar_id}/events`,
{ method: "POST" }
);
}
@@ -46,6 +66,8 @@ export async function POST(request: NextRequest) {
*
* Edits an event
*
* Internally, this is mapped go gcal's PATCH method because it supports partial changes
*
* @param request
* @returns
*/
@@ -57,8 +79,8 @@ export async function PUT(request: NextRequest) {
// TODO: Where does the token go?
// TODO: Request Body
return await fetch(
`https://calendar.google.com/calendars/${calendar_id}/events`,
{ method: "PUT" }
`https://www.googleapis.com/calendar/v3/calendars/${calendar_id}/events`,
{ method: "PATCH" }
);
}

@@ -90,7 +112,7 @@ export async function DELETE(request: NextRequest) {

// TODO: Where does the token go?
return await fetch(
`https://calendar.google.com/calendars/${calendar_id}/events/${id}`,
`https://www.googleapis.com/calendar/v3/calendars/${calendar_id}/events/${id}`,
{ method: "DELETE" }
);
}