Skip to content

Commit

Permalink
feat(users): add user about endpoint, remove unnecessary endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
tyronejosee committed Jul 11, 2024
1 parent 62e3412 commit a7fd93a
Show file tree
Hide file tree
Showing 4 changed files with 1,143 additions and 68 deletions.
10 changes: 10 additions & 0 deletions apps/profiles/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,13 @@ def to_representation(self, instance):
representation = super().to_representation(instance)
representation["image"] = representation.get("image", "") or ""
return representation


class ProfileAboutSerializer(serializers.ModelSerializer):
"""Serializer for Profile model (Bio only)."""

class Meta:
model = Profile
fields = [
"bio",
]
6 changes: 5 additions & 1 deletion apps/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

from django.urls import path, include

from .views import UserReviewsView
from .views import UserAboutView, UserReviewsView


urlpatterns = [
path(
"api/v1/users/<str:username>/about/",
UserAboutView.as_view(),
),
path(
"api/v1/users/<str:username>/reviews/",
UserReviewsView.as_view(),
Expand Down
83 changes: 16 additions & 67 deletions apps/users/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
"""Views for Users App."""

from django.shortcuts import get_object_or_404
from django.utils.translation import gettext as _
from rest_framework.generics import ListAPIView, RetrieveAPIView
from rest_framework.permissions import AllowAny
from rest_framework.exceptions import NotFound

from apps.reviews.models import Review
from apps.reviews.serializers import ReviewReadSerializer
from .permissions import IsMember
from apps.profiles.models import Profile
from apps.profiles.serializers import ProfileAboutSerializer
from .models import User
from .permissions import IsMember


class UserDetailView(RetrieveAPIView):
Expand All @@ -23,46 +27,24 @@ class UserDetailView(RetrieveAPIView):

class UserAboutView(RetrieveAPIView):
"""
View for retrieving the about section of a user.
View for retrieving the about section or bio of a user.
Endpoints:
- GET api/v1/users/{username}/about/
"""

pass # TODO: Pending for implementation

permission_classes = [AllowAny]
serializer_class = ProfileAboutSerializer
lookup_field = "username"
lookup_url_kwarg = "username"

class UserHistoryView(RetrieveAPIView):
"""
View for retrieving the history of a user.
Endpoints:
- GET api/v1/users/{username}/history/
"""

pass # TODO: Pending for implementation


class UserStatsView(RetrieveAPIView):
"""
View for retrieving the statistics of a user.
Endpoints:
- GET api/v1/users/{username}/stats/
"""

pass # TODO: Pending for implementation


class UserFriendsView(ListAPIView):
"""
View for retrieving the friends of a user.
Endpoints:
- GET api/v1/users/{username}/friends/
"""
def get_queryset(self):
username = self.kwargs.get("username").lower()
return Profile.objects.filter(user_id__username=username).select_related("user")

pass # TODO: Pending for implementation
def get_object(self):
queryset = self.get_queryset()
return get_object_or_404(queryset.values("bio"))


class UserReviewsView(ListAPIView):
Expand All @@ -83,36 +65,3 @@ def get_queryset(self):
except User.DoesNotExist:
raise NotFound(_("User not found."))
return Review.objects.filter(user_id=user)


class UserFavoritesView(ListAPIView):
"""
View for retrieving the favorite items of a user.
Endpoints:
- GET api/v1/users/{username}/favorites/
"""

pass # TODO: Pending for implementation


class UserRecommendationsView(ListAPIView):
"""
View for retrieving the recommendations for a user.
Endpoints:
- GET api/v1/users/{username}/recommendations/
"""

pass # TODO: Pending for implementation


class UserClubsView(ListAPIView):
"""
View for retrieving the clubs a user is a member of.
Endpoints:
- GET api/v1/users/{username}/clubs/
"""

pass # TODO: Pending for implementation
Loading

0 comments on commit a7fd93a

Please sign in to comment.