-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fcb3dd7
commit 2ca4be7
Showing
1 changed file
with
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,29 @@ | ||
from http import HTTPMethod | ||
|
||
from flask import Blueprint | ||
from sqlalchemy.orm import joinedload | ||
|
||
from OpenOversight.app.models.database import Assignment, Department, Officer, db | ||
from OpenOversight.app.models.database_cache import ( | ||
get_database_cache_entry, | ||
put_database_cache_entry, | ||
) | ||
from OpenOversight.app.utils.constants import KEY_DEPT_ALL_OFFICERS | ||
|
||
|
||
v1 = Blueprint("v1", __name__, url_prefix="/v1") | ||
|
||
|
||
@v1.route("/departments/<int:department_id>/officers", methods=[HTTPMethod.GET]) | ||
def download_dept_officers(department_id: int): | ||
cache_params = (Department(id=department_id), KEY_DEPT_ALL_OFFICERS) | ||
officers = get_database_cache_entry(*cache_params) | ||
if officers is None: | ||
officers = ( | ||
db.session.query(Officer) | ||
.options(joinedload(Officer.assignments).joinedload(Assignment.job)) | ||
.options(joinedload(Officer.salaries)) | ||
.filter_by(department_id=department_id) | ||
.all() | ||
) | ||
put_database_cache_entry(*cache_params, officers) |