-
-
Notifications
You must be signed in to change notification settings - Fork 19
Add calendar event management #2257
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
apps/web/src/app/api/v1/workspaces/[wsId]/calendar/events/[eventId]/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { createClient } from '@tuturuuu/supabase/next/server'; | ||
import { CalendarEvent } from '@tuturuuu/types/primitives/calendar-event'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
interface Params { | ||
params: Promise<{ | ||
wsId: string; | ||
eventId: string; | ||
}>; | ||
} | ||
|
||
export async function GET(_: Request, { params }: Params) { | ||
const supabase = await createClient(); | ||
const { wsId, eventId } = await params; | ||
|
||
try { | ||
const { data: event, error } = await supabase | ||
.from('workspace_calendar_events') | ||
.select('*') | ||
.eq('id', eventId) | ||
.eq('ws_id', wsId) | ||
.single(); | ||
|
||
if (error) throw error; | ||
|
||
return NextResponse.json(event); | ||
} catch (error) { | ||
console.error('Calendar event API error:', error); | ||
return NextResponse.json( | ||
{ error: 'An error occurred while processing your request' }, | ||
{ status: 500 } | ||
); | ||
} | ||
} | ||
|
||
export async function PUT(request: Request, { params }: Params) { | ||
const supabase = await createClient(); | ||
const { wsId, eventId } = await params; | ||
|
||
try { | ||
const updates: Partial<CalendarEvent> = await request.json(); | ||
|
||
const { data, error } = await supabase | ||
.from('workspace_calendar_events') | ||
.update({ | ||
title: updates.title, | ||
description: updates.description, | ||
start_at: updates.start_at, | ||
end_at: updates.end_at, | ||
color: updates.color, | ||
}) | ||
.eq('id', eventId) | ||
.eq('ws_id', wsId) | ||
.select() | ||
.single(); | ||
|
||
if (error) throw error; | ||
|
||
return NextResponse.json(data); | ||
} catch (error) { | ||
console.error('Calendar event API error:', error); | ||
return NextResponse.json( | ||
{ error: 'An error occurred while processing your request' }, | ||
{ status: 500 } | ||
); | ||
} | ||
} | ||
|
||
export async function DELETE(_: Request, { params }: Params) { | ||
const supabase = await createClient(); | ||
const { wsId, eventId } = await params; | ||
|
||
try { | ||
const { error } = await supabase | ||
.from('workspace_calendar_events') | ||
.delete() | ||
.eq('id', eventId) | ||
.eq('ws_id', wsId); | ||
|
||
if (error) throw error; | ||
|
||
return NextResponse.json({ message: 'Event deleted successfully' }); | ||
} catch (error) { | ||
console.error('Calendar event API error:', error); | ||
return NextResponse.json( | ||
{ error: 'An error occurred while processing your request' }, | ||
{ status: 500 } | ||
); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
apps/web/src/app/api/v1/workspaces/[wsId]/calendar/events/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { createClient } from '@tuturuuu/supabase/next/server'; | ||
import { CalendarEvent } from '@tuturuuu/types/primitives/calendar-event'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
interface Params { | ||
params: Promise<{ | ||
wsId: string; | ||
}>; | ||
} | ||
|
||
export async function GET(request: Request, { params }: Params) { | ||
const supabase = await createClient(); | ||
const { wsId } = await params; | ||
|
||
// Get the start_at and end_at from the URL | ||
const url = new URL(request.url); | ||
const start_at = url.searchParams.get('start_at'); | ||
const end_at = url.searchParams.get('end_at'); | ||
|
||
if (!start_at || !end_at) { | ||
return NextResponse.json( | ||
{ error: 'Start and end dates are required' }, | ||
{ status: 400 } | ||
); | ||
} | ||
|
||
try { | ||
const { data: events, error } = await supabase | ||
.from('workspace_calendar_events') | ||
.select('*') | ||
.eq('ws_id', wsId) | ||
.gte('start_at', new Date(start_at).toISOString()) | ||
.lte('end_at', new Date(end_at).toISOString()); | ||
|
||
if (error) throw error; | ||
|
||
return NextResponse.json({ data: events, count: events.length }); | ||
} catch (error) { | ||
console.error('Calendar events API error:', error); | ||
return NextResponse.json( | ||
{ error: 'An error occurred while processing your request' }, | ||
{ status: 500 } | ||
); | ||
} | ||
} | ||
|
||
export async function POST(request: Request, { params }: Params) { | ||
const supabase = await createClient(); | ||
const { wsId } = await params; | ||
|
||
try { | ||
const event: Omit<CalendarEvent, 'id'> = await request.json(); | ||
|
||
const { data, error } = await supabase | ||
.from('workspace_calendar_events') | ||
.insert({ | ||
title: event.title || '', | ||
description: event.description || '', | ||
start_at: event.start_at, | ||
end_at: event.end_at, | ||
color: event.color || 'blue', | ||
ws_id: wsId, | ||
}) | ||
.select() | ||
.single(); | ||
|
||
if (error) throw error; | ||
|
||
vhpx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return NextResponse.json(data, { status: 201 }); | ||
} catch (error) { | ||
console.error('Calendar events API error:', error); | ||
return NextResponse.json( | ||
{ error: 'An error occurred while processing your request' }, | ||
{ status: 500 } | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.