feat: Semaine 8
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
from data.database import get_database_connection
|
||||
from data.repositories.protocols.customer_repository_protocol import CustomerRepositoryProtocol
|
||||
from domain.entities.customer import Customer
|
||||
from domain.services.order_service import OrderService
|
||||
|
||||
class CustomerRepository(CustomerRepositoryProtocol):
|
||||
def __init__(self) -> None:
|
||||
self.db = get_database_connection()
|
||||
|
||||
def find_by_id(self, customer_id: int):
|
||||
row = self.db.execute(
|
||||
"""
|
||||
SELECT c.id, c.name, c.email, c.address
|
||||
FROM customers c
|
||||
LEFT JOIN orders o
|
||||
ON o.customer_id = c.id
|
||||
WHERE c.id = :id
|
||||
GROUP BY c.id
|
||||
""",
|
||||
{"id": customer_id}
|
||||
).fetchone()
|
||||
|
||||
if row is None: return None
|
||||
|
||||
return Customer(
|
||||
id= row['id'],
|
||||
name= row['name'],
|
||||
email= row['email'],
|
||||
address= row['address'],
|
||||
order_count= row['order_count'],
|
||||
is_premium= row['order_count'] >= OrderService.PREMIUM_THRESHOLD,
|
||||
)
|
||||
Reference in New Issue
Block a user