feat: Add settings API endpoint
- Add GET endpoint to retrieve current settings - Add POST endpoint to update settings - Add PUT endpoint to update individual settings fields
This commit is contained in:
36
app/api/settings/route.ts
Normal file
36
app/api/settings/route.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { NextRequest, NextResponse } from 'next/server'
|
||||||
|
import { settingsManager } from '../../../lib/settings'
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
try {
|
||||||
|
const settings = await settingsManager.loadSettings()
|
||||||
|
return NextResponse.json(settings)
|
||||||
|
} catch (e: any) {
|
||||||
|
return NextResponse.json({ error: e.message }, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(req: NextRequest) {
|
||||||
|
try {
|
||||||
|
const updates = await req.json()
|
||||||
|
const settings = await settingsManager.updateSettings(updates)
|
||||||
|
return NextResponse.json(settings)
|
||||||
|
} catch (e: any) {
|
||||||
|
return NextResponse.json({ error: e.message }, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function PUT(req: NextRequest) {
|
||||||
|
try {
|
||||||
|
const { symbol, timeframe, layouts } = await req.json()
|
||||||
|
|
||||||
|
if (symbol) await settingsManager.setSymbol(symbol)
|
||||||
|
if (timeframe) await settingsManager.setTimeframe(timeframe)
|
||||||
|
if (layouts) await settingsManager.setLayouts(layouts)
|
||||||
|
|
||||||
|
const settings = await settingsManager.loadSettings()
|
||||||
|
return NextResponse.json(settings)
|
||||||
|
} catch (e: any) {
|
||||||
|
return NextResponse.json({ error: e.message }, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user