2020-11-16 02:00:43 +03:00
|
|
|
"""Example blueprint."""
|
|
|
|
|
|
|
|
from flask import Blueprint, request, render_template
|
|
|
|
from dependency_injector.wiring import inject, Provide
|
|
|
|
|
|
|
|
from githubnavigator.services import SearchService
|
|
|
|
from githubnavigator.containers import Container
|
|
|
|
|
|
|
|
|
2021-09-30 22:53:37 +03:00
|
|
|
blueprint = Blueprint("example", __name__, template_folder="templates/")
|
2020-11-16 02:00:43 +03:00
|
|
|
|
|
|
|
|
2021-09-30 22:53:37 +03:00
|
|
|
@blueprint.route("/")
|
2020-11-16 02:00:43 +03:00
|
|
|
@inject
|
|
|
|
def index(
|
|
|
|
search_service: SearchService = Provide[Container.search_service],
|
|
|
|
default_query: str = Provide[Container.config.default.query],
|
|
|
|
default_limit: int = Provide[Container.config.default.limit.as_int()],
|
|
|
|
):
|
2021-09-30 22:53:37 +03:00
|
|
|
query = request.args.get("query", default_query)
|
|
|
|
limit = request.args.get("limit", default_limit, int)
|
2020-11-16 02:00:43 +03:00
|
|
|
|
|
|
|
repositories = search_service.search_repositories(query, limit)
|
|
|
|
|
|
|
|
return render_template(
|
2021-09-30 22:53:37 +03:00
|
|
|
"index.html",
|
2020-11-16 02:00:43 +03:00
|
|
|
query=query,
|
|
|
|
limit=limit,
|
|
|
|
repositories=repositories,
|
|
|
|
)
|