endpoint setup
This commit is contained in:
83
app/db/models/insurance_details.py
Normal file
83
app/db/models/insurance_details.py
Normal file
@@ -0,0 +1,83 @@
|
||||
from datetime import date
|
||||
from sqlalchemy import (
|
||||
String,
|
||||
Integer,
|
||||
Boolean,
|
||||
Date,
|
||||
ForeignKey,
|
||||
Text
|
||||
)
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from app.db.models.base import Base
|
||||
|
||||
|
||||
class InsuranceDetails(Base):
|
||||
|
||||
__tablename__ = "insurance_details"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
|
||||
# 🔗 Relation with Property
|
||||
property_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("properties.id", ondelete="CASCADE"),
|
||||
index=True
|
||||
)
|
||||
|
||||
# -----------------------------
|
||||
# REQUIRED FIELDS (Your spec)
|
||||
# -----------------------------
|
||||
|
||||
insurance_company: Mapped[str] = mapped_column(String(150))
|
||||
|
||||
claim_number: Mapped[str] = mapped_column(String(100), unique=True)
|
||||
|
||||
date_of_loss: Mapped[date] = mapped_column(Date)
|
||||
|
||||
adjuster_name: Mapped[str] = mapped_column(String(150), nullable=True)
|
||||
adjuster_phone: Mapped[str] = mapped_column(String(30), nullable=True)
|
||||
adjuster_email: Mapped[str] = mapped_column(String(150), nullable=True)
|
||||
|
||||
claim_filed: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
claim_approved: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
|
||||
# -----------------------------
|
||||
# 🇺🇸 US Insurance Standard Fields
|
||||
# -----------------------------
|
||||
|
||||
policy_number: Mapped[str] = mapped_column(String(100), nullable=True)
|
||||
|
||||
coverage_type: Mapped[str] = mapped_column(
|
||||
String(50), nullable=True
|
||||
)
|
||||
# e.g. Homeowners, Flood, Fire, Liability, Windstorm
|
||||
|
||||
claim_type: Mapped[str] = mapped_column(
|
||||
String(50), nullable=True
|
||||
)
|
||||
# e.g. Roof Damage, Water Damage, Fire, Storm, Theft
|
||||
|
||||
deductible_amount: Mapped[int] = mapped_column(nullable=True)
|
||||
|
||||
claim_amount: Mapped[int] = mapped_column(nullable=True)
|
||||
|
||||
approved_amount: Mapped[int] = mapped_column(nullable=True)
|
||||
|
||||
payment_status: Mapped[str] = mapped_column(
|
||||
String(50), nullable=True
|
||||
)
|
||||
# Pending / Paid / Denied / Under Review
|
||||
|
||||
date_claim_filed: Mapped[date] = mapped_column(Date, nullable=True)
|
||||
|
||||
date_claim_closed: Mapped[date] = mapped_column(Date, nullable=True)
|
||||
|
||||
insurance_agent_name: Mapped[str] = mapped_column(String(150), nullable=True)
|
||||
insurance_agent_phone: Mapped[str] = mapped_column(String(30), nullable=True)
|
||||
|
||||
notes: Mapped[str] = mapped_column(Text, nullable=True)
|
||||
|
||||
# -----------------------------
|
||||
# Relationship
|
||||
# -----------------------------
|
||||
|
||||
property = relationship("Property", back_populates="insurance_records")
|
||||
@@ -1,4 +1,5 @@
|
||||
from sqlalchemy import String, Integer, Float, BigInteger
|
||||
from geoalchemy2 import Geography
|
||||
from sqlalchemy import String, Integer, Float, BigInteger, UniqueConstraint
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from app.db.models.base import Base
|
||||
@@ -7,6 +8,9 @@ from app.db.models.base import Base
|
||||
class Location(Base):
|
||||
|
||||
__tablename__ = "locations"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("osm_type", "osm_id", name="uq_osm_location"),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
||||
|
||||
@@ -38,6 +42,10 @@ class Location(Base):
|
||||
bbox_lon_min: Mapped[float] = mapped_column(Float)
|
||||
bbox_lon_max: Mapped[float] = mapped_column(Float)
|
||||
|
||||
geom: Mapped[str] = mapped_column(
|
||||
Geography("POINT", srid=4326)
|
||||
)
|
||||
|
||||
property = relationship(
|
||||
"Property",
|
||||
back_populates="location",
|
||||
|
||||
@@ -63,3 +63,9 @@ class Property(Base):
|
||||
back_populates="property",
|
||||
uselist=False,
|
||||
)
|
||||
|
||||
insurance_records = relationship(
|
||||
"InsuranceDetails",
|
||||
back_populates="property",
|
||||
cascade="all, delete-orphan"
|
||||
)
|
||||
Reference in New Issue
Block a user