Skip to content

Commit

Permalink
Merge f5fdb8e into 6a69ab3
Browse files Browse the repository at this point in the history
  • Loading branch information
dougthor42 committed Mar 21, 2019
2 parents 6a69ab3 + f5fdb8e commit 42e9ac1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
+ Added an internal api for datapoints to `db.py`. (#125)
+ The REST api is now viewable via a Swagger (or ReDoc!) web page! (#34)
+ Core API routes have been refactored to use Flask's Pluggable Views. (#128)
+ Sorted the Swagger API into logical blueprints by Schema/MethodView. (#133)


## 0.5.0 (2019-02-28)
Expand Down
2 changes: 2 additions & 0 deletions src/trendlines/app_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def create_app():
# Initialize flask-rest-api for OpenAPI (Swagger) documentation
routes.api_class.init_app(app)
routes.api_class.register_blueprint(routes.api)
routes.api_class.register_blueprint(routes.api_datapoint)
routes.api_class.register_blueprint(routes.api_metric)

# Create the database file and populate initial tables if needed.
orm.create_db(app.config['DATABASE'])
Expand Down
12 changes: 8 additions & 4 deletions src/trendlines/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
api_class = Api()
api = Blueprint("api", __name__,
description="All API.")
api_datapoint = Blueprint("DataPoints", __name__,
description="CRUD datapoint(s)")
api_metric = Blueprint("Metrics", __name__,
description="CRUD metric(s)")


# Make sure all pages show our version.
Expand Down Expand Up @@ -132,7 +136,7 @@ def get_data_as_json(metric_name):
return jsonify(data)


@api.route("/api/v1/datapoint")
@api_datapoint.route("/api/v1/datapoint")
class DataPoint(MethodView):
def get(self):
"""
Expand All @@ -150,7 +154,7 @@ def post(self):
pass


@api.route("/api/v1/datapoint/<datapoint_id>")
@api_datapoint.route("/api/v1/datapoint/<datapoint_id>")
class DataPointById(MethodView):
def get(self, datapoint_id):
"""
Expand Down Expand Up @@ -185,7 +189,7 @@ def delete(self, datapoint_id):
return "", 204


@api.route("/api/v1/metric")
@api_metric.route("/api/v1/metric")
class Metric(MethodView):
def get(self):
"""
Expand Down Expand Up @@ -256,7 +260,7 @@ def post(self):
return jsonify(body), 201


@api.route("/api/v1/metric/<metric_name>")
@api_metric.route("/api/v1/metric/<metric_name>")
class MetricById(MethodView):
def get(self, metric_name):
"""
Expand Down

0 comments on commit 42e9ac1

Please sign in to comment.