feat(beatmap,beatmapset): get beatmap & beatmapset information by id

This commit is contained in:
MingxuanGame
2025-07-25 17:01:01 +08:00
parent f8abc7067f
commit 376d98ad5a
12 changed files with 452 additions and 9 deletions

26
app/router/beatmap.py Normal file
View File

@@ -0,0 +1,26 @@
from __future__ import annotations
from app.database import (
Beatmap,
BeatmapResp,
User as DBUser,
)
from app.dependencies.database import get_db
from app.dependencies.user import get_current_user
from .api_router import router
from fastapi import Depends, HTTPException
from sqlmodel import Session, select
@router.get("/beatmaps/{bid}", tags=["beatmap"], response_model=BeatmapResp)
async def get_beatmap(
bid: int,
current_user: DBUser = Depends(get_current_user),
db: Session = Depends(get_db),
):
beatmap = db.exec(select(Beatmap).where(Beatmap.id == bid)).first()
if not beatmap:
raise HTTPException(status_code=404, detail="Beatmap not found")
return BeatmapResp.from_db(beatmap)