Skip to content

Commit

Permalink
Merge pull request #5 from soehlert/topic/soehlert/api
Browse files Browse the repository at this point in the history
feat(api): Create scaffolding/first pass at an API
  • Loading branch information
soehlert authored Aug 25, 2023
2 parents 49143a1 + 5006afc commit 0323766
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
19 changes: 19 additions & 0 deletions concerts/api/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from rest_framework import viewsets

from ..models import Artist, Concert, Venue
from .serializers import ArtistSerializer, ConcertSerializer, VenueSerializer


class ArtistViewset(viewsets.ModelViewSet):
queryset = Artist.objects.all()
serializer_class = ArtistSerializer


class VenueViewset(viewsets.ModelViewSet):
queryset = Venue.objects.all()
serializer_class = VenueSerializer


class ConcertViewset(viewsets.ModelViewSet):
queryset = Concert.objects.all()
serializer_class = ConcertSerializer
18 changes: 18 additions & 0 deletions concerts/migrations/0003_alter_venue_country.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.4 on 2023-08-25 17:53

from django.db import migrations
import django_countries.fields


class Migration(migrations.Migration):
dependencies = [
("concerts", "0002_alter_concert_opener"),
]

operations = [
migrations.AlterField(
model_name="venue",
name="country",
field=django_countries.fields.CountryField(default="US", max_length=2),
),
]
2 changes: 1 addition & 1 deletion concerts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Venue(models.Model):

name = models.CharField(max_length=100)
city = models.CharField(max_length=100)
country = CountryField()
country = CountryField(default="US")

def __str__(self):
if self.country:
Expand Down
4 changes: 4 additions & 0 deletions config/api_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
from rest_framework.routers import DefaultRouter, SimpleRouter

from concert_elephant.users.api.views import UserViewSet
from concerts.api.views import ArtistViewset, ConcertViewset, VenueViewset

if settings.DEBUG:
router = DefaultRouter()
else:
router = SimpleRouter()

router.register("artists", ArtistViewset)
router.register("concerts", ConcertViewset)
router.register("venues", VenueViewset)
router.register("users", UserViewSet)


Expand Down
11 changes: 10 additions & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView
from rest_framework.authtoken.views import obtain_auth_token

from .api_router import app_name

urlpatterns = [
path("", TemplateView.as_view(template_name="pages/home.html"), name="home"),
path("about/", TemplateView.as_view(template_name="pages/about.html"), name="about"),
Expand All @@ -18,10 +20,17 @@
# Your stuff: custom urls includes go here
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)


# API URLS
api_version_urls = (
[
path("v1/", include("config.api_router", namespace="v1")),
],
app_name,
)
urlpatterns += [
# API base url
path("api/", include("config.api_router")),
path("api/", include(api_version_urls, namespace="api")),
# DRF auth token
path("auth-token/", obtain_auth_token),
path("api/schema/", SpectacularAPIView.as_view(), name="api-schema"),
Expand Down

0 comments on commit 0323766

Please sign in to comment.