Skip to content

Commit

Permalink
Merge pull request #64 from akroon3r/add_active_notifications_to_api_3
Browse files Browse the repository at this point in the history
Add Active Notifications to API
  • Loading branch information
sjrumsby authored Dec 7, 2018
2 parents b18c54a + a5eff3b commit 85303ee
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions api/app/resources/theq/csrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
See the License for the specific language governing permissions and
limitations under the License.'''

from datetime import datetime
from flask import g
from flask_restplus import Resource
from qsystem import api, db, oidc
from sqlalchemy import exc
from app.models.bookings import Exam
from app.models.theq import Citizen, CSR, Period, ServiceReq, SRState
from app.schemas.bookings import ExamSchema
from app.schemas.theq import CitizenSchema, CSRSchema


Expand Down Expand Up @@ -50,13 +53,15 @@ class CsrSelf(Resource):

csr_schema = CSRSchema()
citizen_schema = CitizenSchema(many=True)
exam_schema = ExamSchema(many=True)

@oidc.accept_token(require_token=True)
def get(self):
try:
csr = CSR.find_by_username(g.oidc_token_info['username'])
db.session.add(csr)
active_sr_state = SRState.get_state_by_name("Active")
today = datetime.now()

active_citizens = Citizen.query \
.join(Citizen.service_reqs) \
Expand All @@ -65,10 +70,17 @@ def get(self):
.filter_by(csr_id=csr.csr_id) \
.filter(Period.time_end.is_(None))

exams = Exam.query \
.filter_by(office_id=csr.office_id) \
.filter(Exam.booking_id.is_(None),
Exam.expiry_date > today).all()

result = self.csr_schema.dump(csr)
active_citizens = self.citizen_schema.dump(active_citizens)
active_exams = self.exam_schema.dump(exams)

return {'csr': result.data,
'active_exams': active_exams,
'active_citizens': active_citizens.data,
'errors': result.errors}

Expand Down

0 comments on commit 85303ee

Please sign in to comment.