diff --git a/backend/sublet/urls.py b/backend/sublet/urls.py index 10e3fa84..068a8ea6 100644 --- a/backend/sublet/urls.py +++ b/backend/sublet/urls.py @@ -2,7 +2,7 @@ from rest_framework import routers from rest_framework.routers import DefaultRouter -from sublet.views import Amenities, Favorites, Offers, Properties, UserFavorites +from sublet.views import Amenities, Favorites, Offers, Properties, UserFavorites, UserOffers app_name = "sublet" @@ -13,6 +13,7 @@ additional_urls = [ path("amenities/", Amenities.as_view(), name="amenities"), path("favorites/", UserFavorites.as_view(), name="user-favorites"), + path("offers/", UserOffers.as_view(), name="user-offers"), path( "properties//favorites/", Favorites.as_view({"post": "create", "delete": "destroy"}), diff --git a/backend/sublet/views.py b/backend/sublet/views.py index dd3261fe..3a09b415 100644 --- a/backend/sublet/views.py +++ b/backend/sublet/views.py @@ -44,7 +44,7 @@ def get_queryset(self): class Properties(viewsets.ModelViewSet): """ - browse: + list: Returns a list of Sublets that match query parameters (e.g., amenities) and belong to the user. create: @@ -129,13 +129,6 @@ def list(self, request, *args, **kwargs): serializer = SimpleSubletSerializer(queryset, many=True) return Response(serializer.data) - def retrieve(self, request, *args, **kwargs): - """Returns details of a specific Sublet.""" - print("new testing?") - sublet = self.get_object() - serializer = SubletSerializer(sublet) - return Response(serializer.data) - class Favorites(viewsets.ModelViewSet): serializer_class = FavoriteSerializer @@ -195,3 +188,13 @@ def destroy(self, request, *args, **kwargs): self.check_object_permissions(self.request, obj) self.perform_destroy(obj) return Response(status=status.HTTP_204_NO_CONTENT) + + +class UserOffers(generics.ListAPIView): + serializer_class = OfferSerializer + + def get_queryset(self): + user = self.request.user + # print(type(user.favorite_set)) + # return user.favorite_set + return Offer.objects.filter(user=user)