diff --git a/main.py b/main.py index 37e6274..dbec219 100644 --- a/main.py +++ b/main.py @@ -36,7 +36,6 @@ async def unicorn_exception_handler(request: Request, exc: ObjectNotFoundExcepti return JSONResponse(status_code=404, content={"detail": exc.name}) -auto_include_routers(app, routers) -auto_include_routers(app, modules, True) +auto_include_routers(app, routers, True) app.mount("/static", StaticFiles(directory="static"), name="static") diff --git a/modules/clients/routers/__init__.py b/routers/crm/__init__.py similarity index 100% rename from modules/clients/routers/__init__.py rename to routers/crm/__init__.py diff --git a/modules/fulfillment_base/routers/__init__.py b/routers/crm/v1/__init__.py similarity index 100% rename from modules/fulfillment_base/routers/__init__.py rename to routers/crm/v1/__init__.py diff --git a/routers/board.py b/routers/crm/v1/board.py similarity index 100% rename from routers/board.py rename to routers/crm/v1/board.py diff --git a/routers/deal.py b/routers/crm/v1/deal.py similarity index 100% rename from routers/deal.py rename to routers/crm/v1/deal.py diff --git a/routers/deal_group.py b/routers/crm/v1/deal_group.py similarity index 100% rename from routers/deal_group.py rename to routers/crm/v1/deal_group.py diff --git a/routers/module.py b/routers/crm/v1/module.py similarity index 100% rename from routers/module.py rename to routers/crm/v1/module.py diff --git a/routers/crm/v1/modules/__init__.py b/routers/crm/v1/modules/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/routers/crm/v1/modules/clients/__init__.py b/routers/crm/v1/modules/clients/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/modules/clients/routers/client.py b/routers/crm/v1/modules/clients/client.py similarity index 100% rename from modules/clients/routers/client.py rename to routers/crm/v1/modules/clients/client.py diff --git a/routers/crm/v1/modules/fulfillment_base/__init__.py b/routers/crm/v1/modules/fulfillment_base/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/modules/fulfillment_base/routers/barcode_template.py b/routers/crm/v1/modules/fulfillment_base/barcode_template.py similarity index 100% rename from modules/fulfillment_base/routers/barcode_template.py rename to routers/crm/v1/modules/fulfillment_base/barcode_template.py diff --git a/modules/fulfillment_base/routers/deal_product.py b/routers/crm/v1/modules/fulfillment_base/deal_product.py similarity index 100% rename from modules/fulfillment_base/routers/deal_product.py rename to routers/crm/v1/modules/fulfillment_base/deal_product.py diff --git a/modules/fulfillment_base/routers/deal_service.py b/routers/crm/v1/modules/fulfillment_base/deal_service.py similarity index 100% rename from modules/fulfillment_base/routers/deal_service.py rename to routers/crm/v1/modules/fulfillment_base/deal_service.py diff --git a/modules/fulfillment_base/routers/marketplace.py b/routers/crm/v1/modules/fulfillment_base/marketplace.py similarity index 100% rename from modules/fulfillment_base/routers/marketplace.py rename to routers/crm/v1/modules/fulfillment_base/marketplace.py diff --git a/modules/fulfillment_base/routers/product.py b/routers/crm/v1/modules/fulfillment_base/product.py similarity index 100% rename from modules/fulfillment_base/routers/product.py rename to routers/crm/v1/modules/fulfillment_base/product.py diff --git a/modules/fulfillment_base/routers/service.py b/routers/crm/v1/modules/fulfillment_base/service.py similarity index 100% rename from modules/fulfillment_base/routers/service.py rename to routers/crm/v1/modules/fulfillment_base/service.py diff --git a/modules/fulfillment_base/routers/service_category.py b/routers/crm/v1/modules/fulfillment_base/service_category.py similarity index 100% rename from modules/fulfillment_base/routers/service_category.py rename to routers/crm/v1/modules/fulfillment_base/service_category.py diff --git a/modules/fulfillment_base/routers/services_kit.py b/routers/crm/v1/modules/fulfillment_base/services_kit.py similarity index 100% rename from modules/fulfillment_base/routers/services_kit.py rename to routers/crm/v1/modules/fulfillment_base/services_kit.py diff --git a/routers/project.py b/routers/crm/v1/project.py similarity index 100% rename from routers/project.py rename to routers/crm/v1/project.py diff --git a/routers/status.py b/routers/crm/v1/status.py similarity index 100% rename from routers/status.py rename to routers/crm/v1/status.py diff --git a/utils/auto_include_routers.py b/utils/auto_include_routers.py index f31da6c..ce8abba 100644 --- a/utils/auto_include_routers.py +++ b/utils/auto_include_routers.py @@ -5,6 +5,8 @@ from types import ModuleType from fastapi import FastAPI, APIRouter +names_to_ignore = ["routers", "modules"] + def auto_include_routers(app: FastAPI, package: ModuleType, full_path: bool = False): """ @@ -16,7 +18,6 @@ def auto_include_routers(app: FastAPI, package: ModuleType, full_path: bool = Fa """ package_path = Path(package.__file__).parent - base_pkg_name = package.__name__.replace("_", "-") for _, name, _ in pkgutil.walk_packages(package.__path__, package.__name__ + "."): module = importlib.import_module(name) @@ -33,7 +34,7 @@ def auto_include_routers(app: FastAPI, package: ModuleType, full_path: bool = Fa parts: list[str] = list(relative_path.parts) # Remove "routers" folder(s) from prefix parts - parts = [p for p in parts if p != "routers"] + parts = [p for p in parts if p not in names_to_ignore] # Drop extension from filename parts[-1] = parts[-1].replace(".py", "") @@ -41,7 +42,6 @@ def auto_include_routers(app: FastAPI, package: ModuleType, full_path: bool = Fa if full_path: # Use full path prefix_parts = [p.replace("_", "-") for p in parts if p != "__init__"] - prefix_parts.insert(0, base_pkg_name) else: # Only use last file name prefix_parts = [parts[-1].replace("_", "-")]