90 lines
3.6 KiB
Python
90 lines
3.6 KiB
Python
import uuid
|
|
# Hozzáadva: Boolean, text, func
|
|
from sqlalchemy import Column, String, Integer, ForeignKey, Text, DateTime, Float, Boolean, text, func
|
|
# PostgreSQL specifikus típusok
|
|
from sqlalchemy.dialects.postgresql import UUID as PG_UUID, JSONB
|
|
from sqlalchemy.orm import relationship
|
|
from app.db.base_class import Base
|
|
|
|
class GeoPostalCode(Base):
|
|
__tablename__ = "geo_postal_codes"
|
|
__table_args__ = {"schema": "data"}
|
|
id = Column(Integer, primary_key=True)
|
|
country_code = Column(String(5), default="HU")
|
|
zip_code = Column(String(10), nullable=False)
|
|
city = Column(String(100), nullable=False)
|
|
|
|
class GeoStreet(Base):
|
|
__tablename__ = "geo_streets"
|
|
__table_args__ = {"schema": "data"}
|
|
id = Column(Integer, primary_key=True)
|
|
postal_code_id = Column(Integer, ForeignKey("data.geo_postal_codes.id"))
|
|
name = Column(String(200), nullable=False)
|
|
|
|
class GeoStreetType(Base):
|
|
__tablename__ = "geo_street_types"
|
|
__table_args__ = {"schema": "data"}
|
|
id = Column(Integer, primary_key=True)
|
|
name = Column(String(50), unique=True, nullable=False)
|
|
|
|
class Address(Base):
|
|
"""Univerzális cím entitás GPS adatokkal kiegészítve."""
|
|
__tablename__ = "addresses"
|
|
__table_args__ = {"schema": "data"}
|
|
|
|
id = Column(PG_UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
postal_code_id = Column(Integer, ForeignKey("data.geo_postal_codes.id"))
|
|
street_name = Column(String(200), nullable=False)
|
|
street_type = Column(String(50), nullable=False)
|
|
house_number = Column(String(50), nullable=False)
|
|
stairwell = Column(String(20))
|
|
floor = Column(String(20))
|
|
door = Column(String(20))
|
|
parcel_id = Column(String(50))
|
|
full_address_text = Column(Text)
|
|
|
|
# Robot és térképes funkciók számára
|
|
latitude = Column(Float)
|
|
longitude = Column(Float)
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
# Add to /app/models/address.py
|
|
class Branch(Base):
|
|
"""
|
|
Telephely entitás. A fizikai helyszín, ahol a szolgáltatás vagy flotta-kezelés zajlik.
|
|
Minden cégnek van legalább egy 'Main' telephelye.
|
|
"""
|
|
__tablename__ = "branches"
|
|
__table_args__ = {"schema": "data"}
|
|
|
|
id = Column(PG_UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
organization_id = Column(Integer, ForeignKey("data.organizations.id"), nullable=False)
|
|
address_id = Column(PG_UUID(as_uuid=True), ForeignKey("data.addresses.id"), nullable=True)
|
|
|
|
name = Column(String(100), nullable=False) # pl. "Központi iroda", "Dunakeszi Szerviz"
|
|
is_main = Column(Boolean, default=False)
|
|
|
|
# Részletes címadatok (Denormalizált a gyors kereséshez)
|
|
postal_code = Column(String(10), index=True)
|
|
city = Column(String(100), index=True)
|
|
street_name = Column(String(150))
|
|
street_type = Column(String(50))
|
|
house_number = Column(String(20))
|
|
stairwell = Column(String(20))
|
|
floor = Column(String(20))
|
|
door = Column(String(20))
|
|
hrsz = Column(String(50)) # Helyrajzi szám
|
|
|
|
# Telephely specifikus adatok
|
|
opening_hours = Column(JSONB, server_default=text("'{}'::jsonb"))
|
|
branch_rating = Column(Float, default=0.0)
|
|
|
|
status = Column(String(30), default="active")
|
|
is_deleted = Column(Boolean, default=False)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
organization = relationship("Organization", back_populates="branches")
|
|
address = relationship("Address")
|
|
# Kapcsolat a szerviz értékelésekkel
|
|
reviews = relationship("Rating", primaryjoin="and_(Branch.id==foreign(Rating.target_id), Rating.target_type=='branch')") |