Saved List
A saved list is a collection of items (products) that a user wants to keep track of for future reference or purchase. It's very similar to a wishlist, where you save items you might want to buy later.
A saved list is a collection of items (products) that a user wants to keep track of for future reference or purchase. It's very similar to a wishlist, where you save items you might want to buy later.
1. Create Saved List
- The
createFromTrolleymethod in theSavedListsControllerhandles a POST request to the/create-from-trolley/{trolleyId}endpoint. - It retrieves the specified trolley and its lines, checks if the user is authorized to view it.
- and processes the trolley lines to gather product details and quantities.
- If the trolley is empty, it aborts with a 422 status.
- The method prepares data including items and the current date, optionally adding the customer ID, and uses the
quickTrolleyServiceto create a new quick trolley. - Then It simply logs the creation and returns the new saved list as a
SavedListResourcewith product data.
Route::post('/create-from-trolley/{trolleyId}', 'SavedListsController@createFromTrolley');
Details
- Route:
/create-from-trolley/{trolleyId} - HTTP Request:
POST - Controller:
SavedListsController - Method:
createFromTrolley
2. Display Saved List
- The
showmethod in theSavedListsControllerhandles a GET request to the/{savedListRef}endpoint. - It retrieves the quick trolley using the provided reference and loads additional data as specified.
- The method ensures the user has the correct session ID by comparing it with the trolley's session ID.
- If the user's session ID does not match, it aborts with a 403 Forbidden status.
- The method then returns the retrieved quick trolley as a
SavedListResource.
Route::get('/{savedListRef}', 'SavedListsController@show');
Details
- Route:
/{savedListRef} - HTTP Request:
GET - Controller:
SavedListsController - Method:
show
3. Update Saved List
- The
updatemethod in theSavedListsControllerhandles a PATCH request to the/{savedListRef}endpoint. - It retrieves the quick trolley using the provided reference.
- The method ensures the user has the correct session ID by comparing it with the trolley's session ID.
- If the user's session ID does not match, it aborts with a 403 Forbidden status.
- The method updates the quick trolley with new data, specifically the label (name) provided in the request.
- A debug log entry is created to indicate the successful update of the quick trolley.
- The method re-fetches the updated quick trolley to ensure all data, including product codes, are included, and returns it as a
SavedListResource.
Route::patch('/{savedListRef}', 'SavedListsController@update');
Details
- Route:
/{savedListRef} - HTTP Request:
PATCH - Controller:
SavedListsController - Method:
update
4. Delete Saved List
- The
deletemethod in theSavedListsControllerhandles a DELETE request to the/{savedListRef}endpoint. - It retrieves the quick trolley using the provided reference.
- The method ensures the user has the correct session ID by comparing it with the trolley's session ID.
- If the user's session ID does not match, it aborts with a 403 Forbidden status.
- The method deletes the quick trolley using the
quickTrolleyService. - A debug log entry is created to indicate the successful deletion of the quick trolley.
- The method returns a no-content response indicating successful deletion.
Route::delete('/{savedListRef}', 'SavedListsController@delete');
Details
- Route:
/{savedListRef} - HTTP Request:
DELETE - Controller:
SavedListsController - Method:
delete
5. Add a New Item
- The
addNewItemmethod in theSavedListsControllerhandles a POST request to the/{savedListRef}/itemsendpoint. - It retrieves the quick trolley using the provided reference.
- The method ensures the user has the correct session ID by comparing it with the trolley's session ID.
- If the user's session ID does not match, it aborts with a 403 Forbidden status.
- The method retrieves the product using the provided product code.
- It then adds the product to the quick trolley with the specified quantity.
- A debug log entry is created to indicate the successful addition of the item to the quick trolley.
- The method re-fetches the updated quick trolley to ensure all data, including product codes, are included, and returns it as a
SavedListResourcewith a 201 Created status.
Route::post('/{savedListRef}/items', 'SavedListsController@addNewItem');
Details
- Route:
/{savedListRef}/items - HTTP Request:
POST - Controller:
SavedListsController - Method:
addNewItem
6. Update Item Quantity
- The
updateItemQuantitymethod in theSavedListsControllerhandles a PATCH request to the/{savedListRef}/items/{productCode}endpoint. - It retrieves the quick trolley using the provided reference.
- The method ensures the user has the correct session ID by comparing it with the trolley's session ID.
- If the user's session ID does not match, it aborts with a 403 Forbidden status.
- The method finds the product within the quick trolley's products using the provided product code.
- If the product is not found, it returns a 404 Not Found response.
- It updates the product quantity in the quick trolley with the specified quantity.
- A debug log entry is created to indicate the successful update of the item quantity in the quick trolley.
- The method re-fetches the updated quick trolley to ensure all data, including product codes, are included, and returns it as a
SavedListResource.
Route::patch('/{savedListRef}/items/{productCode}', 'SavedListsController@updateItemQuantity');
Details
- Route:
/{savedListRef}/items/{productCode} - HTTP Request:
PATCH - Controller:
SavedListsController - Method:
updateItemQuantity
7. Delete an Item
- The
deleteItemmethod in theSavedListsControllerhandles a DELETE request to the/{savedListRef}/items/{productCode}endpoint. - It retrieves the quick trolley using the provided reference.
- The method ensures the user has the correct session ID by comparing it with the trolley's session ID.
- If the user's session ID does not match, it aborts with a 403 Forbidden status.
- The method finds the product within the quick trolley's products using the provided product code.
- If the product is not found, it returns a 404 Not Found response.
- It deletes the product from the quick trolley.
- A debug log entry is created to indicate the successful deletion of the item from the quick trolley.
- The method re-fetches the updated quick trolley to ensure all data, including product codes, are included, and returns it as a
SavedListResource.
Route::delete('/{savedListRef}/items/{productCode}', 'SavedListsController@deleteItem');
Details
- Route:
/{savedListRef}/items/{productCode} - HTTP Request:
DELETE - Controller:
SavedListsController - Method:
deleteItem