[update]: Select Offer

This commit is contained in:
Vivian Dee
2025-04-23 18:35:47 +01:00
parent 5768b537b1
commit 8cfa957cc0
2 changed files with 82 additions and 12 deletions
+22
View File
@@ -40,6 +40,28 @@ class Offer(db.Model):
if not offer:
return False
return offer
@classmethod
def get_offer_by_id(cls, offer_id):
"""
Return an offer by its ID.
"""
offer = cls.query.filter_by(id=str(offer_id)).first()
if not offer:
raise ValueError(f"Offer with ID {offer_id} not found")
return offer
@classmethod
def get_offer_by_product_id(cls, product_id):
"""
Return an offer by its product ID.
"""
offer = cls.query.filter_by(product_id=str(product_id)).first()
if not offer:
raise ValueError(f"Offer with Product ID {product_id} not found")
return offer
def to_dict(self):
return {