obs-ss-plugin-webui/app/api/teams/route.ts
Decobus 1d4b1eefba
Some checks failed
Lint and Build / build (20) (push) Has been cancelled
Lint and Build / build (22) (push) Has been cancelled
Initial commit - OBS Source Switcher Plugin UI
Complete Next.js application for managing OBS Source Switcher
- Stream management with multiple screen layouts
- Team management CRUD operations
- SQLite database integration
- OBS WebSocket API integration
- Updated to latest versions (Next.js 15.4.1, React 19.1.0, Tailwind CSS 4.0.0)
- Enhanced .gitignore for privacy and development
2025-07-15 22:15:57 -04:00

37 lines
No EOL
1.1 KiB
TypeScript

import { NextResponse } from 'next/server';
import { getDatabase } from '../../../lib/database';
import { Team } from '@/types';
import { TABLE_NAMES } from '@/lib/constants';
export async function GET() {
const db = await getDatabase();
const teams: Team[] = await db.all(`SELECT * FROM ${TABLE_NAMES.TEAMS}`);
return NextResponse.json(teams);
}
export async function POST(request: Request) {
try {
const { team_name } = await request.json();
if (!team_name) {
return NextResponse.json({ error: 'Team name is required' }, { status: 400 });
}
const db = await getDatabase();
const result = await db.run(
`INSERT INTO ${TABLE_NAMES.TEAMS} (team_name) VALUES (?)`,
[team_name]
);
const newTeam: Team = {
team_id: result.lastID!,
team_name: team_name
};
return NextResponse.json(newTeam, { status: 201 });
} catch (error) {
console.error('Error creating team:', error);
return NextResponse.json({ error: 'Failed to create team' }, { status: 500 });
}
}