
- Create User model and database schema - Add JWT authentication with secure password hashing - Create authentication endpoints for registration and login - Update invoice routes to require authentication - Ensure users can only access their own invoices - Update documentation in README.md
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
import datetime
|
|
|
|
from sqlalchemy import (
|
|
Column,
|
|
String,
|
|
Integer,
|
|
Float,
|
|
DateTime,
|
|
ForeignKey,
|
|
Text,
|
|
)
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class Invoice(Base):
|
|
__tablename__ = "invoices"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
invoice_number = Column(String(255), unique=True, index=True, nullable=False)
|
|
date_created = Column(DateTime, default=datetime.datetime.utcnow, nullable=False)
|
|
due_date = Column(DateTime, nullable=False)
|
|
customer_name = Column(String(255), nullable=False)
|
|
customer_email = Column(String(255), nullable=True)
|
|
customer_address = Column(Text, nullable=True)
|
|
total_amount = Column(Float, nullable=False)
|
|
status = Column(String(50), default="PENDING", nullable=False)
|
|
notes = Column(Text, nullable=True)
|
|
|
|
# Foreign key to user
|
|
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
|
|
# Relationship with invoice items
|
|
items = relationship("InvoiceItem", back_populates="invoice", cascade="all, delete-orphan")
|
|
|
|
# Relationship with user
|
|
user = relationship("User", back_populates="invoices")
|
|
|
|
|
|
class InvoiceItem(Base):
|
|
__tablename__ = "invoice_items"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
invoice_id = Column(Integer, ForeignKey("invoices.id"), nullable=False)
|
|
description = Column(String(255), nullable=False)
|
|
quantity = Column(Float, nullable=False)
|
|
unit_price = Column(Float, nullable=False)
|
|
amount = Column(Float, nullable=False)
|
|
|
|
# Relationship with invoice
|
|
invoice = relationship("Invoice", back_populates="items") |