Skip to content

Adding Wishlist Routes #16

@nani-samireddy

Description

@nani-samireddy

Overview

We need to extend our existing Express API to support wishlist functionalities. The wishlist schema will consist of a userId and an array of product IDs. The following routes are required for managing wishlists:

Wishlist Schema

const wishlistSchema = new mongoose.Schema({
    userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
    items: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Product' }] // Product schema will be added later
});

Routes

The following table outlines the required routes for managing wishlists:

HTTP Method Route Description Access Level
GET /api/wishlist/ Get all the wishlists available Superadmin only
GET /api/wishlist/:id Get a wishlist with a specific ID Public
GET /api/wishlist/ Get the wishlist of the currently logged-in user Logged-in user
POST /api/wishlist/ Create a wishlist for the current user Logged-in user
PUT /api/wishlist/:productId Add an item to the currently logged-in user's wishlist. If the wishlist does not exist, create one and then add the item Logged-in user
DELETE /api/wishlist/:productId Delete an item from the currently logged-in user's wishlist Logged-in user

Notes

  • There is no route to delete a wishlist directly. A wishlist should be deleted automatically when the associated user account is deleted.
  • Ensure that proper authentication and authorization checks are in place, especially for routes restricted to logged-in users and the superadmin.
  • The product schema will be added later, so currently, it is referenced as an array of product IDs.

Sample Schema

const mongoose = require('mongoose');

const wishlistSchema = new mongoose.Schema({
    userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
    items: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Product' }] // Product schema will be added later
});

module.exports = mongoose.model('Wishlist', wishlistSchema);

Checklist

  • Define the wishlist schema.
  • Implement the route to get all wishlists (GET /api/wishlist/).
  • Implement the route to get a wishlist by ID (GET /api/wishlist/:id).
  • Implement the route to get the wishlist of the currently logged-in user (GET /api/wishlist/).
  • Implement the route to create a wishlist for the current user (POST /api/wishlist/).
  • Implement the route to add an item to the currently logged-in user's wishlist (PUT /api/wishlist/:productId).
  • Implement the route to delete an item from the currently logged-in user's wishlist (DELETE /api/wishlist/:productId).
  • Ensure authentication and authorization checks are in place.
  • Write unit and integration tests for all routes.
  • Ensure that the wishlist is deleted automatically when the user account is deleted.
  • Update the Bruno collection with the updated routes.

Steps to Follow Before Starting the Work:

  1. Clone the repository if don't have:
    git clone git@github.com:The-Software-Squad/mvep-api.git
  2. If you already have the repository, checkout to the dev branch:
    git checkout dev
  3. Pull the latest changes:
    git pull origin dev
  4. Create a new branch for this feature:
    git checkout -b feature/add-wishlist-routes
  5. Once all tasks are completed and the code is thoroughly tested, Push your branch to the remote repository:
    git push origin feature/add-wishlist-routes

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions