Skip to content

Commit

Permalink
Create route to retrieve all user offers
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-Jess committed Oct 24, 2023
1 parent 20225e8 commit beb8bd5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion backend/sublet/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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/<sublet_id>/favorites/",
Favorites.as_view({"post": "create", "delete": "destroy"}),
Expand Down
19 changes: 11 additions & 8 deletions backend/sublet/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit beb8bd5

Please sign in to comment.