Commit 360b5c0a authored by Patrick van der Leer's avatar Patrick van der Leer
Browse files

Refs #2 - this shit works

parent 672c357d
# Created by .ignore support plugin (hsz.mobi)
*.db
### VirtualEnv template
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
......
import logging
from logging.handlers import RotatingFileHandler
import connexion
from connexion import RestyResolver
# import connexion
from flask import Flask
from flask_cors import CORS
from eBookHub.config import ProdConfig
from . import extensions as ext
......@@ -14,22 +15,36 @@ def init(config_object=ProdConfig):
:param config_object: The configuration object to use.
"""
connextion_app = connexion.App(__name__, specification_dir='openapi/')
connextion_app.add_api('core.yaml')
app = connextion_app.app
app = Flask(__name__)
app.config.from_object(config_object)
app.config['intercept_exceptions'] = False
configure_extensions(app)
configure_logging(app)
configure_blueprints(app)
with app.app_context():
configure_blueprints(app)
CORS(
app,
origins='*',
allow_headers=['Content-Type', 'Authorization', 'Access-Control-Allow-Credentials'],
supports_credentials=True
)
configure_shellcontext(app)
return app
def configure_blueprints(app):
""" Configure blueprints. """
pass
create_api(app)
def create_api(app, host='localhost', port=5000, api_prefix=''):
from safrs import SAFRSAPI
from .models import Author, Book, BookEdition
api = SAFRSAPI(app, host=host, port=port, prefix=api_prefix)
api.expose_object(Author)
api.expose_object(Book)
api.expose_object(BookEdition)
def configure_extensions(app):
......
from . import authors
\ No newline at end of file
def get_all_authors():
return []
from inspect import isfunction, ismethod
from datetime import datetime as dt
from safrs import SAFRSBase
from sqlalchemy.ext.declarative import DeclarativeMeta
from sqlalchemy.orm.collections import InstrumentedList
......@@ -85,7 +86,7 @@ class SoftDeleteMixin(object):
return self.delete(commit=commit, hard_delete=True)
class Model(db.Model, PrettyPrint):
class Model(SAFRSBase, db.Model, PrettyPrint):
"""Base model class that includes CRUD convenience methods."""
__abstract__ = True
......
from .core import Author, Book, BookEdition
__all__ = [
Author,
Book,
BookEdition
]
openapi: '3.0.0'
info:
title: eBook HUB
version: "0.1"
paths:
/authors:
get:
tags:
- Authors
operationId: eBookHub.api.authors.get_all_authors
summary: Get all authors
parameters:
- name: limit
in: query
schema:
type: integer
minimum: 0
default: 100
responses:
'200':
description: Return authors
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Author'
components:
parameters:
author_id:
name: author_id
description: Author's Unique identifier
in: path
required: true
schema:
type: string
pattern: '^[a-zA-Z0-9-]+$'
schemas:
Author:
type: object
required:
- name
properties:
id:
type: integer
description: Unique identifier
example: '123'
readOnly: true
name:
type: string
description: Author's name
example: J.K. Rowling
minLength: 1
maxLength: 255
\ No newline at end of file
from eBookHub import init
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager, prompt_bool
from eBookHub import init, db
from eBookHub.utils import get_config
database_manager = Manager(usage="Perform database operations")
@database_manager.command
def drop():
"""Drops database tables"""
if prompt_bool("Are you sure you want to lose all your data"):
db.drop_all()
@database_manager.command
def create(default_data=True, sample_data=False):
"""Creates database tables from sqlalchemy models"""
db.create_all()
@database_manager.command
def recreate(default_data=True, sample_data=False):
"""Recreates database tables (same as issuing 'drop' and then 'create')"""
drop()
create(default_data, sample_data)
app = init(get_config())
manager = Manager(app)
migrate = Migrate(app, db)
manager.add_command('db', database_manager)
manager.add_command('database', database_manager)
manager.add_command('alembic', MigrateCommand)
if __name__ == "__main__":
manager.run()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment