Vibe coded a bit more ... now we have session, attached picture and analysis, MOA group computation
This commit is contained in:
37
blueprints/api/feed.py
Normal file
37
blueprints/api/feed.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from flask import Blueprint, request
|
||||
from sqlalchemy import func, select
|
||||
|
||||
from extensions import db
|
||||
from models import ShootingSession
|
||||
from .utils import ok, serialize_session
|
||||
|
||||
feed_bp = Blueprint("api_feed", __name__, url_prefix="/feed")
|
||||
|
||||
|
||||
@feed_bp.get("/")
|
||||
def feed():
|
||||
try:
|
||||
page = max(1, int(request.args.get("page", 1)))
|
||||
per_page = min(100, max(1, int(request.args.get("per_page", 20))))
|
||||
except (TypeError, ValueError):
|
||||
page, per_page = 1, 20
|
||||
|
||||
total = db.session.scalar(
|
||||
select(func.count()).select_from(ShootingSession)
|
||||
.where(ShootingSession.is_public == True) # noqa: E712
|
||||
) or 0
|
||||
|
||||
sessions = db.session.scalars(
|
||||
select(ShootingSession)
|
||||
.where(ShootingSession.is_public == True) # noqa: E712
|
||||
.order_by(ShootingSession.session_date.desc(), ShootingSession.created_at.desc())
|
||||
.offset((page - 1) * per_page)
|
||||
.limit(per_page)
|
||||
).all()
|
||||
|
||||
return ok({
|
||||
"data": [serialize_session(s, include_user=True) for s in sessions],
|
||||
"total": total,
|
||||
"page": page,
|
||||
"per_page": per_page,
|
||||
})
|
||||
Reference in New Issue
Block a user