def get(self): try: user = g.jwt_oidc_token_info['username'] has_role([Role.internal_user.value], g.jwt_oidc_token_info['realm_access']['roles'], user, "CitizenList GET /citizens/") csr = CSR.find_by_username(g.jwt_oidc_token_info['username']) if not csr: raise Exception('no user found with username: `{}`'.format( g.jwt_oidc_token_info['username'])) citizens = Citizen.query \ .options(joinedload(Citizen.service_reqs, innerjoin=True).joinedload(ServiceReq.periods).options(raiseload(Period.sr),joinedload(Period.csr).raiseload('*')),raiseload(Citizen.office),raiseload(Citizen.counter),raiseload(Citizen.user)) \ .filter_by(office_id=csr.office_id, cs_id=active_id) \ .order_by(Citizen.priority) result = self.citizens_schema.dump(citizens) return { 'citizens': result, 'errors': self.citizens_schema.validate(citizens) }, 200 except exc.SQLAlchemyError as e: print(e) return {'message': 'API is down'}, 500
def post(self): user = g.oidc_token_info['username'] has_role([Role.internal_user.value], g.oidc_token_info['realm_access']['roles'], user, "CitizenList POST /citizens/") json_data = request.get_json() csr = CSR.find_by_username(g.oidc_token_info['username']) if not csr: raise Exception('no user found with username: `{}`'.format(g.oidc_token_info['username'])) try: citizen = self.citizen_schema.load(json_data).data citizen.office_id = csr.office_id citizen.start_time = datetime.now() except ValidationError as err: print(err) return {"message": err.messages}, 422 citizen.cs_id = active_id citizen.service_count = 1 db.session.add(citizen) db.session.commit() SnowPlow.add_citizen(citizen, csr) result = self.citizen_schema.dump(citizen) return {'citizen': result.data, 'errors': result.errors}, 201
def get(self): try: user = g.oidc_token_info['username'] has_role([Role.internal_user.value], g.oidc_token_info['realm_access']['roles'], user, "CsrStateList GET /csr_states/") states = CSRState.query.all() result = self.csr_state_schema.dump(states) return {'csr_states': result.data, 'errors': result.errors} except exc.SQLAlchemyError as e: print(e) return {'message': 'API is down'}, 500
def get(self): try: user = g.oidc_token_info['username'] has_role([Role.internal_user.value], g.oidc_token_info['realm_access']['roles'], user, "CitizenList GET /citizens/") csr = CSR.find_by_username(g.oidc_token_info['username']) if not csr: raise Exception('no user found with username: `{}`'.format(g.oidc_token_info['username'])) citizens = Citizen.query.filter_by(office_id=csr.office_id, cs_id=active_id) \ .order_by(Citizen.priority) \ .join(Citizen.service_reqs).all() result = self.citizens_schema.dump(citizens) return {'citizens': result.data, 'errors': result.errors}, 200 except exc.SQLAlchemyError as e: print(e) return {'message': 'API is down'}, 500