Add GET/POST /competitors/config/system endpoints for Settings page

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-05 12:30:29 +00:00
parent 8948d3abf6
commit d94b8feee6

View file

@ -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") @router.post("/config/location")
async def set_location_config( async def set_location_config(
config: LocationConfigRequest, config: LocationConfigRequest,