mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2026-01-02 01:47:04 -05:00
feat: Implement initial schema and add various API, service, and management command enhancements across the application.
This commit is contained in:
@@ -119,9 +119,7 @@ class CreateTripView(RoadTripViewMixin, View):
|
||||
|
||||
# Get parks
|
||||
parks = list(
|
||||
Park.objects.filter(
|
||||
id__in=park_ids, location__isnull=False
|
||||
).select_related("location", "operator")
|
||||
Park.objects.filter(id__in=park_ids, location__isnull=False).select_related("location", "operator")
|
||||
)
|
||||
|
||||
if len(parks) != len(park_ids):
|
||||
@@ -159,9 +157,7 @@ class CreateTripView(RoadTripViewMixin, View):
|
||||
{
|
||||
"status": "success",
|
||||
"data": trip_data,
|
||||
"trip_url": reverse(
|
||||
"parks:roadtrip_detail", kwargs={"trip_id": "temp"}
|
||||
),
|
||||
"trip_url": reverse("parks:roadtrip_detail", kwargs={"trip_id": "temp"}),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -258,12 +254,8 @@ class FindParksAlongRouteView(RoadTripViewMixin, View):
|
||||
|
||||
# Get start and end parks
|
||||
try:
|
||||
start_park = Park.objects.select_related("location").get(
|
||||
id=start_park_id, location__isnull=False
|
||||
)
|
||||
end_park = Park.objects.select_related("location").get(
|
||||
id=end_park_id, location__isnull=False
|
||||
)
|
||||
start_park = Park.objects.select_related("location").get(id=start_park_id, location__isnull=False)
|
||||
end_park = Park.objects.select_related("location").get(id=end_park_id, location__isnull=False)
|
||||
except Park.DoesNotExist:
|
||||
return render(
|
||||
request,
|
||||
@@ -272,21 +264,21 @@ class FindParksAlongRouteView(RoadTripViewMixin, View):
|
||||
)
|
||||
|
||||
# Find parks along route
|
||||
parks_along_route = self.roadtrip_service.find_parks_along_route(
|
||||
start_park, end_park, max_detour_km
|
||||
)
|
||||
parks_along_route = self.roadtrip_service.find_parks_along_route(start_park, end_park, max_detour_km)
|
||||
|
||||
# Return JSON if requested
|
||||
if request.headers.get("Accept") == "application/json" or request.content_type == "application/json":
|
||||
return JsonResponse({
|
||||
"status": "success",
|
||||
"data": {
|
||||
"parks": [self._park_to_dict(p) for p in parks_along_route],
|
||||
"start_park": self._park_to_dict(start_park),
|
||||
"end_park": self._park_to_dict(end_park),
|
||||
"count": len(parks_along_route)
|
||||
return JsonResponse(
|
||||
{
|
||||
"status": "success",
|
||||
"data": {
|
||||
"parks": [self._park_to_dict(p) for p in parks_along_route],
|
||||
"start_park": self._park_to_dict(start_park),
|
||||
"end_park": self._park_to_dict(end_park),
|
||||
"count": len(parks_along_route),
|
||||
},
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
return render(
|
||||
request,
|
||||
@@ -375,9 +367,7 @@ class GeocodeAddressView(RoadTripViewMixin, View):
|
||||
"longitude": coordinates.longitude,
|
||||
},
|
||||
"address": address,
|
||||
"nearby_parks": [
|
||||
loc.to_dict() for loc in map_response.locations[:20]
|
||||
],
|
||||
"nearby_parks": [loc.to_dict() for loc in map_response.locations[:20]],
|
||||
"radius_km": radius_km,
|
||||
},
|
||||
}
|
||||
@@ -418,12 +408,8 @@ class ParkDistanceCalculatorView(RoadTripViewMixin, View):
|
||||
|
||||
# Get parks
|
||||
try:
|
||||
park1 = Park.objects.select_related("location").get(
|
||||
id=park1_id, location__isnull=False
|
||||
)
|
||||
park2 = Park.objects.select_related("location").get(
|
||||
id=park2_id, location__isnull=False
|
||||
)
|
||||
park1 = Park.objects.select_related("location").get(id=park1_id, location__isnull=False)
|
||||
park2 = Park.objects.select_related("location").get(id=park2_id, location__isnull=False)
|
||||
except Park.DoesNotExist:
|
||||
return JsonResponse(
|
||||
{
|
||||
@@ -448,9 +434,7 @@ class ParkDistanceCalculatorView(RoadTripViewMixin, View):
|
||||
|
||||
from services.roadtrip import Coordinates
|
||||
|
||||
route = self.roadtrip_service.calculate_route(
|
||||
Coordinates(*coords1), Coordinates(*coords2)
|
||||
)
|
||||
route = self.roadtrip_service.calculate_route(Coordinates(*coords1), Coordinates(*coords2))
|
||||
|
||||
if not route:
|
||||
return JsonResponse(
|
||||
@@ -471,15 +455,11 @@ class ParkDistanceCalculatorView(RoadTripViewMixin, View):
|
||||
"formatted_duration": route.formatted_duration,
|
||||
"park1": {
|
||||
"name": park1.name,
|
||||
"formatted_location": getattr(
|
||||
park1, "formatted_location", ""
|
||||
),
|
||||
"formatted_location": getattr(park1, "formatted_location", ""),
|
||||
},
|
||||
"park2": {
|
||||
"name": park2.name,
|
||||
"formatted_location": getattr(
|
||||
park2, "formatted_location", ""
|
||||
),
|
||||
"formatted_location": getattr(park2, "formatted_location", ""),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user