diff --git a/author/migrations/0001_initial.py b/author/migrations/0001_initial.py new file mode 100644 index 0000000..dc0f655 --- /dev/null +++ b/author/migrations/0001_initial.py @@ -0,0 +1,25 @@ +# Generated by Django 4.1 on 2024-11-30 14:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Author', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=64)), + ('last_name', models.CharField(max_length=64)), + ('pseudonym', models.CharField(blank=True, max_length=64, null=True)), + ('age', models.IntegerField()), + ('retired', models.BooleanField()), + ], + ), + ] diff --git a/author/serializers.py b/author/serializers.py index d286b95..56a1bab 100644 --- a/author/serializers.py +++ b/author/serializers.py @@ -1,6 +1,12 @@ from rest_framework import serializers +from author.models import Author + class AuthorSerializer(serializers.ModelSerializer): - # write your code here - pass + class Meta: + model = Author + fields = [ + "first_name", "last_name", + "pseudonym", "age", "retired" + ] diff --git a/author/urls.py b/author/urls.py index fa856a3..624c3c6 100644 --- a/author/urls.py +++ b/author/urls.py @@ -1,3 +1,24 @@ -# Create your urls here +from rest_framework import routers +from django.urls import path, include +from author.views import AuthorViewSet -urlpatterns = [] +app_name = "author" + +author_list = AuthorViewSet.as_view( + actions={ + "get": "list", + "post": "create" + } +) +author_detail = AuthorViewSet.as_view( + actions={ + "get": "retrieve", + "put": "update", + "patch": "partial_update", + "delete": "destroy" + } +) +urlpatterns = [ + path("authors/", author_list, name="manage-list"), + path("authors//", author_detail, name="manage-detail"), +] diff --git a/author/views.py b/author/views.py index 608b89d..e7ff77e 100644 --- a/author/views.py +++ b/author/views.py @@ -1,6 +1,10 @@ from rest_framework import viewsets +from author.models import Author +from author.serializers import AuthorSerializer + class AuthorViewSet(viewsets.ModelViewSet): # write your code here - pass + queryset = Author.objects.all() + serializer_class = AuthorSerializer diff --git a/author_service/urls.py b/author_service/urls.py index 313c351..5eeb35c 100644 --- a/author_service/urls.py +++ b/author_service/urls.py @@ -18,5 +18,5 @@ urlpatterns = [ path("admin/", admin.site.urls), - path("api/", include("author.urls", namespace="author")), + path("api/author/", include("author.urls", namespace="author")), ]