Skip to content

Commit

Permalink
Merge 44d0aab into 2524ecc
Browse files Browse the repository at this point in the history
  • Loading branch information
dougthor42 committed Feb 25, 2019
2 parents 2524ecc + 44d0aab commit 2195a9f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -22,6 +22,7 @@
+ `peewee-moves` was updated to v2.0.1.
+ Documentation is now reStructuredText and is hosted by ReadTheDocs (#91)
+ Switched to using `loguru` for logging. (#94)
+ Renamed some function arguments to be more clear. (#89)


## v0.3.0 (2019-01-28)
Expand Down
50 changes: 25 additions & 25 deletions src/trendlines/routes.py
Expand Up @@ -85,20 +85,20 @@ def post_datapoint():
return msg, 201


@api.route("/api/v1/data/<metric>", methods=["GET"])
def get_data_as_json(metric):
@api.route("/api/v1/data/<metric_name>", methods=["GET"])
def get_data_as_json(metric_name):
"""
Return data for a given metric as JSON.
"""
logger.debug("API: get '%s'" % metric)
logger.debug("API: get '%s'" % metric_name)
try:
raw_data = db.get_data(metric)
units = db.get_units(metric)
raw_data = db.get_data(metric_name)
units = db.get_units(metric_name)
except DoesNotExist:
return ErrorResponse.metric_not_found(metric)
return ErrorResponse.metric_not_found(metric_name)

if len(raw_data) == 0:
return ErrorResponse.metric_has_no_data(metric)
return ErrorResponse.metric_has_no_data(metric_name)

data = utils.format_data(raw_data, units)

Expand Down Expand Up @@ -164,17 +164,17 @@ def api_get_metrics():
pass


@api.route("/api/v1/metric/<metric>", methods=["GET"])
def get_metric_as_json(metric):
@api.route("/api/v1/metric/<metric_name>", methods=["GET"])
def get_metric_as_json(metric_name):
"""
Return metric information as JSON
"""
logger.debug("API: get metric '%s'" % metric)
logger.debug("API: get metric '%s'" % metric_name)

try:
raw_data = db.Metric.get(db.Metric.name == metric)
raw_data = db.Metric.get(db.Metric.name == metric_name)
except DoesNotExist:
return ErrorResponse.metric_not_found(metric)
return ErrorResponse.metric_not_found(metric_name)

data = model_to_dict(raw_data)

Expand Down Expand Up @@ -237,21 +237,21 @@ def post_metric():
return jsonify(body), 201


@api.route("/api/v1/metric/<metric>", methods=["DELETE"])
def delete_metric(metric):
logger.debug("'api: DELETE '%s'" % metric)
@api.route("/api/v1/metric/<metric_name>", methods=["DELETE"])
def delete_metric(metric_name):
logger.debug("'api: DELETE '%s'" % metric_name)

try:
found = db.Metric.get(db.Metric.name == metric)
found = db.Metric.get(db.Metric.name == metric_name)
found.delete_instance()
except DoesNotExist:
return ErrorResponse.metric_not_found(metric)
return ErrorResponse.metric_not_found(metric_name)
else:
return "", 204


@api.route("/api/v1/metric/<metric>", methods=["PUT"])
def put_metric(metric):
@api.route("/api/v1/metric/<metric_name>", methods=["PUT"])
def put_metric(metric_name):
"""
Replace a metric with new values.
Expand Down Expand Up @@ -292,10 +292,10 @@ def put_metric(metric):

# First see if our item actually exists
try:
metric = db.Metric.get(db.Metric.name == metric)
metric = db.Metric.get(db.Metric.name == metric_name)
old = model_to_dict(metric)
except DoesNotExist:
return ErrorResponse.metric_not_found(metric)
return ErrorResponse.metric_not_found(metric_name)

# Parse our json.
try:
Expand Down Expand Up @@ -324,8 +324,8 @@ def put_metric(metric):
return jsonify(rv), 200


@api.route("/api/v1/metric/<metric>", methods=["PATCH"])
def patch_metric(metric):
@api.route("/api/v1/metric/<metric_name>", methods=["PATCH"])
def patch_metric(metric_name):
"""
Update the values for a given metric.
Expand Down Expand Up @@ -364,10 +364,10 @@ def patch_metric(metric):

# First see if our item actually exists
try:
metric = db.Metric.get(db.Metric.name == metric)
metric = db.Metric.get(db.Metric.name == metric_name)
old = model_to_dict(metric)
except DoesNotExist:
return ErrorResponse.metric_not_found(metric)
return ErrorResponse.metric_not_found(metric_name)

metric = update_model_from_dict(metric, data)

Expand Down

0 comments on commit 2195a9f

Please sign in to comment.