mirror of
				https://github.com/bspeice/UNCCGameDay-Server
				synced 2025-11-04 02:10:37 -05:00 
			
		
		
		
	Add code for the REST API to work with Parking lot ratings
This commit is contained in:
		@ -8,3 +8,8 @@ class ParkingLotSerializer(serializers.ModelSerializer):
 | 
				
			|||||||
	class Meta:
 | 
						class Meta:
 | 
				
			||||||
		model = ParkingLot
 | 
							model = ParkingLot
 | 
				
			||||||
		fields = ('location', 'filled_pct')
 | 
							fields = ('location', 'filled_pct')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class ParkingRatingSerializer(serializers.ModelSerializer):
 | 
				
			||||||
 | 
						class Meta:
 | 
				
			||||||
 | 
							model = ParkingRating
 | 
				
			||||||
 | 
							fields = ('rating', 'parking_lot',)
 | 
				
			||||||
 | 
				
			|||||||
@ -2,5 +2,6 @@ from django.conf.urls import url, patterns
 | 
				
			|||||||
import views
 | 
					import views
 | 
				
			||||||
 | 
					
 | 
				
			||||||
urlpatterns = patterns('',
 | 
					urlpatterns = patterns('',
 | 
				
			||||||
	url('^lots/$', views.ParkingLotList.as_view())
 | 
						url('^lots/$', views.ParkingLotList.as_view()),
 | 
				
			||||||
 | 
						url('^rate/$', views.RateLot.as_view())
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@ -1,8 +1,9 @@
 | 
				
			|||||||
from models import ParkingLot
 | 
					from models import ParkingLot, ParkingRating
 | 
				
			||||||
from serializers import ParkingLotSerializer
 | 
					from serializers import *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from rest_framework.views import APIView
 | 
					from rest_framework.views import APIView
 | 
				
			||||||
from rest_framework.response import Response
 | 
					from rest_framework.response import Response
 | 
				
			||||||
 | 
					from rest_framework import status
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ParkingLotList(APIView):
 | 
					class ParkingLotList(APIView):
 | 
				
			||||||
	"""
 | 
						"""
 | 
				
			||||||
@ -13,3 +14,15 @@ class ParkingLotList(APIView):
 | 
				
			|||||||
		parking_lots = ParkingLot.objects.all()
 | 
							parking_lots = ParkingLot.objects.all()
 | 
				
			||||||
		serializer = ParkingLotSerializer(parking_lots, many=True)
 | 
							serializer = ParkingLotSerializer(parking_lots, many=True)
 | 
				
			||||||
		return Response(serializer.data)
 | 
							return Response(serializer.data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class RateLot(APIView):
 | 
				
			||||||
 | 
						"""
 | 
				
			||||||
 | 
						Rate a parking lot
 | 
				
			||||||
 | 
						"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						def post(self, request):
 | 
				
			||||||
 | 
							rating = ParkingRatingSerializer(data=request.DATA)
 | 
				
			||||||
 | 
							if rating.is_valid():
 | 
				
			||||||
 | 
								rating.save()
 | 
				
			||||||
 | 
								return Response(rating.data)
 | 
				
			||||||
 | 
							return Response(rating.errors, status=status.HTTP_400_BAD_REQUEST)
 | 
				
			||||||
@ -4,4 +4,4 @@
 | 
				
			|||||||
from gameday.models import ParkingLot
 | 
					from gameday.models import ParkingLot
 | 
				
			||||||
if ParkingLot.objects.all().count() == 0:
 | 
					if ParkingLot.objects.all().count() == 0:
 | 
				
			||||||
	for location in ParkingLot.LOT_CHOICES:
 | 
						for location in ParkingLot.LOT_CHOICES:
 | 
				
			||||||
		ParkingLot.objects.create(location=location)
 | 
							ParkingLot.objects.create(location=location[0])
 | 
				
			||||||
		Reference in New Issue
	
	Block a user