Updated claude big changes
This commit is contained in:
@@ -17,7 +17,13 @@ url = URL.create(
|
|||||||
port=ApplicationConfig.POSTGRES_PORT
|
port=ApplicationConfig.POSTGRES_PORT
|
||||||
)
|
)
|
||||||
|
|
||||||
engine = create_engine(url)
|
engine = create_engine(
|
||||||
|
url,
|
||||||
|
pool_pre_ping=True, # Verify connections before use
|
||||||
|
pool_size=5, # Maintain 5 connections in pool
|
||||||
|
max_overflow=10, # Allow 10 additional connections when busy
|
||||||
|
pool_recycle=3600, # Recycle connections after 1 hour
|
||||||
|
)
|
||||||
|
|
||||||
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||||
session = Session()
|
session = Session()
|
||||||
|
|||||||
20
app/main.py
20
app/main.py
@@ -1,6 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
from fastapi import FastAPI
|
import uuid
|
||||||
|
from fastapi import FastAPI, Request
|
||||||
from .database import engine
|
from .database import engine
|
||||||
from . import models
|
from . import models
|
||||||
from .routers import payment
|
from .routers import payment
|
||||||
@@ -8,6 +9,7 @@ from .routers.transaction import transaction_router
|
|||||||
from .routers.auto import auto_router
|
from .routers.auto import auto_router
|
||||||
from .routers.user_check import user_check_router
|
from .routers.user_check import user_check_router
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
from starlette.middleware.base import BaseHTTPMiddleware
|
||||||
from config import load_config
|
from config import load_config
|
||||||
from authorizenet import apicontractsv1
|
from authorizenet import apicontractsv1
|
||||||
from authorizenet.apicontrollers import getCustomerProfileIdsController
|
from authorizenet.apicontrollers import getCustomerProfileIdsController
|
||||||
@@ -48,13 +50,23 @@ models.Base.metadata.create_all(bind=engine)
|
|||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
# print(ApplicationConfig.origins)
|
# Request ID middleware for request tracking/correlation
|
||||||
|
class RequestIDMiddleware(BaseHTTPMiddleware):
|
||||||
|
async def dispatch(self, request: Request, call_next):
|
||||||
|
request_id = request.headers.get("X-Request-ID") or str(uuid.uuid4())[:8]
|
||||||
|
request.state.request_id = request_id
|
||||||
|
response = await call_next(request)
|
||||||
|
response.headers["X-Request-ID"] = request_id
|
||||||
|
return response
|
||||||
|
|
||||||
|
app.add_middleware(RequestIDMiddleware)
|
||||||
|
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=ApplicationConfig.origins,
|
allow_origins=ApplicationConfig.origins,
|
||||||
allow_credentials=True,
|
allow_credentials=True,
|
||||||
allow_methods=["*"],
|
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
||||||
allow_headers=["*"],
|
allow_headers=["Authorization", "Content-Type", "Accept", "Origin", "X-Requested-With", "X-Request-ID"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,41 @@
|
|||||||
## File: app/schemas.py (or your equivalent path)
|
## File: app/schemas.py (or your equivalent path)
|
||||||
|
|
||||||
from pydantic import BaseModel, ConfigDict # --- MODIFICATION: Import ConfigDict
|
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
import re
|
||||||
|
|
||||||
# --- NEW SCHEMAS FOR CIM WORKFLOW (Now with correct Pydantic V2 config) ---
|
# --- NEW SCHEMAS FOR CIM WORKFLOW (Now with correct Pydantic V2 config) ---
|
||||||
|
|
||||||
class CardCreate(BaseModel):
|
class CardCreate(BaseModel):
|
||||||
card_number: str
|
card_number: str = Field(..., min_length=13, max_length=19, description="Credit card number (13-19 digits)")
|
||||||
expiration_date: str # Format: "YYYY-MM"
|
expiration_date: str = Field(..., description="Expiration date in YYYY-MM format")
|
||||||
cvv: str
|
cvv: str = Field(..., min_length=3, max_length=4, description="Card security code (3-4 digits)")
|
||||||
main_card: bool = False
|
main_card: bool = False
|
||||||
|
|
||||||
|
@field_validator('card_number')
|
||||||
|
@classmethod
|
||||||
|
def validate_card_number(cls, v):
|
||||||
|
digits_only = re.sub(r'\D', '', v)
|
||||||
|
if len(digits_only) < 13 or len(digits_only) > 19:
|
||||||
|
raise ValueError('Card number must be 13-19 digits')
|
||||||
|
return digits_only
|
||||||
|
|
||||||
|
@field_validator('expiration_date')
|
||||||
|
@classmethod
|
||||||
|
def validate_expiration_date(cls, v):
|
||||||
|
if not re.match(r'^\d{4}-\d{2}$', v):
|
||||||
|
raise ValueError('Expiration date must be in YYYY-MM format')
|
||||||
|
return v
|
||||||
|
|
||||||
|
@field_validator('cvv')
|
||||||
|
@classmethod
|
||||||
|
def validate_cvv(cls, v):
|
||||||
|
if not re.match(r'^\d{3,4}$', v):
|
||||||
|
raise ValueError('CVV must be 3-4 digits')
|
||||||
|
return v
|
||||||
|
|
||||||
class Card(BaseModel):
|
class Card(BaseModel):
|
||||||
id: int
|
id: int
|
||||||
user_id: int
|
user_id: int
|
||||||
@@ -82,18 +105,18 @@ class Transaction(TransactionBase):
|
|||||||
|
|
||||||
class CustomerBase(BaseModel):
|
class CustomerBase(BaseModel):
|
||||||
account_number: Optional[str] = None
|
account_number: Optional[str] = None
|
||||||
customer_last_name: Optional[str] = None
|
customer_last_name: Optional[str] = Field(None, max_length=50, description="Last name (max 50 chars)")
|
||||||
customer_first_name: Optional[str] = None
|
customer_first_name: Optional[str] = Field(None, max_length=50, description="First name (max 50 chars)")
|
||||||
customer_town: Optional[str] = None
|
customer_town: Optional[str] = Field(None, max_length=40, description="City (max 40 chars)")
|
||||||
customer_state: Optional[int] = None
|
customer_state: Optional[int] = None
|
||||||
customer_zip: Optional[str] = None
|
customer_zip: Optional[str] = Field(None, max_length=20, description="ZIP code (max 20 chars)")
|
||||||
customer_first_call: Optional[datetime] = None
|
customer_first_call: Optional[datetime] = None
|
||||||
customer_email: Optional[str] = None
|
customer_email: Optional[str] = Field(None, max_length=255, description="Email (max 255 chars)")
|
||||||
customer_automatic: Optional[int] = None
|
customer_automatic: Optional[int] = None
|
||||||
customer_phone_number: Optional[str] = None
|
customer_phone_number: Optional[str] = None
|
||||||
customer_home_type: Optional[int] = None
|
customer_home_type: Optional[int] = None
|
||||||
customer_apt: Optional[str] = None
|
customer_apt: Optional[str] = None
|
||||||
customer_address: Optional[str] = None
|
customer_address: Optional[str] = Field(None, max_length=60, description="Address (max 60 chars)")
|
||||||
company_id: Optional[int] = None
|
company_id: Optional[int] = None
|
||||||
customer_latitude: Optional[str] = None
|
customer_latitude: Optional[str] = None
|
||||||
customer_longitude: Optional[str] = None
|
customer_longitude: Optional[str] = None
|
||||||
|
|||||||
Reference in New Issue
Block a user