Exemplo n.º 1
0
 def put(self, request, artist_id, format = None):
     music = self.get_object(artist_id)
     serializer = MusicSerializer(music, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 2
0
    def post(self, request, room, format=None):
        """
        Post new music
        ---
        parameters:
          - name: music_id
            type: string
            paramType: body
            required: true

          - name: url
            type: string
            paramType: body
            required: true

          - name: thumbnail
            type: string
            paramType: body
            required: true

          - name: total_duration
            type: integer
            paramType: body
            required: true

          - name: duration
            type: integer
            paramType: body
            required: true

          - name: timer_start
            type: integer
            paramType: body

          - name: source
            type: string
            paramType: body
            required: true

          - name: name
            type: string
            paramType: body
            required: true
        """
        request.data.update({'room_id': room.id})
        try:
            music = Music.objects.get(music_id=request.data.get('music_id'), room=room)
            serializer = MusicSerializer(music, data=request.data, partial=True)
        except Music.DoesNotExist:
            serializer = MusicSerializer(data=request.data)
        if serializer.is_valid():
            music = serializer.save()
            room.add_music(music)
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 3
0
    def post(self, request, room, format=None):
        """
        Post new music
        ---
        parameters:
          - name: music_id
            type: string
            paramType: body
            required: true

          - name: url
            type: string
            paramType: body
            required: true

          - name: thumbnail
            type: string
            paramType: body
            required: true

          - name: total_duration
            type: integer
            paramType: body
            required: true

          - name: duration
            type: integer
            paramType: body
            required: true

          - name: timer_start
            type: integer
            paramType: body

          - name: source
            type: string
            paramType: body
            required: true

          - name: name
            type: string
            paramType: body
            required: true
        """
        request.data.update({'room_id': room.id})
        try:
            music = Music.objects.get(music_id=request.data.get('music_id'), room=room)
            serializer = MusicSerializer(music, data=request.data, partial=True)
        except Music.DoesNotExist:
            serializer = MusicSerializer(data=request.data)
        if serializer.is_valid():
            music = serializer.save()
            room.add_music(music)
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 4
0
 def patch(self, request, room, pk, format=None):
     """
     Update music
     ---
     serializer: MusicSerializer
     """
     try:
         music = Music.objects.get(pk=pk, room=room)
     except Music.DoesNotExist:
         return Response(status=status.HTTP_404_NOT_FOUND)
     serializer = MusicSerializer(music, data=request.data, partial=True)
     if serializer.is_valid():
         serializer.save()
         message = {
             'action': 'music_patched',
             'music': serializer.data,
         }
         room.send_message(message)
         return Response(serializer.data, status=status.HTTP_200_OK)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 5
0
 def patch(self, request, room, pk, format=None):
     """
     Update music
     ---
     serializer: MusicSerializer
     """
     try:
         music = Music.objects.get(pk=pk, room=room)
     except Music.DoesNotExist:
         return Response(status=status.HTTP_404_NOT_FOUND)
     serializer = MusicSerializer(music, data=request.data, partial=True)
     if serializer.is_valid():
         serializer.save()
         message = {
             'action': 'music_patched',
             'music': serializer.data,
         }
         room.send_message(message)
         return Response(serializer.data, status=status.HTTP_200_OK)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 6
0
 def post(self, request, format = None):
     serializer = MusicSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)