Skip to content

Commit

Permalink
Fix dependency issue based on ssola/python-flask-microservice#3 and s…
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelPeralvo committed May 10, 2018
1 parent de8f5c1 commit fae2ea5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
10 changes: 5 additions & 5 deletions api/items.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
items = {
0: {"name": "First item"}
}
from flask_injector import inject
from services.provider import ItemsProvider


def search() -> list:
return items
@inject
def search(data_provider: ItemsProvider) -> list:
return data_provider.get()
15 changes: 14 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
from connexion.resolver import RestyResolver
import connexion

from injector import Binder
from flask_injector import FlaskInjector
from connexion.resolver import RestyResolver

from services.provider import ItemsProvider


def configure(binder: Binder) -> Binder:
binder.bind(
ItemsProvider,
ItemsProvider([{"Name": "Test 1"}])
)


if __name__ == '__main__':
app = connexion.App(__name__, specification_dir='swagger/')
app.add_api('app.yaml', resolver=RestyResolver('api'))
FlaskInjector(app=app.app, modules=[configure])
app.run(port=9090)
Empty file added services/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions services/provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class ItemsProvider(object):
def __init__(self, items: list = []):
self._items = items

def get(self, number_of_items: int = 5) -> list:
if not self._items:
return []

if number_of_items > len(self._items):
number_of_items = len(self._items)

return self._items[0:number_of_items]

0 comments on commit fae2ea5

Please sign in to comment.