mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 12:11:13 -05:00
Refactor code structure and remove redundant changes
This commit is contained in:
@@ -10,7 +10,7 @@ from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import AbstractBaseUser
|
||||
|
||||
from .models import Park, ParkArea
|
||||
from apps.location.models import Location
|
||||
from .services.location_service import ParkLocationService
|
||||
|
||||
# Use AbstractBaseUser for type hinting
|
||||
UserType = AbstractBaseUser
|
||||
@@ -89,7 +89,7 @@ class ParkService:
|
||||
|
||||
# Handle location if provided
|
||||
if location_data:
|
||||
LocationService.create_park_location(park=park, **location_data)
|
||||
ParkLocationService.create_park_location(park=park, **location_data)
|
||||
|
||||
return park
|
||||
|
||||
@@ -227,97 +227,3 @@ class ParkService:
|
||||
park.save()
|
||||
|
||||
return park
|
||||
|
||||
|
||||
class LocationService:
|
||||
"""Service for managing location operations."""
|
||||
|
||||
@staticmethod
|
||||
def create_park_location(
|
||||
*,
|
||||
park: Park,
|
||||
latitude: Optional[float] = None,
|
||||
longitude: Optional[float] = None,
|
||||
street_address: str = "",
|
||||
city: str = "",
|
||||
state: str = "",
|
||||
country: str = "",
|
||||
postal_code: str = "",
|
||||
) -> Location:
|
||||
"""
|
||||
Create a location for a park.
|
||||
|
||||
Args:
|
||||
park: Park instance
|
||||
latitude: Latitude coordinate
|
||||
longitude: Longitude coordinate
|
||||
street_address: Street address
|
||||
city: City name
|
||||
state: State/region name
|
||||
country: Country name
|
||||
postal_code: Postal/ZIP code
|
||||
|
||||
Returns:
|
||||
Created Location instance
|
||||
|
||||
Raises:
|
||||
ValidationError: If location data is invalid
|
||||
"""
|
||||
location = Location(
|
||||
content_object=park,
|
||||
name=park.name,
|
||||
location_type="park",
|
||||
latitude=latitude,
|
||||
longitude=longitude,
|
||||
street_address=street_address,
|
||||
city=city,
|
||||
state=state,
|
||||
country=country,
|
||||
postal_code=postal_code,
|
||||
)
|
||||
|
||||
# CRITICAL STYLEGUIDE FIX: Call full_clean before save
|
||||
location.full_clean()
|
||||
location.save()
|
||||
|
||||
return location
|
||||
|
||||
@staticmethod
|
||||
def update_park_location(
|
||||
*, park_id: int, location_updates: Dict[str, Any]
|
||||
) -> Location:
|
||||
"""
|
||||
Update location information for a park.
|
||||
|
||||
Args:
|
||||
park_id: ID of the park
|
||||
location_updates: Dictionary of location field updates
|
||||
|
||||
Returns:
|
||||
Updated Location instance
|
||||
|
||||
Raises:
|
||||
Location.DoesNotExist: If location doesn't exist
|
||||
ValidationError: If location data is invalid
|
||||
"""
|
||||
with transaction.atomic():
|
||||
park = Park.objects.get(id=park_id)
|
||||
|
||||
try:
|
||||
location = park.location
|
||||
except Location.DoesNotExist:
|
||||
# Create location if it doesn't exist
|
||||
return LocationService.create_park_location(
|
||||
park=park, **location_updates
|
||||
)
|
||||
|
||||
# Apply updates
|
||||
for field, value in location_updates.items():
|
||||
if hasattr(location, field):
|
||||
setattr(location, field, value)
|
||||
|
||||
# CRITICAL STYLEGUIDE FIX: Call full_clean before save
|
||||
location.full_clean()
|
||||
location.save()
|
||||
|
||||
return location
|
||||
|
||||
Reference in New Issue
Block a user