wrongmove/services/decision_service.py
Viktor Barzin 49280d9679
fix: QA fixes for property decisions feature
- Replace deprecated datetime.utcnow() with datetime.now(UTC) in model
  and repository
- Add listing_type validation to decision_service (RENT/BUY only)
- Fix decision filtering tests failing due to rate limiting by patching
  _match_endpoint
- Add SwipeCard component test suite (11 tests covering rendering,
  interactions, and POI distances)
- Add test for invalid listing_type validation
2026-02-21 14:04:34 +00:00

59 lines
1.5 KiB
Python

"""Unified decision service -- shared between CLI and HTTP API."""
from models.decision import ListingDecision
from repositories.decision_repository import DecisionRepository
VALID_DECISIONS = {"liked", "disliked"}
VALID_LISTING_TYPES = {"RENT", "BUY"}
def set_decision(
repository: DecisionRepository,
user_id: int,
listing_id: int,
listing_type: str,
decision: str,
) -> ListingDecision:
if decision not in VALID_DECISIONS:
raise ValueError(
f"Invalid decision '{decision}'. Must be one of: {VALID_DECISIONS}"
)
if listing_type not in VALID_LISTING_TYPES:
raise ValueError(
f"Invalid listing_type '{listing_type}'. Must be one of: {VALID_LISTING_TYPES}"
)
return repository.upsert_decision(
user_id=user_id,
listing_id=listing_id,
listing_type=listing_type,
decision=decision,
)
def get_decisions(
repository: DecisionRepository,
user_id: int,
) -> list[ListingDecision]:
return repository.get_decisions_for_user(user_id)
def clear_decision(
repository: DecisionRepository,
user_id: int,
listing_id: int,
listing_type: str,
) -> bool:
return repository.delete_decision(
user_id=user_id,
listing_id=listing_id,
listing_type=listing_type,
)
def get_disliked_listing_ids(
repository: DecisionRepository,
user_id: int,
listing_type: str,
) -> set[int]:
return repository.get_disliked_listing_ids(
user_id=user_id, listing_type=listing_type
)