diff --git a/backend/api/competitors.py b/backend/api/competitors.py index 12fffa6..5e41cfb 100644 --- a/backend/api/competitors.py +++ b/backend/api/competitors.py @@ -144,6 +144,40 @@ async def get_scraper_status( ) +@router.get("/config/system") +async def get_system_config( + db: AsyncSession = Depends(get_db), + current_user: dict = Depends(get_current_user) +): + """Return all system_config rows as a flat dict.""" + result = await db.execute(text("SELECT config_key, config_value FROM system_config")) + return {row.config_key: row.config_value for row in result.fetchall()} + + +class SystemConfigUpdate(BaseModel): + key: str + value: str + + +@router.post("/config/system") +async def set_system_config( + payload: SystemConfigUpdate, + db: AsyncSession = Depends(get_db), + current_user: dict = Depends(get_current_user) +): + """Upsert a single system_config key.""" + await db.execute( + text(""" + INSERT INTO system_config (config_key, config_value) + VALUES (:key, :value) + ON CONFLICT (config_key) DO UPDATE SET config_value = EXCLUDED.config_value + """), + {'key': payload.key, 'value': payload.value} + ) + await db.commit() + return {"status": "success", "key": payload.key} + + @router.post("/config/location") async def set_location_config( config: LocationConfigRequest,