|
|
|
@ -8,7 +8,7 @@ from apistar.backends.sqlalchemy_backend import Session
|
|
|
|
|
from apistar.frameworks.wsgi import WSGIApp as App
|
|
|
|
|
from apistar.handlers import docs_urls, static_urls
|
|
|
|
|
from models.schema import Base, Cookie
|
|
|
|
|
from render import JSONRenderer
|
|
|
|
|
import render
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def welcome(name=None):
|
|
|
|
@ -17,7 +17,6 @@ def welcome(name=None):
|
|
|
|
|
return {'message': 'Welcome to API Star, %s!' % name}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@annotate(renderers=[JSONRenderer()])
|
|
|
|
|
def get_cookies(session: Session):
|
|
|
|
|
cookies = session.query(Cookie).all()
|
|
|
|
|
# result = [{"id": cookie.id,
|
|
|
|
@ -34,7 +33,6 @@ def get_cookies(session: Session):
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@annotate(renderers=[JSONRenderer()])
|
|
|
|
|
def get_cookie(session: Session, id):
|
|
|
|
|
cookie = session.query(Cookie).filter_by(id=id).one_or_none()
|
|
|
|
|
if cookie is None:
|
|
|
|
@ -50,7 +48,7 @@ def create_cookie(session: Session, json_data: http.RequestData, route: Router):
|
|
|
|
|
qoh=json_data['qoh'],
|
|
|
|
|
unit_cost=json_data['unit_cost'])
|
|
|
|
|
session.add(cookie)
|
|
|
|
|
session.flush()
|
|
|
|
|
session.commit()
|
|
|
|
|
headers = {'Location': route.reverse_url('get_cookie', dict(id=cookie.id))}
|
|
|
|
|
return http.Response(cookie.to_dict(), status=201, headers=headers)
|
|
|
|
|
|
|
|
|
@ -68,7 +66,8 @@ settings = {
|
|
|
|
|
'DATABASE': {
|
|
|
|
|
'URL': 'postgresql://:@localhost/apistar',
|
|
|
|
|
'METADATA': Base.metadata
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'RENDERERS': [render.JSONRenderer()]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app = App(routes=routes,
|
|
|
|
@ -77,6 +76,5 @@ app = App(routes=routes,
|
|
|
|
|
components=sqlalchemy_backend.components
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
app.main()
|
|
|
|
|
app.main()
|
|
|
|
|