forked from admin/zeropost-tool
feat: P1 Calendar — CalendarView (month/week/list, drag&drop, channel filter)
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { requireUser } from '@/lib/session';
|
||||
import { engine } from '@/lib/engine';
|
||||
|
||||
// GET /api/calendar?from=&to=&channel_id=
|
||||
export async function GET(request) {
|
||||
const user = await requireUser();
|
||||
if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const params = {};
|
||||
if (searchParams.get('from')) params.from = searchParams.get('from');
|
||||
if (searchParams.get('to')) params.to = searchParams.get('to');
|
||||
if (searchParams.get('channel_id')) params.channel_id = searchParams.get('channel_id');
|
||||
|
||||
try {
|
||||
const data = await engine.getCalendar(user.id, params);
|
||||
return NextResponse.json(data);
|
||||
} catch (err) {
|
||||
return NextResponse.json({ error: err.message }, { status: err.status || 500 });
|
||||
}
|
||||
}
|
||||
|
||||
// PATCH /api/calendar — reschedule user_post (drag & drop)
|
||||
export async function PATCH(request) {
|
||||
const user = await requireUser();
|
||||
if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
|
||||
const { id, scheduled_at } = await request.json();
|
||||
if (!id || !scheduled_at) {
|
||||
return NextResponse.json({ error: 'id and scheduled_at required' }, { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
const post = await engine.updatePost(user.id, id, { scheduled_at, status: 'scheduled' });
|
||||
return NextResponse.json(post);
|
||||
} catch (err) {
|
||||
return NextResponse.json({ error: err.message }, { status: err.status || 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user