@@ -54,7 +54,7 @@ class UserFavorites(ListAPIView, DefaultOrderMixin):
5454
5555 def get_queryset (self ):
5656 user = self .request .user
57- return user .listings_favorited
57+ return user .listings_favorited . all ()
5858
5959
6060# TODO: Can add feature to filter for active offers only
@@ -250,26 +250,32 @@ class Favorites(
250250
251251 def get_queryset (self ):
252252 user = self .request .user
253- return user .listings_favorited
253+ return user .listings_favorited . all ()
254254
255255 def create (self , request , * args , ** kwargs ):
256256 listing_id = int (self .kwargs ["listing_id" ])
257- queryset = self .get_queryset ()
258- if queryset .filter (id = listing_id ).exists ():
259- raise exceptions .ValidationError ("Favorite already exists" )
257+ favorites = request .user .listings_favorited
258+ if favorites .filter (id = listing_id ).exists ():
259+ return Response (
260+ {"favorited" : True , "detail" : "Favorite already exists" },
261+ status = status .HTTP_200_OK ,
262+ )
260263 listing = get_object_or_404 (Listing , id = listing_id )
261- self . get_queryset () .add (listing )
262- return Response (status = status .HTTP_201_CREATED )
264+ favorites .add (listing )
265+ return Response ({ "favorited" : True }, status = status .HTTP_200_OK )
263266
264267 def destroy (self , request , * args , ** kwargs ):
265268 listing_id = int (self .kwargs ["listing_id" ])
266269 listing = get_object_or_404 (Listing , id = listing_id )
267270
268271 if listing not in request .user .listings_favorited .all ():
269- raise exceptions .NotFound ("Favorite does not exist." )
272+ return Response (
273+ {"favorited" : False , "detail" : "Favorite does not exist" },
274+ status = status .HTTP_200_OK ,
275+ )
270276
271- self . get_queryset () .remove (listing )
272- return Response (status = status .HTTP_204_NO_CONTENT )
277+ request . user . listings_favorited .remove (listing )
278+ return Response ({ "favorited" : False }, status = status .HTTP_200_OK )
273279
274280
275281class Offers (viewsets .ModelViewSet ):
0 commit comments