Exemplo n.º 1
0
    def get(self, field_id):
        field = Fields.query.filter_by(id=field_id).first_or_404()
        schema = FieldSchema()

        response = schema.dump(field)

        if response.errors:
            return {"success": False, "errors": response.errors}, 400

        return {"success": True, "data": response.data}
Exemplo n.º 2
0
    def get(self, query_args):
        q = query_args.pop("q", None)
        field = str(query_args.pop("field", None))
        filters = build_model_filters(model=Fields, query=q, field=field)

        fields = Fields.query.filter_by(**query_args).filter(*filters).all()
        schema = FieldSchema(many=True)

        response = schema.dump(fields)

        if response.errors:
            return {"success": False, "errors": response.errors}, 400

        return {"success": True, "data": response.data}
Exemplo n.º 3
0
    def post(self):
        req = request.get_json()
        schema = FieldSchema()
        response = schema.load(req, session=db.session)

        if response.errors:
            return {"success": False, "errors": response.errors}, 400

        db.session.add(response.data)
        db.session.commit()

        response = schema.dump(response.data)
        db.session.close()

        return {"success": True, "data": response.data}
Exemplo n.º 4
0
    def patch(self, field_id):
        field = Fields.query.filter_by(id=field_id).first_or_404()
        schema = FieldSchema()

        req = request.get_json()

        response = schema.load(req, session=db.session, instance=field)
        if response.errors:
            return {"success": False, "errors": response.errors}, 400

        db.session.commit()

        response = schema.dump(response.data)
        db.session.close()

        return {"success": True, "data": response.data}