mirror of
https://github.com/bspeice/UNCCGameDay-Server
synced 2025-12-08 02:58:48 -05:00
Add code for the REST API to work with Parking lot ratings
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
from models import ParkingLot
|
||||
from serializers import ParkingLotSerializer
|
||||
from models import ParkingLot, ParkingRating
|
||||
from serializers import *
|
||||
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
|
||||
class ParkingLotList(APIView):
|
||||
"""
|
||||
@ -12,4 +13,16 @@ class ParkingLotList(APIView):
|
||||
def get(self, request):
|
||||
parking_lots = ParkingLot.objects.all()
|
||||
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)
|
||||
Reference in New Issue
Block a user