Refactor backend and frontend code for improved structure and functionality
- Rearranged imports in multiple files for consistency and clarity. - Updated logging middleware to exclude specific paths from logging. - Enhanced security module by cleaning up token handling and improving tenant validation. - Added tenant and company scoped mixins for better database model management. - Implemented generic CRUD routes for tenant-scoped resources. - Improved error handling and response management in API routes. - Cleaned up login and logout processes to ensure proper session management. - Introduced mechanisms to clear local storage and cookies on tenant change. - Enhanced company store to detect tenant changes and clear data accordingly. - Added new DTO mixins for currency and value affect flags.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import ConfigDict
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class CodePedimentoRegimenDTO(BaseModel):
|
||||
id: Optional[int] = None
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from sqlalchemy import (
|
||||
String,
|
||||
Integer,
|
||||
ForeignKey,
|
||||
ForeignKeyConstraint,
|
||||
PrimaryKeyConstraint,
|
||||
)
|
||||
from sqlalchemy.orm import mapped_column, Mapped, relationship
|
||||
|
||||
from core.database import Base
|
||||
from sqlalchemy import ForeignKeyConstraint, Integer, PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..pedimento_codes.models import PedimentoCode
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from .models import CodePedimentoRegimen
|
||||
from .dto import CodePedimentoRegimenDTO
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import CodePedimentoRegimenDTO
|
||||
from .models import CodePedimentoRegimen
|
||||
|
||||
router = APIRouter(prefix="/code-pedimento-regimens")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.code_pedimento_regimens.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.transport_types.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class ContainerDTO(BaseModel):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from sqlalchemy import String, PrimaryKeyConstraint
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from core.database import Base
|
||||
from sqlalchemy import PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
|
||||
class Container(Base):
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from .models import Container
|
||||
from .dto import ContainerDTO
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import ContainerDTO
|
||||
from .models import Container
|
||||
|
||||
router = APIRouter(prefix="/containers")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.containers.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class CountryDTO(BaseModel):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from sqlalchemy import String, PrimaryKeyConstraint, Index
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from core.database import Base
|
||||
from sqlalchemy import Index, PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
|
||||
class Country(Base):
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from .models import Country
|
||||
from .dto import CountryDTO
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import CountryDTO
|
||||
from .models import Country
|
||||
|
||||
router = APIRouter(prefix="/countries")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.countries.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class CurrencyTypeDTO(BaseModel):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from sqlalchemy import String, PrimaryKeyConstraint
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from core.database import Base
|
||||
from sqlalchemy import PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
|
||||
class CurrencyType(Base):
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from .models import CurrencyType
|
||||
from .dto import CurrencyTypeDTO
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import CurrencyTypeDTO
|
||||
from .models import CurrencyType
|
||||
|
||||
router = APIRouter(prefix="/currency-types")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.currency_types.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class CustomsSectionDTO(BaseModel):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from sqlalchemy import String, PrimaryKeyConstraint
|
||||
from sqlalchemy.orm import mapped_column
|
||||
from core.database import Base
|
||||
from sqlalchemy import PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import mapped_column
|
||||
|
||||
|
||||
class CustomsSection(Base):
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from .models import CustomsSection
|
||||
from .dto import CustomsSectionDTO
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import CustomsSectionDTO
|
||||
from .models import CustomsSection
|
||||
|
||||
router = APIRouter(prefix="/customs-sections")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.customs_sections.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class CustomsWarehouseDTO(BaseModel):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from sqlalchemy import String, PrimaryKeyConstraint
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from core.database import Base
|
||||
from sqlalchemy import PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
|
||||
class CustomsWarehouse(Base):
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from .models import CustomsWarehouse
|
||||
from .dto import CustomsWarehouseDTO
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import CustomsWarehouseDTO
|
||||
from .models import CustomsWarehouse
|
||||
|
||||
router = APIRouter(prefix="/customs-warehouses")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.customs_warehouses.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class IncotermDTO(BaseModel):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from sqlalchemy import String, PrimaryKeyConstraint
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from core.database import Base
|
||||
from sqlalchemy import PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
|
||||
class Incoterm(Base):
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from .models import Incoterm
|
||||
from .dto import IncotermDTO
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import IncotermDTO
|
||||
from .models import Incoterm
|
||||
|
||||
router = APIRouter(prefix="/incoterms")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.incoterms.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import ConfigDict
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class InvoiceTypeDTO(BaseModel):
|
||||
key: str = Field(..., min_length=1, max_length=5)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from sqlalchemy import String, PrimaryKeyConstraint
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from core.database import Base
|
||||
from sqlalchemy import PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
|
||||
class InvoiceType(Base):
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from .models import InvoiceType
|
||||
from .dto import InvoiceTypeDTO
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import InvoiceTypeDTO
|
||||
from .models import InvoiceType
|
||||
|
||||
router = APIRouter(prefix="/invoice-types")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.invoice_types.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class MaterialTypeDTO(BaseModel):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from sqlalchemy import String, PrimaryKeyConstraint
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from core.database import Base
|
||||
from sqlalchemy import PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
|
||||
class MaterialType(Base):
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from .models import MaterialType
|
||||
from .dto import MaterialTypeDTO
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import MaterialTypeDTO
|
||||
from .models import MaterialType
|
||||
|
||||
router = APIRouter(prefix="/material-types")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.material_types.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class PaymentMethodDTO(BaseModel):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from sqlalchemy import String, PrimaryKeyConstraint
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from core.database import Base
|
||||
from sqlalchemy import PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
|
||||
class PaymentMethod(Base):
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from .models import PaymentMethod
|
||||
from .dto import PaymentMethodDTO
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import PaymentMethodDTO
|
||||
from .models import PaymentMethod
|
||||
|
||||
router = APIRouter(prefix="/payment-methods")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.payment_methods.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import ConfigDict
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class PedimentoCodeDTO(BaseModel):
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from typing import TYPE_CHECKING, List
|
||||
from sqlalchemy import String, PrimaryKeyConstraint
|
||||
from sqlalchemy.orm import mapped_column, Mapped, relationship
|
||||
|
||||
from core.database import Base
|
||||
from sqlalchemy import PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..code_pedimento_regimens.models import CodePedimentoRegimen
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from .models import PedimentoCode
|
||||
from .dto import PedimentoCodeDTO
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import PedimentoCodeDTO
|
||||
from .models import PedimentoCode
|
||||
|
||||
router = APIRouter(prefix="/pedimento-codes")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.pedimento_codes.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import ConfigDict
|
||||
from typing import List
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class RegimenPedimentoDTO(BaseModel):
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from typing import TYPE_CHECKING, List
|
||||
from sqlalchemy import String, PrimaryKeyConstraint, ForeignKey
|
||||
from sqlalchemy.orm import mapped_column, Mapped, relationship
|
||||
|
||||
from core.database import Base
|
||||
from sqlalchemy import PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..code_pedimento_regimens.models import CodePedimentoRegimen
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from .models import RegimenPedimento
|
||||
from .dto import RegimenPedimentoDTO
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import RegimenPedimentoDTO
|
||||
from .models import RegimenPedimento
|
||||
|
||||
router = APIRouter(prefix="/pedimento-regimens")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.pedimento_regimens.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
@@ -5,24 +5,24 @@ Agrega todos los módulos de la aplicación
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from .pedimento_codes.routes import router as pedimento_codes_router
|
||||
from .payment_methods.routes import router as payment_methods_router
|
||||
from .code_pedimento_regimens.routes import router as code_pedimento_regimens_router
|
||||
from .containers.routes import router as containers_router
|
||||
from .countries.routes import router as countries_router
|
||||
from .material_types.routes import router as material_types_router
|
||||
from .currency_types.routes import router as currency_types_router
|
||||
from .states.routes import router as states_router
|
||||
from .transport_types.routes import router as transport_types_router
|
||||
from .customs_warehouses.routes import router as customs_warehouses_router
|
||||
from .valuation_methods.routes import router as valuation_methods_router
|
||||
from .sectors.routes import router as sectors_router
|
||||
from .transport_modes.routes import router as transport_modes_router
|
||||
from .customs_sections.routes import router as customs_sections_router
|
||||
from .invoice_types.routes import router as invoice_types_router
|
||||
from .code_pedimento_regimens.routes import router as code_pedimento_regimens_router
|
||||
from .pedimento_regimens.routes import router as pedimento_regimens_router
|
||||
from .customs_warehouses.routes import router as customs_warehouses_router
|
||||
from .incoterms.routes import router as incoterms_router
|
||||
from .invoice_types.routes import router as invoice_types_router
|
||||
from .material_types.routes import router as material_types_router
|
||||
from .payment_methods.routes import router as payment_methods_router
|
||||
from .pedimento_codes.routes import router as pedimento_codes_router
|
||||
from .pedimento_regimens.routes import router as pedimento_regimens_router
|
||||
from .sectors.routes import router as sectors_router
|
||||
from .states.routes import router as states_router
|
||||
from .trailer_types.routes import router as trailer_types_router
|
||||
from .transport_modes.routes import router as transport_modes_router
|
||||
from .transport_types.routes import router as transport_types_router
|
||||
from .valuation_methods.routes import router as valuation_methods_router
|
||||
|
||||
# Router principal
|
||||
router = APIRouter()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class SectorDTO(BaseModel):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from sqlalchemy import String, SmallInteger, PrimaryKeyConstraint
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from core.database import Base
|
||||
from sqlalchemy import PrimaryKeyConstraint, SmallInteger, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
|
||||
class Sector(Base):
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from .models import Sector
|
||||
from .dto import SectorDTO
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import SectorDTO
|
||||
from .models import Sector
|
||||
|
||||
router = APIRouter(prefix="/sectors")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.sectors.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import ConfigDict
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class StateDTO(BaseModel):
|
||||
m3_key: str = Field(..., min_length=1, max_length=3)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from typing import Optional
|
||||
from sqlalchemy import String, PrimaryKeyConstraint
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
|
||||
from core.database import Base
|
||||
from sqlalchemy import PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
|
||||
class State(Base):
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from .models import State
|
||||
from .dto import StateDTO
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import StateDTO
|
||||
from .models import State
|
||||
|
||||
router = APIRouter(prefix="/states")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.states.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class TrailerTypeBaseDTO(BaseModel):
|
||||
trailer_type_key: str
|
||||
description: Optional[str]
|
||||
company_id: str
|
||||
tenant_id: str
|
||||
|
||||
|
||||
class TrailerTypeCreateDTO(TrailerTypeBaseDTO):
|
||||
pass
|
||||
|
||||
|
||||
class TrailerTypeResponseDTO(TrailerTypeBaseDTO):
|
||||
class Config:
|
||||
from_attributes = True
|
||||
from_attributes = True
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey
|
||||
from api.v1.common.base_models import TenantScopedMixin
|
||||
from core.database import Base
|
||||
from sqlalchemy import Column, ForeignKeyConstraint, String
|
||||
|
||||
class TrailerType(Base):
|
||||
|
||||
class TrailerType(Base, TenantScopedMixin):
|
||||
__tablename__ = "trailer_type"
|
||||
__table_args__ = {"schema": "a76"}
|
||||
__table_args__ = (
|
||||
ForeignKeyConstraint(["company_id"], ["a76.company.id"]),
|
||||
ForeignKeyConstraint(["tenant_id"], ["a76.tenants.id"]),
|
||||
{"schema": "a76"},
|
||||
)
|
||||
|
||||
trailer_type_key = Column(String(2), primary_key=True, nullable=False)
|
||||
description = Column(String(100), nullable=True)
|
||||
company_id = Column(Integer, ForeignKey("a76.company.id"), nullable=False)
|
||||
tenant_id = Column(Integer, ForeignKey("a76.tenants.id"), nullable=False)
|
||||
@@ -1,24 +1,36 @@
|
||||
from core.database import get_core_db
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
from . import services, dto
|
||||
from core.database import get_core_db
|
||||
|
||||
from . import dto, services
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/trailer-types/{trailer_type_key}", response_model=dto.TrailerTypeResponseDTO)
|
||||
|
||||
@router.get(
|
||||
"/trailer-types/{trailer_type_key}", response_model=dto.TrailerTypeResponseDTO
|
||||
)
|
||||
def get_trailer_type(trailer_type_key: str, db: Session = Depends(get_core_db)):
|
||||
trailer_type = services.TrailerTypeService.get_trailer_type_by_key(db, trailer_type_key)
|
||||
trailer_type = services.TrailerTypeService.get_trailer_type_by_key(
|
||||
db, trailer_type_key
|
||||
)
|
||||
if not trailer_type:
|
||||
raise HTTPException(status_code=404, detail="Trailer type not found")
|
||||
return trailer_type
|
||||
|
||||
|
||||
@router.post("/trailer-types", response_model=dto.TrailerTypeResponseDTO)
|
||||
def create_trailer_type(trailer_type_data: dto.TrailerTypeCreateDTO, db: Session = Depends(get_core_db)):
|
||||
def create_trailer_type(
|
||||
trailer_type_data: dto.TrailerTypeCreateDTO, db: Session = Depends(get_core_db)
|
||||
):
|
||||
return services.TrailerTypeService.create_trailer_type(db, trailer_type_data)
|
||||
|
||||
@router.delete("/trailer-types/{trailer_type_key}", response_model=dto.TrailerTypeResponseDTO)
|
||||
|
||||
@router.delete(
|
||||
"/trailer-types/{trailer_type_key}", response_model=dto.TrailerTypeResponseDTO
|
||||
)
|
||||
def delete_trailer_type(trailer_type_key: str, db: Session = Depends(get_core_db)):
|
||||
trailer_type = services.TrailerTypeService.delete_trailer_type(db, trailer_type_key)
|
||||
if not trailer_type:
|
||||
raise HTTPException(status_code=404, detail="Trailer type not found")
|
||||
return trailer_type
|
||||
return trailer_type
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from . import models, dto
|
||||
|
||||
from . import dto, models
|
||||
|
||||
|
||||
class TrailerTypeService:
|
||||
@staticmethod
|
||||
def get_trailer_type_by_key(db: Session, trailer_type_key: str):
|
||||
return db.query(models.TrailerType).filter(models.TrailerType.trailer_type_key == trailer_type_key).first()
|
||||
return (
|
||||
db.query(models.TrailerType)
|
||||
.filter(models.TrailerType.trailer_type_key == trailer_type_key)
|
||||
.first()
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def create_trailer_type(db: Session, trailer_type_data: dto.TrailerTypeCreateDTO):
|
||||
@@ -20,4 +26,4 @@ class TrailerTypeService:
|
||||
if trailer_type:
|
||||
db.delete(trailer_type)
|
||||
db.commit()
|
||||
return trailer_type
|
||||
return trailer_type
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class TransportModeDTO(BaseModel):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from sqlalchemy import String, PrimaryKeyConstraint
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from core.database import Base
|
||||
from sqlalchemy import PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
|
||||
class TransportMode(Base):
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_core_db
|
||||
from core.security import has_role, get_current_user
|
||||
from .models import TransportMode
|
||||
from .dto import TransportModeDTO
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import TransportModeDTO
|
||||
from .models import TransportMode
|
||||
|
||||
router = APIRouter(prefix="/transport-modes")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.transport_modes.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class TransportTypeDTO(BaseModel):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from sqlalchemy import String, PrimaryKeyConstraint
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from core.database import Base
|
||||
from sqlalchemy import PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
|
||||
class TransportType(Base):
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_core_db
|
||||
from core.security import has_role, get_current_user
|
||||
from .models import TransportType
|
||||
from .dto import TransportTypeDTO
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import TransportTypeDTO
|
||||
from .models import TransportType
|
||||
|
||||
router = APIRouter(prefix="/transport-types")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.transport_types.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class ValuationMethodDTO(BaseModel):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from sqlalchemy import String, PrimaryKeyConstraint
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from core.database import Base
|
||||
from sqlalchemy import PrimaryKeyConstraint, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
|
||||
class ValuationMethod(Base):
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from .models import ValuationMethod
|
||||
from .dto import ValuationMethodDTO
|
||||
from typing import Any, Dict
|
||||
|
||||
from core.database import get_core_db
|
||||
from core.security import get_current_user, has_role
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .dto import ValuationMethodDTO
|
||||
from .models import ValuationMethod
|
||||
|
||||
router = APIRouter(prefix="/valuation-methods")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from api.v1.modules.public.reference_data.valuation_methods.routes import router
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
||||
Reference in New Issue
Block a user