diff --git a/backend/secfit/users/urls.py b/backend/secfit/users/urls.py index 27ee5f23083e536f18eca554e3fecd0771d14969..378baf7ed21d0fa30149cb31cea725d9ee4600c1 100644 --- a/backend/secfit/users/urls.py +++ b/backend/secfit/users/urls.py @@ -1,3 +1,5 @@ +"""Contains paths in the api for the users application. +""" from django.urls import path from users import views diff --git a/backend/secfit/users/views.py b/backend/secfit/users/views.py index e8c1e5ab32259394b11e5cb5c6f7adc52424f87f..eab5c21c9ecb310111ade08a799d5f1aa199923d 100644 --- a/backend/secfit/users/views.py +++ b/backend/secfit/users/views.py @@ -1,7 +1,9 @@ -import django -from rest_framework import mixins, generics +from rest_framework import mixins, generics, permissions +from rest_framework.permissions import IsAuthenticatedOrReadOnly +from django.contrib.auth import get_user_model +from django.db.models import Q +from rest_framework.parsers import MultiPartParser, FormParser from workouts.mixins import CreateListModelMixin -from rest_framework import permissions from users.serializers import ( UserSerializer, OfferSerializer, @@ -10,22 +12,17 @@ from users.serializers import ( UserGetSerializer, ProfilePutSerializer ) -from rest_framework.permissions import ( - AllowAny, - IsAdminUser, - IsAuthenticated, - IsAuthenticatedOrReadOnly, -) from users.models import Offer, AthleteFile -from django.contrib.auth import get_user_model -from django.db.models import Q -from django.shortcuts import get_object_or_404 -from rest_framework.parsers import MultiPartParser, FormParser from users.permissions import IsCurrentUser, IsAthlete, IsCoach from workouts.permissions import IsOwner, IsReadOnly # Create your views here. class UserList(mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView): + """Class defining the web response for the creation of users, or + a list of users. + + HTTP methods: GET, POST + """ serializer_class = UserSerializer users = [] admins = [] @@ -55,6 +52,11 @@ class UserDetail( mixins.DestroyModelMixin, generics.GenericAPIView, ): + """Class defining the web response for the retrieval of a user, or + updating/deleting a user. + + HTTP methods: GET, DELETE, PUT, PATCH + """ lookup_field_options = ["pk", "username"] serializer_class = UserSerializer queryset = get_user_model().objects.all() @@ -87,6 +89,10 @@ class ProfileUpdate( mixins.UpdateModelMixin, generics.GenericAPIView, ): + """Class defining the web response for updating a profile. + + HTTP methods: PUT + """ serializer_class = ProfilePutSerializer queryset = get_user_model().objects.all() permission_classes = [permissions.IsAuthenticated & IsCurrentUser] @@ -97,6 +103,11 @@ class ProfileUpdate( class OfferList( mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView ): + """Class defining the web response for the creation of offers, or + a list of offers. + + HTTP methods: GET, POST + """ permission_classes = [IsAuthenticatedOrReadOnly] serializer_class = OfferSerializer @@ -145,6 +156,11 @@ class OfferDetail( mixins.DestroyModelMixin, generics.GenericAPIView, ): + """Class defining the web response for the retrieval of an offer, or + updating/deleting an offer. + + HTTP methods: GET, DELETE, PUT, PATCH + """ permission_classes = [IsAuthenticatedOrReadOnly] queryset = Offer.objects.all() serializer_class = OfferSerializer @@ -168,6 +184,11 @@ class AthleteFileList( CreateListModelMixin, generics.GenericAPIView, ): + """Class defining the web response for the creation of athlete files, or + a list of athlete files. + + HTTP methods: GET, POST + """ queryset = AthleteFile.objects.all() serializer_class = AthleteFileSerializer permission_classes = [permissions.IsAuthenticated & (IsAthlete | IsCoach)] @@ -199,6 +220,11 @@ class AthleteFileDetail( mixins.DestroyModelMixin, generics.GenericAPIView, ): + """Class defining the web response for the retrieval of an athlete file, or + deleting an athlete file. + + HTTP methods: GET, DELETE + """ queryset = AthleteFile.objects.all() serializer_class = AthleteFileSerializer permission_classes = [permissions.IsAuthenticated & (IsAthlete | IsOwner)]