mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-30 03:07:00 -05:00
feat: Implement MFA authentication, add ride statistics model, and update various services, APIs, and tests across the application.
This commit is contained in:
@@ -3,11 +3,12 @@ Services for park-related business logic.
|
||||
Following Django styleguide pattern for business logic encapsulation.
|
||||
"""
|
||||
|
||||
from typing import Optional, Dict, Any
|
||||
from django.db import transaction
|
||||
from django.db.models import Q
|
||||
from typing import Any
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import AbstractBaseUser
|
||||
from django.db import transaction
|
||||
from django.db.models import Q
|
||||
|
||||
from .models import Park, ParkArea
|
||||
from .services.location_service import ParkLocationService
|
||||
@@ -26,15 +27,15 @@ class ParkService:
|
||||
name: str,
|
||||
description: str = "",
|
||||
status: str = "OPERATING",
|
||||
operator_id: Optional[int] = None,
|
||||
property_owner_id: Optional[int] = None,
|
||||
opening_date: Optional[str] = None,
|
||||
closing_date: Optional[str] = None,
|
||||
operator_id: int | None = None,
|
||||
property_owner_id: int | None = None,
|
||||
opening_date: str | None = None,
|
||||
closing_date: str | None = None,
|
||||
operating_season: str = "",
|
||||
size_acres: Optional[float] = None,
|
||||
size_acres: float | None = None,
|
||||
website: str = "",
|
||||
location_data: Optional[Dict[str, Any]] = None,
|
||||
created_by: Optional[UserType] = None,
|
||||
location_data: dict[str, Any] | None = None,
|
||||
created_by: UserType | None = None,
|
||||
) -> Park:
|
||||
"""
|
||||
Create a new park with validation and location handling.
|
||||
@@ -97,8 +98,8 @@ class ParkService:
|
||||
def update_park(
|
||||
*,
|
||||
park_id: int,
|
||||
updates: Dict[str, Any],
|
||||
updated_by: Optional[UserType] = None,
|
||||
updates: dict[str, Any],
|
||||
updated_by: UserType | None = None,
|
||||
) -> Park:
|
||||
"""
|
||||
Update an existing park with validation.
|
||||
@@ -130,7 +131,7 @@ class ParkService:
|
||||
return park
|
||||
|
||||
@staticmethod
|
||||
def delete_park(*, park_id: int, deleted_by: Optional[UserType] = None) -> bool:
|
||||
def delete_park(*, park_id: int, deleted_by: UserType | None = None) -> bool:
|
||||
"""
|
||||
Soft delete a park by setting status to DEMOLISHED.
|
||||
|
||||
@@ -156,7 +157,7 @@ class ParkService:
|
||||
park_id: int,
|
||||
name: str,
|
||||
description: str = "",
|
||||
created_by: Optional[UserType] = None,
|
||||
created_by: UserType | None = None,
|
||||
) -> ParkArea:
|
||||
"""
|
||||
Create a new area within a park.
|
||||
@@ -195,9 +196,11 @@ class ParkService:
|
||||
Returns:
|
||||
Updated Park instance with fresh statistics
|
||||
"""
|
||||
from django.db.models import Avg, Count
|
||||
|
||||
from apps.rides.models import Ride
|
||||
|
||||
from .models import ParkReview
|
||||
from django.db.models import Count, Avg
|
||||
|
||||
with transaction.atomic():
|
||||
park = Park.objects.select_for_update().get(id=park_id)
|
||||
|
||||
Reference in New Issue
Block a user