diff --git a/backend/apps/comment/api/v1/serializers.py b/backend/apps/comment/api/v1/serializers.py index c0b9baf9..e924695e 100644 --- a/backend/apps/comment/api/v1/serializers.py +++ b/backend/apps/comment/api/v1/serializers.py @@ -4,7 +4,7 @@ from ...models import CommentModel -class CommentSerializer(serializers.ModelSerializer): +class CommentModelSerializer(serializers.ModelSerializer): path = serializers.CharField(required=False) class Meta: diff --git a/backend/apps/comment/api/v1/viewsets.py b/backend/apps/comment/api/v1/viewsets.py index 381f823f..0d31732e 100644 --- a/backend/apps/comment/api/v1/viewsets.py +++ b/backend/apps/comment/api/v1/viewsets.py @@ -1,12 +1,12 @@ from common.api.bases.viewsets import UpdateRetrieveDestroyViewSet from ...models import CommentModel -from .serializers import CommentSerializer +from .serializers import CommentModelSerializer class CommentModelViewSet(UpdateRetrieveDestroyViewSet): queryset = CommentModel.objects.all() - serializer_class = CommentSerializer + serializer_class = CommentModelSerializer def perform_destroy(self, instance): CommentModel.objects.soft_delete(instance) # pyright: ignore diff --git a/backend/apps/quib/api/v1/serializers.py b/backend/apps/quib/api/v1/serializers.py index 141b9e1b..2e75c88c 100644 --- a/backend/apps/quib/api/v1/serializers.py +++ b/backend/apps/quib/api/v1/serializers.py @@ -1,20 +1,23 @@ from rest_framework import serializers -from apps.quiblet.api.v1.serializers import QuibletSerializer, QuibletSlimSerializer +from apps.quiblet.api.v1.serializers import ( + QuibletModelSerializer, + QuibletSlimModelSerializer, +) from ...models import QuibModel -class QuibSerializer(serializers.ModelSerializer): - quiblet = QuibletSerializer(read_only=True) +class QuibModelSerializer(serializers.ModelSerializer): + quiblet = QuibletModelSerializer(read_only=True) class Meta: model = QuibModel fields = '__all__' -class QuibSlimSerializer(serializers.ModelSerializer): - quiblet = QuibletSlimSerializer(read_only=True) +class QuibSlimModelSerializer(serializers.ModelSerializer): + quiblet = QuibletSlimModelSerializer(read_only=True) class Meta: model = QuibModel diff --git a/backend/apps/quib/api/v1/viewsets.py b/backend/apps/quib/api/v1/viewsets.py index 3a29555b..22f6b45c 100644 --- a/backend/apps/quib/api/v1/viewsets.py +++ b/backend/apps/quib/api/v1/viewsets.py @@ -4,10 +4,10 @@ from rest_framework import response, status, viewsets from rest_framework.decorators import action -from apps.comment.api.v1.serializers import CommentSerializer +from apps.comment.api.v1.serializers import CommentModelSerializer from ...models import QuibModel -from .serializers import QuibSerializer, QuibSlimSerializer +from .serializers import QuibModelSerializer, QuibSlimModelSerializer class QuibModelViewSet(viewsets.ModelViewSet): @@ -15,11 +15,11 @@ class QuibModelViewSet(viewsets.ModelViewSet): def get_serializer_class(self): # pyright: ignore if self.action == 'list': - return QuibSlimSerializer + return QuibSlimModelSerializer # if custom action: 'comment' if self.action == 'comments': - return CommentSerializer - return QuibSerializer + return CommentModelSerializer + return QuibModelSerializer @action(detail=True, methods=[HTTPMethod.GET, HTTPMethod.POST]) def comments(self, request, pk=None): @@ -27,11 +27,11 @@ def comments(self, request, pk=None): if request.method == HTTPMethod.GET: comments = quib_instance.comments.all() - serializer = CommentSerializer(comments, many=True) + serializer = CommentModelSerializer(comments, many=True) return response.Response(serializer.data, status=status.HTTP_200_OK) - serializer = CommentSerializer(data=request.data) + serializer = CommentModelSerializer(data=request.data) serializer.is_valid(raise_exception=True) comment_instance = serializer.save() diff --git a/backend/apps/quiblet/api/v1/serializers.py b/backend/apps/quiblet/api/v1/serializers.py index 48262395..cf6998ad 100644 --- a/backend/apps/quiblet/api/v1/serializers.py +++ b/backend/apps/quiblet/api/v1/serializers.py @@ -3,7 +3,7 @@ from ...models import QuibletModel -class QuibletSerializer(serializers.ModelSerializer): +class QuibletModelSerializer(serializers.ModelSerializer): class Meta: model = QuibletModel fields = '__all__' @@ -17,7 +17,7 @@ def validate_name(self, name): return name -class QuibletSlimSerializer(serializers.ModelSerializer): +class QuibletSlimModelSerializer(serializers.ModelSerializer): class Meta: model = QuibletModel fields = ('name', 'avatar') diff --git a/backend/apps/quiblet/api/v1/viewsets.py b/backend/apps/quiblet/api/v1/viewsets.py index 703249ca..730d1bff 100644 --- a/backend/apps/quiblet/api/v1/viewsets.py +++ b/backend/apps/quiblet/api/v1/viewsets.py @@ -8,12 +8,12 @@ from common.patches.request import PatchedHttpRequest from ...models import QuibletModel -from .serializers import QuibletExistsSerializer, QuibletSerializer +from .serializers import QuibletExistsSerializer, QuibletModelSerializer class QuibletModelViewSet(viewsets.ModelViewSet): queryset = QuibletModel.objects.all() - serializer_class = QuibletSerializer + serializer_class = QuibletModelSerializer lookup_field = 'name' def get_queryset(self) -> QuerySet[QuibletModel]: # pyright: ignore @@ -21,7 +21,7 @@ def get_queryset(self) -> QuerySet[QuibletModel]: # pyright: ignore def get_object(self) -> QuibletModel: # pyright: ignore qs = self.get_queryset() - filter_kwargs = {f'{self.lookup_field}': self.kwargs[self.lookup_field]} + filter_kwargs = {f'{self.lookup_field}__iexact': self.kwargs[self.lookup_field]} obj = qs.filter(**filter_kwargs).first() if not obj: diff --git a/backend/apps/user/api/v1/serializers.py b/backend/apps/user/api/v1/serializers.py index 4c417d9b..b8b91ca6 100644 --- a/backend/apps/user/api/v1/serializers.py +++ b/backend/apps/user/api/v1/serializers.py @@ -3,7 +3,7 @@ from ...models import ProfileModel, User -class UserSerializer(serializers.ModelSerializer): +class UserModelSerializer(serializers.ModelSerializer): class Meta: model = User fields = ('id', 'email', 'password', 'date_joined') @@ -15,19 +15,19 @@ def create(self, validated_data): return user -class ProfileSerializer(serializers.ModelSerializer): - user = UserSerializer(read_only=True) - - class Meta: - model = ProfileModel - fields = '__all__' - - -class AuthSerializer(serializers.ModelSerializer): +class UserAuthModelSerializer(serializers.ModelSerializer): class Meta: model = User fields = ('email', 'password') -class AuthTokenResponseSerializer(serializers.Serializer): +class UserAuthTokenSerializer(serializers.Serializer): token = serializers.CharField() + + +class ProfileModelSerializer(serializers.ModelSerializer): + user = UserModelSerializer(read_only=True) + + class Meta: + model = ProfileModel + fields = '__all__' diff --git a/backend/apps/user/api/v1/views.py b/backend/apps/user/api/v1/views.py index f2bdc479..4e5b59ec 100644 --- a/backend/apps/user/api/v1/views.py +++ b/backend/apps/user/api/v1/views.py @@ -7,7 +7,11 @@ from common.api.exceptions import ServerError from common.api.serializers import DetailResponseSerializer -from .serializers import AuthSerializer, AuthTokenResponseSerializer, ProfileSerializer +from .serializers import ( + ProfileModelSerializer, + UserAuthModelSerializer, + UserAuthTokenSerializer, +) class LoginAPIView(views.APIView): @@ -18,9 +22,9 @@ class LoginAPIView(views.APIView): and issues a token upon successful login. """ - serializer_class = AuthSerializer + serializer_class = UserAuthModelSerializer - @extend_schema(responses=AuthTokenResponseSerializer) + @extend_schema(responses=UserAuthTokenSerializer) def post(self, request, format=None): user = authenticate( email=request.data.get('email'), password=request.data.get('password') @@ -54,7 +58,7 @@ class RegisterAPIView(generics.CreateAPIView): View to handle registering of new users. """ - serializer_class = AuthSerializer + serializer_class = UserAuthModelSerializer class MeAPIView(views.APIView): @@ -68,7 +72,7 @@ class MeAPIView(views.APIView): """ permission_classes = (permissions.IsAuthenticated,) - serializer_class = ProfileSerializer + serializer_class = ProfileModelSerializer def get(self, request): if request.user_profile: diff --git a/backend/apps/user/api/v1/viewsets.py b/backend/apps/user/api/v1/viewsets.py index 69c8ea2d..9cb21a3d 100644 --- a/backend/apps/user/api/v1/viewsets.py +++ b/backend/apps/user/api/v1/viewsets.py @@ -2,7 +2,7 @@ from rest_framework import exceptions, filters, permissions, viewsets from ...models import ProfileModel -from .serializers import ProfileSerializer +from .serializers import ProfileModelSerializer class ProfileModelReadOnlyViewSet(viewsets.ReadOnlyModelViewSet): @@ -14,7 +14,7 @@ class ProfileModelReadOnlyViewSet(viewsets.ReadOnlyModelViewSet): """ queryset = ProfileModel.objects.all() - serializer_class = ProfileSerializer + serializer_class = ProfileModelSerializer filter_backends = (filters.SearchFilter,) search_fields = ('username',) @@ -28,7 +28,7 @@ class MyProfilesModelViewSet(viewsets.ModelViewSet): """ permission_classes = (permissions.IsAuthenticated,) - serializer_class = ProfileSerializer + serializer_class = ProfileModelSerializer def get_queryset(self): # pyright: ignore """