diff --git a/src/vigenere_api/api/app.py b/src/vigenere_api/api/app.py index 7d0af337293c564e00c79d0c5d50350df0439bae..a963bbcd0334082ed7b4d7d119a7ee70e6ee904e 100644 --- a/src/vigenere_api/api/app.py +++ b/src/vigenere_api/api/app.py @@ -16,14 +16,13 @@ """Create the application Vigenere-API.""" -from blacksheep import Application -from blacksheep import Response +from blacksheep import Application, Response from blacksheep.server.env import is_development from blacksheep.server.responses import redirect -from .v1.controllers import CaesarController -from .v1.openapi_docs import docs - +from vigenere_api.version import get_version +from .v1.controllers import CaesarController as V1CaesarController +from .v1.openapi_docs import docs as v1_docs application = Application() application.debug = False @@ -39,13 +38,15 @@ if is_development(): # pragma: no cover application.debug = True application.show_error_details = True -application.register_controllers([CaesarController]) -docs.bind_app(application) +application.register_controllers([V1CaesarController]) +v1_docs.bind_app(application) get = application.router.get +version = get_version() + -@docs(ignored=True) +@v1_docs(ignored=True) @get() async def index() -> Response: """ @@ -58,4 +59,20 @@ async def index() -> Response: redirect Response """ - return redirect("/api/v1") + return redirect(f"/api/v{version.major}") + + +def __fallback() -> str: + """ + Process all requests to bad routes. + + Returns + ------- + error_text + str + """ + + return "OOPS! Nothing was found here!" + + +application.router.fallback = __fallback diff --git a/src/vigenere_api/api/v1/controllers/docs/__init__.py b/src/vigenere_api/api/v1/controllers/docs/__init__.py deleted file mode 100644 index ae19115604b299defb11e27bc455eeb9a0973a4e..0000000000000000000000000000000000000000 --- a/src/vigenere_api/api/v1/controllers/docs/__init__.py +++ /dev/null @@ -1,23 +0,0 @@ -# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -# Vigenere-API + -# Copyright (C) 2023 Axel DAVID + -# + -# This program is free software: you can redistribute it and/or modify it under + -# the terms of the GNU General Public License as published by the Free Software + -# Foundation, either version 3 of the License, or (at your option) any later version. + -# + -# This program is distributed in the hope that it will be useful, but WITHOUT ANY + -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. + -# + -# You should have received a copy of the GNU General Public License along with + -# this program. If not, see <https://www.gnu.org/licenses/>. + -# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -"""All OpenAPI docs for each controller.""" - -from .caesar import post_caesar_cipher_docs -from .caesar import post_caesar_decipher_docs - - -__all__ = ["post_caesar_cipher_docs", "post_caesar_decipher_docs"] diff --git a/src/vigenere_api/api/v1/controllers/docs/vigenere.py b/src/vigenere_api/api/v1/controllers/docs/vigenere.py deleted file mode 100644 index 44c1a51312655c1dd298daec1f585017a0b9c9f4..0000000000000000000000000000000000000000 --- a/src/vigenere_api/api/v1/controllers/docs/vigenere.py +++ /dev/null @@ -1,17 +0,0 @@ -# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -# Vigenere-API + -# Copyright (C) 2023 Axel DAVID + -# + -# This program is free software: you can redistribute it and/or modify it under + -# the terms of the GNU General Public License as published by the Free Software + -# Foundation, either version 3 of the License, or (at your option) any later version. + -# + -# This program is distributed in the hope that it will be useful, but WITHOUT ANY + -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. + -# + -# You should have received a copy of the GNU General Public License along with + -# this program. If not, see <https://www.gnu.org/licenses/>. + -# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -"""The vigenere controller's documentation.""" diff --git a/src/vigenere_api/api/v1/controllers/vigenere.py b/src/vigenere_api/api/v1/controllers/vigenere.py deleted file mode 100644 index dbd964bb3d840253c15b91e85d28c77e4b846fd0..0000000000000000000000000000000000000000 --- a/src/vigenere_api/api/v1/controllers/vigenere.py +++ /dev/null @@ -1,17 +0,0 @@ -# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -# Vigenere-API + -# Copyright (C) 2023 Axel DAVID + -# + -# This program is free software: you can redistribute it and/or modify it under + -# the terms of the GNU General Public License as published by the Free Software + -# Foundation, either version 3 of the License, or (at your option) any later version. + -# + -# This program is distributed in the hope that it will be useful, but WITHOUT ANY + -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. + -# + -# You should have received a copy of the GNU General Public License along with + -# this program. If not, see <https://www.gnu.org/licenses/>. + -# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -"""The vigenere controller."""