Automated Action 609e7fb237 Implement retail management and payment API with FastAPI
This API provides endpoints for:
- Product and inventory management
- Customer management
- Order processing
- Payment processing with Stripe integration
- User authentication

generated with BackendIM... (backend.im)
2025-05-12 12:00:19 +00:00

36 lines
1.3 KiB
Python

from typing import Optional
from sqlalchemy.orm import Session
from app.crud.base import CRUDBase
from app.models.customer import Customer
from app.schemas.customer import CustomerCreate, CustomerUpdate
class CRUDCustomer(CRUDBase[Customer, CustomerCreate, CustomerUpdate]):
def get_by_email(self, db: Session, *, email: str) -> Optional[Customer]:
return db.query(Customer).filter(Customer.email == email).first()
def get_by_stripe_id(self, db: Session, *, stripe_customer_id: str) -> Optional[Customer]:
return db.query(Customer).filter(Customer.stripe_customer_id == stripe_customer_id).first()
def create_with_stripe_id(self, db: Session, *, obj_in: CustomerCreate, stripe_customer_id: str) -> Customer:
db_obj = Customer(
first_name=obj_in.first_name,
last_name=obj_in.last_name,
email=obj_in.email,
phone=obj_in.phone,
address=obj_in.address,
city=obj_in.city,
state=obj_in.state,
zip_code=obj_in.zip_code,
country=obj_in.country,
stripe_customer_id=stripe_customer_id
)
db.add(db_obj)
db.commit()
db.refresh(db_obj)
return db_obj
customer = CRUDCustomer(Customer)