"""Routes for the api server""" from flask_restx import Resource, Namespace from .apimodel import weight_apimodel, bp_apimodel, bp_parser, weight_parser from .extensions import db from .datamodel import WeightData, BpData health_ns = Namespace("Health") @health_ns.route("/weight") class WeightAPI(Resource): """API Route /health/weight""" @health_ns.marshal_list_with(weight_apimodel) def get(self): """List weight datasets""" return WeightData.query.all() @health_ns.route("/weight-insert") class WeightInsertAPI(Resource): """API Route /health/weight-insert""" @health_ns.marshal_list_with(weight_apimodel) @health_ns.expect(weight_parser) def get(self): """Insert weight dataset by GET""" weight = WeightData(device=weight_parser.parse_args().device, weight=weight_parser.parse_args().weight) db.session.add(weight) db.session.commit() return weight, 201 @health_ns.route("/bp") class BpApi(Resource): """API Route bloodpressure""" @health_ns.marshal_list_with(bp_apimodel) def get(self): """List bloodpressure datasets""" return BpData.query.all() @health_ns.route("/bp-insert") class BpInsertAPI(Resource): """API Route /health/bp-insert""" @health_ns.marshal_list_with(bp_apimodel) @health_ns.expect(bp_parser) def get(self): """Insert bp dataset by GET""" bp = BpData(device = bp_parser.parse_args().device, sys = bp_parser.parse_args().sys, dia = bp_parser.parse_args().dia, pulse = bp_parser.parse_args().pulse) db.session.add(bp) db.session.commit() return bp, 201