WishlistViewSet
Overview
The WishlistViewSet is a set of API views for managing a user's wishlist. It allows users to view their wishlist, add products to it, and remove products. The viewset supports pagination and handles batch operations for adding/removing multiple products.
Actions
- list(self, request)
Endpoint: api/v1/wishlist/product/list/
Method: GET
Permissions: IsAuthenticated
GET: This action retrieves all products currently in the user's wishlist.
Permissions: Only authenticated users can access this endpoint.
Response:
- If pagination is applied, it returns a paginated list of wishlist items.
- Each item includes product details and the is_wished status.
``` json
{
"id": 1,
"user": 1,
"product": {
"id": 1,
"name": "Product A",
"price": 100
},
"is_wished": true,
"created_at": "2024-12-05T10:00:00"
}
```
-
create(self, request) Endpoint:
api/v1/wishlist/product/add/
Method:POST
Permissions:IsAuthenticatedPOST: This action allows users to add multiple products to their wishlist.Request Body: A list of product IDs to be added to the wishlist.{ "product_ids": [1, 2, 3] }Permissions: Only authenticated users can access this endpoint.Response: - Returns a message indicating successful addition of products. - Includes a list of product IDs that were already in the wishlist.```json { "message": "Products added to wishlist", "added_items": [...], "already_in_wishlist": [2] } ``` -
destroy(self, request) Endpoint:
api/v1/wishlist/product/remove/
Method:DELETE
Permissions:IsAuthenticatedDELETE: This action allows users to remove multiple products from their wishlist.Request Body: A list of product IDs to be removed from the wishlist.{ "product_ids": [1, 3] }Permissions: Only authenticated users can access this endpoint.Response: - Returns a message indicating successful removal of products from the wishlist. - Includes a list of product IDs that were successfully deleted and those that were not found in the wishlist.```json { "message": "Products removed from wishlist", "deleted_products": [1], "not_in_wishlist": [3] } ```