Skip to content

Commit

Permalink
Merge pull request #1691 from emfcamp/volunteer-info-beamer-api
Browse files Browse the repository at this point in the history
Dumb volunteer API for Info Beamer to consume
  • Loading branch information
jellybob authored May 28, 2024
2 parents ee8009f + fa87e68 commit 0cf80e8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/volunteer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ def volunteer_variables():
from . import training # noqa: F401
from . import bar_training # noqa: F401
from . import stats # noqa: F401
from . import api # noqa: F401
46 changes: 46 additions & 0 deletions apps/volunteer/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from datetime import datetime

from sqlalchemy import and_
from models.volunteer.shift import Shift
from . import volunteer


def serialize_shift(shift: Shift):
return {
"id": shift.id,
"role": shift.role.name,
"venue": shift.venue.name,
"min_needed": shift.min_needed,
"max_needed": shift.max_needed,
"current": shift.current_count,
"start": shift.start,
"end": shift.end,
}


@volunteer.route("/info-beamer.json")
def volunteer_json():
"""Basic API to get volunteer needs on Info Beamer screens."""
urgent_shifts = (
Shift.query.filter(and_(Shift.end >= datetime.now(), Shift.current_count < Shift.min_needed))
.order_by(Shift.start)
.limit(10)
.all()
)
non_urgent_shifts = (
Shift.query.filter(
and_(
Shift.end >= datetime.now(),
Shift.current_count < Shift.max_needed,
Shift.current_count >= Shift.min_needed,
)
)
.order_by(Shift.start)
.limit(10)
.all()
)

return {
"urgent_shifts": [serialize_shift(shift) for shift in urgent_shifts],
"non_urgent_shifts": [serialize_shift(shift) for shift in non_urgent_shifts],
}

0 comments on commit 0cf80e8

Please sign in to comment.