From 61af02a0d3fe4fc5d3f161c68dc6a3b67e694a80 Mon Sep 17 00:00:00 2001 From: DAVID Axel <axel.david@etu.univ-amu.fr> Date: Wed, 3 May 2023 04:05:59 +0200 Subject: [PATCH] refactor: :lipstick: Prepare the app before the v2 --- src/vigenere_api/api/app.py | 35 ++++++++++++++----- .../api/v1/controllers/docs/__init__.py | 23 ------------ .../api/v1/controllers/docs/vigenere.py | 17 --------- .../api/v1/controllers/vigenere.py | 17 --------- 4 files changed, 26 insertions(+), 66 deletions(-) delete mode 100644 src/vigenere_api/api/v1/controllers/docs/__init__.py delete mode 100644 src/vigenere_api/api/v1/controllers/docs/vigenere.py delete mode 100644 src/vigenere_api/api/v1/controllers/vigenere.py diff --git a/src/vigenere_api/api/app.py b/src/vigenere_api/api/app.py index 7d0af33..a963bbc 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 ae19115..0000000 --- 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 44c1a51..0000000 --- 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 dbd964b..0000000 --- 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.""" -- GitLab