Add rudimentary API functionality.
This commit is contained in:
parent
0fb7f148bb
commit
abe64f3a7d
14 changed files with 93 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
dj-database-url>=0.4.2
|
dj-database-url>=0.4.2
|
||||||
Django>=2.0
|
Django>=2.0
|
||||||
django-authtools>=1.6.0
|
django-authtools>=1.6.0
|
||||||
|
djangorestframework>=3.7.7
|
||||||
psycopg2>=2.7.3.2
|
psycopg2>=2.7.3.2
|
||||||
python-decouple>=3.1
|
python-decouple>=3.1
|
||||||
pytz>=2017.3
|
pytz>=2017.3
|
||||||
|
|
0
savepointradio/api/__init__.py
Normal file
0
savepointradio/api/__init__.py
Normal file
3
savepointradio/api/admin.py
Normal file
3
savepointradio/api/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
5
savepointradio/api/apps.py
Normal file
5
savepointradio/api/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class ApiConfig(AppConfig):
|
||||||
|
name = 'api'
|
0
savepointradio/api/migrations/__init__.py
Normal file
0
savepointradio/api/migrations/__init__.py
Normal file
3
savepointradio/api/models.py
Normal file
3
savepointradio/api/models.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
0
savepointradio/api/serializers/__init__.py
Normal file
0
savepointradio/api/serializers/__init__.py
Normal file
36
savepointradio/api/serializers/radio.py
Normal file
36
savepointradio/api/serializers/radio.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from radio.models import Album, Artist, Game, Song
|
||||||
|
|
||||||
|
|
||||||
|
class AlbumSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Album
|
||||||
|
fields = ('id', 'title')
|
||||||
|
|
||||||
|
|
||||||
|
class ArtistSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Artist
|
||||||
|
fields = ('id', 'alias', 'first_name', 'last_name')
|
||||||
|
|
||||||
|
|
||||||
|
class ArtistFullnameSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Artist
|
||||||
|
fields = ('id', 'full_name')
|
||||||
|
|
||||||
|
|
||||||
|
class GameSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Game
|
||||||
|
fields = ('id', 'title')
|
||||||
|
|
||||||
|
|
||||||
|
class SongSerializer(serializers.ModelSerializer):
|
||||||
|
artists = ArtistFullnameSerializer(many=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Song
|
||||||
|
fields = ('id', 'album', 'artists', 'published_date', 'game',
|
||||||
|
'num_played', 'last_played', 'length', 'song_type', 'title')
|
3
savepointradio/api/tests.py
Normal file
3
savepointradio/api/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
13
savepointradio/api/urls.py
Normal file
13
savepointradio/api/urls.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
from rest_framework.routers import DefaultRouter
|
||||||
|
|
||||||
|
from api.views.radio import (AlbumViewSet, ArtistViewSet,
|
||||||
|
GameViewSet, SongViewSet)
|
||||||
|
|
||||||
|
|
||||||
|
router = DefaultRouter()
|
||||||
|
router.register(r'albums', AlbumViewSet, base_name='album')
|
||||||
|
router.register(r'artists', ArtistViewSet, base_name='artist')
|
||||||
|
router.register(r'games', GameViewSet, base_name='game')
|
||||||
|
router.register(r'songs', SongViewSet, base_name='song')
|
||||||
|
|
||||||
|
urlpatterns = router.urls
|
0
savepointradio/api/views/__init__.py
Normal file
0
savepointradio/api/views/__init__.py
Normal file
25
savepointradio/api/views/radio.py
Normal file
25
savepointradio/api/views/radio.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
from rest_framework import viewsets
|
||||||
|
|
||||||
|
from radio.models import Album, Artist, Game, Song
|
||||||
|
from ..serializers.radio import (AlbumSerializer, ArtistSerializer,
|
||||||
|
GameSerializer, SongSerializer)
|
||||||
|
|
||||||
|
|
||||||
|
class AlbumViewSet(viewsets.ModelViewSet):
|
||||||
|
queryset = Album.objects.all()
|
||||||
|
serializer_class = AlbumSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ArtistViewSet(viewsets.ModelViewSet):
|
||||||
|
queryset = Artist.objects.all()
|
||||||
|
serializer_class = ArtistSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class GameViewSet(viewsets.ModelViewSet):
|
||||||
|
queryset = Game.objects.all()
|
||||||
|
serializer_class = GameSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class SongViewSet(viewsets.ModelViewSet):
|
||||||
|
queryset = Song.objects.all()
|
||||||
|
serializer_class = SongSerializer
|
|
@ -38,10 +38,12 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
|
|
||||||
'authtools',
|
'authtools',
|
||||||
|
'rest_framework',
|
||||||
|
|
||||||
'core.apps.CoreConfig',
|
'core.apps.CoreConfig',
|
||||||
'radio.apps.RadioConfig',
|
'radio.apps.RadioConfig',
|
||||||
'profiles.apps.ProfilesConfig'
|
'profiles.apps.ProfilesConfig',
|
||||||
|
'api.apps.ApiConfig',
|
||||||
]
|
]
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = 'en-us'
|
||||||
|
|
|
@ -4,4 +4,5 @@ from django.urls import include, path
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('accounts/', include('authtools.urls')),
|
path('accounts/', include('authtools.urls')),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('api/', include('api.urls')),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue