-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1691 from emfcamp/volunteer-info-beamer-api
Dumb volunteer API for Info Beamer to consume
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
} |