data link naar backend #11
@@ -1,7 +1,42 @@
|
||||
from os import extsep
|
||||
from django.db.models.functions import Extract
|
||||
from playlist.models import Album
|
||||
from rest_framework import serializers
|
||||
from drf_spectacular.utils import extend_schema_serializer, OpenApiExample
|
||||
|
||||
@extend_schema_serializer(
|
||||
examples = [
|
||||
OpenApiExample(
|
||||
name='Album Example',
|
||||
value = {
|
||||
"url": "http://muzak.hoekveen.net/api/album/7MejfRSNnrpcLZIxkeZDqR",
|
||||
"name": "Leftoverture (Expanded Edition)",
|
||||
"album_type": "album",
|
||||
"total_tracks": 10,
|
||||
"image": "http://127.0.0.1:8001/albums/Leftoverture_Expanded_Edition.png",
|
||||
"image_url": "https://i.scdn.co/image/ab67616d0000b2731be40e44db112e123e5e8b51",
|
||||
"artists": [
|
||||
"http://127.0.0.1:8001/api/artist/2hl0xAkS2AIRAu23TVMBG1"
|
||||
]
|
||||
}
|
||||
),
|
||||
OpenApiExample(
|
||||
name = 'Multiple artist single',
|
||||
value = {
|
||||
"url": "http://127.0.0.1:8001/api/album/1pHD8AFu4z1CvuTPjZFOFi",
|
||||
"name": "ラビリンス",
|
||||
"album_type": "single",
|
||||
"total_tracks": 4,
|
||||
"image": None,
|
||||
"image_url": "https://i.scdn.co/image/ab67616d0000b2731607d3aa3a69ca0e1ffbe26b",
|
||||
"artists": [
|
||||
"http://127.0.0.1:8001/api/artist/4ZX8Wr8KHHrW7radu6IwYG",
|
||||
"http://127.0.0.1:8001/api/artist/4d2zOuYJHBPJTpVblHEKJb"
|
||||
]
|
||||
}
|
||||
)
|
||||
]
|
||||
)
|
||||
class AlbumSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Album
|
||||
|
||||
@@ -1,6 +1,27 @@
|
||||
from playlist.models import Artist
|
||||
from rest_framework import serializers
|
||||
from drf_spectacular.utils import extend_schema_serializer, OpenApiExample
|
||||
|
||||
@extend_schema_serializer(
|
||||
examples=[
|
||||
OpenApiExample(
|
||||
'Daft Punk',
|
||||
value = {
|
||||
"id": "4tZwfgrHOc3mvqYlEYSvVi",
|
||||
"name": "Daft Punk",
|
||||
"url": "http://127.0.0.1:8001/api/artist/4tZwfgrHOc3mvqYlEYSvVi"
|
||||
}
|
||||
),
|
||||
OpenApiExample(
|
||||
'コリッキー',
|
||||
value = {
|
||||
"id": "307y5sbPNvRpXjBcZgS25q",
|
||||
"name": "コリッキー",
|
||||
"url": "http://127.0.0.1:8001/api/artist/307y5sbPNvRpXjBcZgS25q"
|
||||
}
|
||||
)
|
||||
]
|
||||
)
|
||||
class ArtistSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Artist
|
||||
|
||||
@@ -2,14 +2,17 @@ from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from playlist.models import Album
|
||||
from playlist.serializers import AlbumSerializer
|
||||
from drf_spectacular.utils import extend_schema
|
||||
|
||||
class AlbumListView(APIView):
|
||||
@extend_schema(responses={200: AlbumSerializer(many=True)})
|
||||
def get(self, request):
|
||||
albums = Album.objects.all()
|
||||
serializer = AlbumSerializer(albums, many=True, context={'request': request})
|
||||
return Response(serializer.data)
|
||||
|
||||
class AlbumDetailView(APIView):
|
||||
@extend_schema(responses={200: AlbumSerializer})
|
||||
def get(self, request, id):
|
||||
album = Album.objects.get(pk=id)
|
||||
serializer = AlbumSerializer(album, context={'request': request})
|
||||
|
||||
@@ -3,13 +3,16 @@ from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from playlist.models import Artist
|
||||
from playlist.serializers import ArtistSerializer
|
||||
from drf_spectacular.utils import extend_schema
|
||||
|
||||
@extend_schema(responses={200: ArtistSerializer(many=True)})
|
||||
class ArtistListView(APIView):
|
||||
def get(self, request):
|
||||
artists = Artist.objects.all()
|
||||
serializer = ArtistSerializer(artists, many=True, context={'request': request})
|
||||
return Response(serializer.data)
|
||||
|
||||
@extend_schema(responses={200: ArtistSerializer})
|
||||
class ArtistDetailView(APIView):
|
||||
def get(self, request, id):
|
||||
artist = Artist.objects.get(pk=id)
|
||||
|
||||
Reference in New Issue
Block a user