добавил запрос на добавление треков для плейлиста
This commit is contained in:
parent
33a082dfb3
commit
1f195ef8da
|
|
@ -86,8 +86,7 @@ class MyUserViewSet(ViewSet):
|
||||||
if check_password(request.data['password'], password):
|
if check_password(request.data['password'], password):
|
||||||
return Response(
|
return Response(
|
||||||
{'detail': 'Пароли одинаковые', 'error': {'email': 'Пароли одинаковые'}},
|
{'detail': 'Пароли одинаковые', 'error': {'email': 'Пароли одинаковые'}},
|
||||||
|
|
||||||
|
|
||||||
status=status.HTTP_400_BAD_REQUEST)
|
status=status.HTTP_400_BAD_REQUEST)
|
||||||
if 'email' in request.data:
|
if 'email' in request.data:
|
||||||
del request.data['email']
|
del request.data['email']
|
||||||
|
|
|
||||||
|
|
@ -64,9 +64,9 @@ class PlayListSchema(AutoSchema):
|
||||||
schema=coreschema.Integer(description='ID плейлиста')
|
schema=coreschema.Integer(description='ID плейлиста')
|
||||||
),
|
),
|
||||||
coreapi.Field(
|
coreapi.Field(
|
||||||
name='songs_id',
|
name='azura_id',
|
||||||
location='form',
|
location='form',
|
||||||
required=False,
|
required=False,
|
||||||
schema=coreschema.Array(description='ID треков')
|
schema=coreschema.String(description='ID трека с азуры')
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
@ -30,6 +30,28 @@ class PlayListViewSet(GenericViewSet):
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
return Response({"error": 'Объекта не существует'}, status=status.HTTP_404_NOT_FOUND)
|
return Response({"error": 'Объекта не существует'}, status=status.HTTP_404_NOT_FOUND)
|
||||||
|
|
||||||
|
@action(detail=False, methods=['post'], schema=PlayListSchema())
|
||||||
|
def add_to_playlist(self, request):
|
||||||
|
try:
|
||||||
|
song = list(Song.objects.filter(azura_id=request.data.get('azura_id')).values_list('pk', flat=True))
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
return Response({"error": 'Песни не существует'}, status=status.HTTP_404_NOT_FOUND)
|
||||||
|
|
||||||
|
try:
|
||||||
|
instance = PlayList.objects.get(pk=request.data.get('playlist_id'))
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
return Response({"error": 'Плейлиста не существует'}, status=status.HTTP_404_NOT_FOUND)
|
||||||
|
|
||||||
|
songs = list(instance.song.all().values_list('pk', flat=True))+song
|
||||||
|
data = {
|
||||||
|
'playlist_id': request.data.get('playlist_id'),
|
||||||
|
'song': songs
|
||||||
|
}
|
||||||
|
serializer = PlayListSerializer(data=data, partial=True, instance=instance)
|
||||||
|
serializer.is_valid(raise_exception=True)
|
||||||
|
serializer.save()
|
||||||
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class SongViewSet(GenericViewSet):
|
class SongViewSet(GenericViewSet):
|
||||||
queryset = Song.objects.all()
|
queryset = Song.objects.all()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue