31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
"""radpostauth — authentication log. Read-only."""
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
|
|
from .. import crud
|
|
from ..database import get_db
|
|
from ..models import RadPostAuth
|
|
from ..pagination import Page, PageParams
|
|
from ..schemas import RadPostAuthOut
|
|
|
|
router = APIRouter(prefix="/radpostauth", tags=["radpostauth (read-only)"])
|
|
|
|
|
|
@router.get("", response_model=Page[RadPostAuthOut])
|
|
def list_postauth(
|
|
page: PageParams = Depends(),
|
|
username: str | None = None,
|
|
reply: str | None = None,
|
|
db: Session = Depends(get_db),
|
|
):
|
|
filters = {"username": username, "reply": reply}
|
|
total = crud.count_rows(db, RadPostAuth, filters)
|
|
rows = crud.list_rows(db, RadPostAuth, limit=page.limit, offset=page.offset,
|
|
filters=filters, order_by=RadPostAuth.id.desc())
|
|
return Page(total=total, limit=page.limit, offset=page.offset, items=rows)
|
|
|
|
|
|
@router.get("/{item_id}", response_model=RadPostAuthOut)
|
|
def get_postauth(item_id: int, db: Session = Depends(get_db)):
|
|
return crud.get_row_or_404(db, RadPostAuth, item_id)
|