Files
live-campus-mcs-p-2027.2/Semaine_07/Jour_04/bank/entities/clients.py
gauvainboiche 606e43e53f Semaine 7
2026-03-20 21:26:23 +01:00

43 lines
1.6 KiB
Python

from accounts import Account
from services import client_service
from sqlalchemy import ForeignKey, Column, Integer, String, Float
from sqlalchemy.orm import relationship
from database import Base, engine
class Client(Base):
__tablename__ = "clients"
id = Column(Integer, primary_key= True, autoincrement= True)
first_name = Column(String(200), nullable= False)
last_name = Column(String(200), nullable= False)
city = Column(String(200))
salary = Column(Float)
bank_id = Column(Integer, ForeignKey("banks.id"), nullable= False)
bank = relationship("Bank", back_populates= "clients")
account = relationship("Account", back_populates= "clients", uselist= False) # type: ignore
services = relationship("Services", back_populates= "clients", secondary= client_service)
def __init__(self, first_name: str, last_name: str, salary: float, city: str, initial_deposit: int | float = 0) -> None:
self.first_name = first_name
self.last_name = last_name
self.salary = salary
self.city = city
self.account: Account = Account(initial_deposit = initial_deposit)
def __eq__(self, other: "Client") -> bool:
return self.first_name == other.first_name and\
self.last_name == other.last_name and\
self.account == other.account # type: ignore
def __repr__(self) -> str:
return f"Client({self.first_name} {self.last_name})"
class ClientNotFound(Exception):
def __init__(self, *args: object) -> None:
super().__init__("Client not found")
Base.metadata.create_all(engine)