fix: wire show_day/show_hour config into API, simplify AddTrackRequest
- create_app now accepts show_day/show_hour params instead of hardcoding Wednesday 22:00 - main.py passes config values through to create_app - Removed soundcloud_url from AddTrackRequest (not implemented); track_id is now required Made-with: Cursor
This commit is contained in:
@@ -15,8 +15,7 @@ class RefreshRequest(BaseModel):
|
||||
|
||||
|
||||
class AddTrackRequest(BaseModel):
|
||||
soundcloud_url: str | None = None
|
||||
track_id: int | None = None
|
||||
track_id: int
|
||||
position: int | None = None
|
||||
|
||||
|
||||
@@ -24,7 +23,13 @@ class MoveTrackRequest(BaseModel):
|
||||
position: int
|
||||
|
||||
|
||||
def create_app(db: Database, poller, admin_token: str) -> FastAPI:
|
||||
def create_app(
|
||||
db: Database,
|
||||
poller,
|
||||
admin_token: str,
|
||||
show_day: int = 2,
|
||||
show_hour: int = 22,
|
||||
) -> FastAPI:
|
||||
app = FastAPI(title="NtR SoundCloud Fetcher")
|
||||
|
||||
def _require_admin(authorization: str | None = Header(None)):
|
||||
@@ -36,7 +41,7 @@ def create_app(db: Database, poller, admin_token: str) -> FastAPI:
|
||||
|
||||
def _current_show():
|
||||
now = datetime.now(timezone.utc)
|
||||
week_start, week_end = get_show_week(now, show_day=2, show_hour=22)
|
||||
week_start, week_end = get_show_week(now, show_day=show_day, show_hour=show_hour)
|
||||
return db.get_or_create_show(week_start, week_end)
|
||||
|
||||
@app.get("/health")
|
||||
@@ -106,10 +111,8 @@ def create_app(db: Database, poller, admin_token: str) -> FastAPI:
|
||||
@app.post("/admin/tracks")
|
||||
def admin_add_track(body: AddTrackRequest, _=Depends(_require_admin)):
|
||||
show = _current_show()
|
||||
if body.track_id is not None:
|
||||
db.add_track_to_show(show.id, body.track_id, body.position)
|
||||
return {"status": "added"}
|
||||
raise HTTPException(status_code=400, detail="Provide track_id")
|
||||
db.add_track_to_show(show.id, body.track_id, body.position)
|
||||
return {"status": "added"}
|
||||
|
||||
@app.delete("/admin/tracks/{track_id}")
|
||||
def admin_remove_track(track_id: int, _=Depends(_require_admin)):
|
||||
|
||||
Reference in New Issue
Block a user