mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 03:11:12 -05:00
Refactor code structure and remove redundant changes
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
"""
|
||||
RideModel submission service for ThrillWiki.
|
||||
|
||||
Handles RideModel entity creation and updates through the Sacred Pipeline.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from apps.entities.models import RideModel, Company
|
||||
from apps.entities.services import BaseEntitySubmissionService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RideModelSubmissionService(BaseEntitySubmissionService):
|
||||
"""
|
||||
Service for creating RideModel submissions through the Sacred Pipeline.
|
||||
|
||||
RideModels represent specific ride models from manufacturers.
|
||||
For example: "B&M Inverted Coaster", "Vekoma Boomerang"
|
||||
|
||||
Required fields:
|
||||
- name: Model name (e.g., "Inverted Coaster")
|
||||
- manufacturer: Company instance or company ID (UUID)
|
||||
- model_type: Type of model (coaster_model, flat_ride_model, etc.)
|
||||
|
||||
Example:
|
||||
from apps.entities.services.ride_model_submission import RideModelSubmissionService
|
||||
|
||||
manufacturer = Company.objects.get(name='Bolliger & Mabillard')
|
||||
|
||||
submission, model = RideModelSubmissionService.create_entity_submission(
|
||||
user=request.user,
|
||||
data={
|
||||
'name': 'Inverted Coaster',
|
||||
'manufacturer': manufacturer,
|
||||
'model_type': 'coaster_model',
|
||||
'description': 'Suspended coaster with inversions...',
|
||||
'typical_height': Decimal('120'),
|
||||
'typical_speed': Decimal('55'),
|
||||
},
|
||||
source='api'
|
||||
)
|
||||
"""
|
||||
|
||||
entity_model = RideModel
|
||||
entity_type_name = 'RideModel'
|
||||
required_fields = ['name', 'manufacturer', 'model_type']
|
||||
|
||||
@classmethod
|
||||
def create_entity_submission(cls, user, data, **kwargs):
|
||||
"""
|
||||
Create a RideModel submission with foreign key handling.
|
||||
|
||||
The 'manufacturer' field can be provided as either:
|
||||
- A Company instance
|
||||
- A UUID string (will be converted to Company instance)
|
||||
|
||||
Args:
|
||||
user: User creating the ride model
|
||||
data: RideModel field data (must include name, manufacturer, and model_type)
|
||||
**kwargs: Additional metadata (source, ip_address, user_agent)
|
||||
|
||||
Returns:
|
||||
tuple: (ContentSubmission, RideModel or None)
|
||||
|
||||
Raises:
|
||||
ValidationError: If manufacturer not found or invalid
|
||||
"""
|
||||
# Validate and normalize manufacturer FK
|
||||
manufacturer = data.get('manufacturer')
|
||||
if manufacturer:
|
||||
if isinstance(manufacturer, str):
|
||||
# UUID string - convert to Company instance
|
||||
try:
|
||||
manufacturer = Company.objects.get(id=manufacturer)
|
||||
data['manufacturer'] = manufacturer
|
||||
except Company.DoesNotExist:
|
||||
raise ValidationError(f"Manufacturer not found: {manufacturer}")
|
||||
elif not isinstance(manufacturer, Company):
|
||||
raise ValidationError(f"Invalid manufacturer type: {type(manufacturer)}")
|
||||
|
||||
# Create submission through base class
|
||||
submission, ride_model = super().create_entity_submission(user, data, **kwargs)
|
||||
|
||||
return submission, ride_model
|
||||
Reference in New Issue
Block a user