Exemplo n.º 1
0
 def put(self, request, id):
     room = self.get_room(id)
     serializer = RoomListSerializer(instance=room, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response({'error': serializer.errors})
Exemplo n.º 2
0
 def post(self, request):
     serializer = RoomListSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response({'error': serializer.errors},
                     status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemplo n.º 3
0
def saved_rooms(request, saved):
    try:
        room = Room.objects.get(saved=saved)
    except Room.DoesNotExist as e:
        return Response({'error': str(e)})

    if request.method == 'GET':
        serializer = RoomListSerializer(room)
        return Response(serializer.data)
Exemplo n.º 4
0
def hotel_rooms(request, id):
    try:
        hotel = Hotel.objects.get(id=id)
    except Hotel.DoesNotExist as e:
        return Response({'error': str(e)})

    if request.method == 'GET':
        serializer = RoomListSerializer(hotel, many=True)
        return Response(serializer.data)
Exemplo n.º 5
0
def room_list(request):
    if request.method == 'GET':
        rooms = Room.objects.all()
        serializer = RoomListSerializer(rooms, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        serializer = RoomListSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response({'error': serializer.errors},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemplo n.º 6
0
def room_detail(request, id):
    try:
        room = Room.objects.get(id=id)
    except Room.DoesNotExist as e:
        return Response({'error': str(e)})

    if request.method == 'GET':
        serializer = RoomListSerializer(room)
        return Response(serializer.data)

    elif request.method == 'PUT':
        serializer = RoomListSerializer(instance=room, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response({'error': serializer.errors})

    elif request.method == 'DELETE':
        room.delete()
        return Response({'deleted': True})
Exemplo n.º 7
0
 def get(self, request, id):
     room = self.get_room(id)
     serializer = RoomListSerializer(room)
     return Response(serializer.data)
Exemplo n.º 8
0
    def get(self, request):
        rooms = Room.objects.all()
        serializer = RoomListSerializer(rooms, many=True)

        return Response(serializer.data)