improve API
This commit is contained in:
parent
fd7191eda7
commit
b68936b274
2 changed files with 10 additions and 11 deletions
14
server.py
14
server.py
|
@ -1,6 +1,6 @@
|
|||
import logging
|
||||
|
||||
from flask import Flask, jsonify, url_for, redirect, abort
|
||||
from flask import Flask, jsonify, url_for, redirect, abort, request
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from sqlalchemy import text
|
||||
|
||||
|
@ -45,12 +45,10 @@ def get_venues():
|
|||
|
||||
|
||||
@app.route('/api/venue/<int:venueid>/')
|
||||
@app.route('/api/venue/<int:venueid>/<string:datetype>/')
|
||||
@app.route('/api/venue/<int:venueid>/<string:datetype>/<int:timeoffset>/')
|
||||
def get_meals(venueid, datetype="week", timeoffset=0):
|
||||
if datetype == "week":
|
||||
def get_meals(venueid):
|
||||
if request.args.get('mode', "week") == "week":
|
||||
sql_range = " AND YEARWEEK(date, 1) = YEARWEEK(CURDATE(), 1) + :offset"
|
||||
elif datetype == "today":
|
||||
elif request.args.get('mode') == "day":
|
||||
sql_range = " AND date=DATE_ADD(CURDATE(), INTERVAL :offset DAY) "
|
||||
else:
|
||||
return abort(400)
|
||||
|
@ -58,7 +56,9 @@ def get_meals(venueid, datetype="week", timeoffset=0):
|
|||
FROM menus
|
||||
JOIN meals ON meals.id = menus.meal
|
||||
WHERE venue = :venue"""
|
||||
results = db.engine.execute(text(sql + sql_range), {"venue": venueid, "offset": timeoffset}).fetchall()
|
||||
results = db.engine.execute(text(sql + sql_range),
|
||||
{"venue": venueid, "offset": request.args.get('offset', 0)}
|
||||
).fetchall()
|
||||
menus = []
|
||||
for row in results:
|
||||
menu = dict(row)
|
||||
|
|
|
@ -3,12 +3,11 @@ info:
|
|||
description: "get the daily menus of selected venues"
|
||||
version: "1.0.0"
|
||||
title: "Hunger API"
|
||||
# termsOfService: "http://swagger.io/terms/"
|
||||
contact:
|
||||
email: "l.winkler23@mailbox.org"
|
||||
# license:
|
||||
# name: "Apache 2.0"
|
||||
# url: "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
license:
|
||||
name: "The MIT License"
|
||||
url: "https://opensource.org/licenses/MIT"
|
||||
externalDocs:
|
||||
description: "Github"
|
||||
url: "https://github.com/findus23/hunger"
|
||||
|
|
Reference in a new issue