Compare commits
6 Commits
master
...
backend-pg
Author | SHA1 | Date | |
---|---|---|---|
|
70e6641e24 | ||
|
2631c344dd | ||
|
5c7ca46e56 | ||
|
4cb80df58a | ||
|
70a5a99909 | ||
|
039855db6f |
17
app.py
17
app.py
@ -1,7 +1,19 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import os
|
||||||
import connexion
|
import connexion
|
||||||
from flask_login import LoginManager
|
import sqlalchemy
|
||||||
|
|
||||||
|
from sqlalchemy import create_engine, Column, Integer, String
|
||||||
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
|
||||||
|
Base = declarative_base()
|
||||||
|
|
||||||
|
import models
|
||||||
|
|
||||||
|
engine = create_engine( os.environ.get( 'DATABASE_URL', 'sqlite:///:memory:' ), echo=True )
|
||||||
|
|
||||||
|
Base.metadata.create_all( engine )
|
||||||
|
|
||||||
app = connexion.App(__name__, specification_dir='./swagger/')
|
app = connexion.App(__name__, specification_dir='./swagger/')
|
||||||
app.add_api('swagger.yaml',
|
app.add_api('swagger.yaml',
|
||||||
@ -9,8 +21,5 @@ app.add_api('swagger.yaml',
|
|||||||
'title': 'Rubber Duck Booking Tool'
|
'title': 'Rubber Duck Booking Tool'
|
||||||
})
|
})
|
||||||
|
|
||||||
login_manager = LoginManager()
|
|
||||||
#login_manager.init_app(app)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(port=8080)
|
app.run(port=8080)
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
|
from flask import Flask, request
|
||||||
|
from flask_restful import Resource, Api
|
||||||
|
|
||||||
|
from models import Duck
|
||||||
|
|
||||||
|
#app =
|
||||||
def ducks_get():
|
def ducks_get():
|
||||||
return 'do some magic!'
|
return 'do some magic!'
|
||||||
|
|
||||||
def duck_get():
|
def duck_get( duck_id ):
|
||||||
return 'do some duck magic!'
|
return 'do some duck magic!'
|
||||||
|
|
||||||
|
def duck_post( name, color ):
|
||||||
|
new_duck = Duck( name, color )
|
||||||
|
return new_duck
|
||||||
|
24
models.py
Normal file
24
models.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import sqlalchemy as sa
|
||||||
|
import sqlalchemy.orm as orm
|
||||||
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
#from flask.ext.login import UserMixin
|
||||||
|
#from sqlalchemy_login_models.model import Base, UserKey, User as SLM_User
|
||||||
|
|
||||||
|
__all__ = ['Duck']
|
||||||
|
|
||||||
|
Base = declarative_base()
|
||||||
|
|
||||||
|
class Duck( Base ):
|
||||||
|
__tablename__ = 'duck'
|
||||||
|
__name__ = "duck"
|
||||||
|
|
||||||
|
duck_id = sa.Column( sa.Integer, primary_key=True )
|
||||||
|
name = sa.Column( sa.String )
|
||||||
|
color = sa.Column( sa.String )
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '{"duck_id": "'+ ( str( self.duck_id ) or '0' ) +'", "name": "'+ self.name +'", "color": "'+ self.color +'" }'
|
||||||
|
|
||||||
|
def __init__(self, name, color):
|
||||||
|
self.name = name
|
||||||
|
self.color = color
|
@ -2,4 +2,5 @@ Flask==0.11.1
|
|||||||
Flask-RESTful==0.3.5
|
Flask-RESTful==0.3.5
|
||||||
connexion==1.0.129
|
connexion==1.0.129
|
||||||
gunicorn
|
gunicorn
|
||||||
flask-login
|
sqlalchemy
|
||||||
|
psycopg2
|
||||||
|
@ -20,7 +20,7 @@ paths:
|
|||||||
200:
|
200:
|
||||||
description: "An object which contains metadata and an array of ducks"
|
description: "An object which contains metadata and an array of ducks"
|
||||||
schema:
|
schema:
|
||||||
type: array
|
type: "array"
|
||||||
items:
|
items:
|
||||||
$ref: '#/definitions/Duck'
|
$ref: '#/definitions/Duck'
|
||||||
security:
|
security:
|
||||||
@ -30,9 +30,33 @@ paths:
|
|||||||
tags:
|
tags:
|
||||||
- "default_controller"
|
- "default_controller"
|
||||||
operationId: "controllers.default_controller.duck_get"
|
operationId: "controllers.default_controller.duck_get"
|
||||||
|
parameters:
|
||||||
|
- name: "duck_id"
|
||||||
|
description: "ID of the Duck"
|
||||||
|
in: "path"
|
||||||
|
required: true
|
||||||
|
type: "integer"
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: "All data regarding the specified duck"
|
description: "All data regarding the specified duck"
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- "default_controller"
|
||||||
|
operationId: "controllers.default_controller.duck_post"
|
||||||
|
parameters:
|
||||||
|
- name: "name"
|
||||||
|
description: "Name of the Duck"
|
||||||
|
in: "formData"
|
||||||
|
required: true
|
||||||
|
type: "string"
|
||||||
|
- name: "color"
|
||||||
|
description: "Color of the Duck"
|
||||||
|
in: "formData"
|
||||||
|
required: true
|
||||||
|
type: "string"
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "Cool"
|
||||||
securityDefinitions:
|
securityDefinitions:
|
||||||
api_key:
|
api_key:
|
||||||
type: "apiKey"
|
type: "apiKey"
|
||||||
@ -40,17 +64,17 @@ securityDefinitions:
|
|||||||
in: "header"
|
in: "header"
|
||||||
definitions:
|
definitions:
|
||||||
Duck:
|
Duck:
|
||||||
type: object
|
type: "object"
|
||||||
properties:
|
properties:
|
||||||
duck_id:
|
duck_id:
|
||||||
type: number
|
type: "integer"
|
||||||
description: ID number of the duck
|
description: "ID number of the duck"
|
||||||
name:
|
name:
|
||||||
type: string
|
type: "string"
|
||||||
description: The name of the duck
|
description: "The name of the duck"
|
||||||
color:
|
color:
|
||||||
type: string
|
type: "string"
|
||||||
description: Color of the duck
|
description: "Color of the duck"
|
||||||
#species = models.ForeignKey(Species)
|
#species = models.ForeignKey(Species)
|
||||||
#location = models.ForeignKey(Location)
|
#location = models.ForeignKey(Location)
|
||||||
#competencies:
|
#competencies:
|
||||||
|
Loading…
Reference in New Issue
Block a user