pesto-students / little-tags-rajeshdh-backend

little-tags-rajeshdh created by GitHub Classroom
https://little-tags-pesto.herokuapp.com/
1 stars 1 forks source link

Schema of the Database + Endpoints #11

Open ArfatSalman opened 3 years ago

ArfatSalman commented 3 years ago

Instructions

Since you have built the frontend, and you have used fake data till now, now is the time to decide what data your database will store and what the shape of the data is going be.

For this issue, you have to decide on which type DB to use (for ex - SQL / Mongo / Neo4J etc) and what tables (or collections) you app is going to have. Apart from that, also describe the fields of the tables and their types. Ensure to list down constraints such as Foreign Key. In short, you have

Since the back-end is an REST-based service, what URLs will your backend expose? Try to write all the end points and how many HTTP verbs they support.

Requirements

Resources

Please ensure that you read these articles well.

rajeshdh commented 3 years ago

I have created a tag for the frontend.

Imagine-Me commented 3 years ago

Endpoints

1. Category

Return the products filtered by categories and other filter criteria (rating, brands, etc...)

URL
/category/:category_name `category_name` : Name of the category user specified ##### BODY Object eg: ```js { "price": Array, //an array of 2 elements, where the first one is min price and where the second one is max price "brands": Array, ///an array of string that contains brands (the result will be filtered based on this) "rating": Array // an array of number that contains the rating } ``` ##### METHOD `POST` ##### Response codes 200 ## 2. Search Returns an array that matches the user query, this can be brand, name of the product eg: ```js [ { “Title”: “shoe”, “slug”:”/category/shoe” } ] ``` ##### URL /search/:name `name`: user input ##### METHOD `POST` ##### BODY Object eg: ```js { "price": Array, //an array of 2 elements, where the first one is min price and where the second one is max price "brands": Array, ///an array of string that contains brands (the result will be filtered based on this) "rating": Array // an array of number that contains the rating } ``` ##### Response codes 200 ## 3. Product Returns all the details of the product ##### URL /product/:id `id`: id of the product ##### METHOD `GET` ##### RESPONSE CODE 200 404 ## 4. Cart ##### URL /user/cart/ #### METHODS ##### 1. GET Returns an array of products which user added to cart ###### RESPONSE CODE: 200 401 ##### 2. PUT Add a product to the user cart ###### BODY Object ```js { “Id”: String, “Selected_features” : Object, //the contains the details of selected features such as color and size “Quantity”: Number } ``` ###### Response codes 204 401 ##### 3. DELETE Remove a product from the cart ###### BODY An object contains the id of the product ###### Response code 200 401 ## 5. Wishlist ##### URL `/user/wishlist/` #### METHODS ##### 1. GET Returns an array of products that the user added to the wishlist ###### Response codes 200 401 ##### 2. PUT Add a product to the user cart ###### BODY An object contains the id of the product ###### Response codes 200 401 ## 6. Order history ##### URL `/user/order-history` ##### METHOD GET ##### Response codes 200 401
rajeshdh commented 3 years ago

We are using MongoDB Atlas as our DB service. We have integrated MongoDB atlas with our API and created new set routes. We are using v1 for the new API routes e.g. https://little-tags-pesto.herokuapp.com/v1/products

rajeshdh commented 3 years ago

DB SCHEMA

We have the following collections defined in our database:

  1. Products
    const ProductSchema = new Schema({
    title: {
    type: String,
    required: true,
    },
    image: {
    type: String,
    required: true,
    },
    brand: {
    type: String,
    required: true,
    },
    description: {
    type: String,
    required: true,
    },
    rating: Number,
    noOfReview: Number,
    stock: Number,
    features: [
    {
      type: {
        type: String,
        required: true,
      },
      value: [String],
    },
    ],
    gallery: [
    {
      title: {
        type: String,
        required: true,
      },
      image: {
        type: String,
        required: true,
      },
    },
    ],
    originalPrice: Number,
    currentPrice: Number,
    offer: Number,
    currency: {
    type: String,
    enum: ['INR', 'USD'],
    default: 'INR',
    },
    category: {
    name: {
      type: String,
      required: true,
    },
    categoryId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Category',
    },
    },
    });
  2. Categories
    const CategorySchema = Schema(
    {
    name: {
      type: String,
      required: true,
    },
    image: {
      type: String,
    },
    description: {
      type: String,
    },
    },
    {
    timestamps: true,
    }
    );
  3. Orders
    const OrderSchema = Schema(
    {
    status: {
      type: String,
      required: true,
      enum: ['active', 'processing', 'complete'],
    },
    modifiedOn: { type: Date, default: Date.now },
    products: [
      {
        productId: {
          type: mongoose.Schema.Types.ObjectId,
          ref: 'Product',
        },
        quantity: {
          type: Number,
          required: true,
        },
        name: String,
        price: Number,
      },
    ],
    user: {
      type: mongoose.Schema.Types.ObjectId,
      required: true,
      ref: 'User',
    },
    shippingAddress: {
      id: 1,
      fullName: { type: String, required: true },
      mobileNumber: { type: String, required: true },
      address: { type: String, required: true },
      state: { type: String, required: true },
      city: { type: String, required: true },
      pin: { type: Number, required: true },
    },
    paymentMethod: {
      type: String,
      required: true,
    },
    paymentResult: {
      id: { type: String },
      status: { type: String },
      update_time: { type: String },
      email_address: { type: String },
    },
    shippingPrice: {
      type: Number,
      required: true,
      default: 0.0,
    },
    totalPrice: {
      type: Number,
      required: true,
      default: 0.0,
    },
    isPaid: {
      type: Boolean,
      required: true,
      default: false,
    },
    paidAt: {
      type: Date,
    },
    isDelivered: {
      type: Boolean,
      required: true,
      default: false,
    },
    deliveredAt: {
      type: Date,
    },
    },
    {
    timestamps: true,
    }
    );
  4. Users
    const UserSchema = Schema(
    {
    username: {
      type: String,
      required: true,
    },
    password: {
      type: String,
      required: true,
    },
    lastName: {
      type: String,
      required: true,
    },
    firstName: {
      type: String,
      required: true,
    },
    email: {
      type: String,
      required: true,
    },
    },
    { timestamps: true }
    );

We still need to work upon the user schema to add wishlist and cart properties.