GithubHelp home page GithubHelp logo

Comments (3)

msnmz avatar msnmz commented on May 1, 2024

Backend updates:

  • Created a child schema for the product schema.
  • Added a comments array to the Product schema
  • Added a Put Request handler to the product API endpoint to handle the creation of a comment
  • Updated products page initial props to pass the page query to the API endpoint for the pagination purposes

Now, all get requests to the /api/product will return a product document with the latest 10 comments if there is.
To get the other comments just need to add a new query parameter to product API; page

Sample GET request:
http://localhost:3000/product?_id=5e18a1e67b1ca583dc3a5796
Output: The product detail page with the product which has the last 10 comments and the total comments count.

Sample GET request:
http://localhost:3000/product?_id=5e18a1e67b1ca583dc3a5796&page=2
Output: The product detail page with the product which has the 10 comments after skipping the last 10 and the total comments count.

from class23-project.

msnmz avatar msnmz commented on May 1, 2024

To create a product, now /api/product has a PUT request handler.
The authorization token is required in the headers.
The body must have these properties as shown with sample values:
{ "header": "Twelweth comment", "content": "This is a comment content", "productId": "5e18a1e67b1ca583dc3a5796" }

The backend will respond with a response that is a JSON object:

{
    "totalComments": 4,
    "product": {
        "sku": "797-94-5844",
        "_id": "5e18a1e67b1ca583dc3a5796",
        "name": "Addy Alldre",
        "price": 1999.23,
        "description": "Vestibulum quam sapien, varius ut, blandit non, interdum in, ante. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis faucibus accumsan odio. Curabitur convallis. Duis consequat dui nec nisi volutpat eleifend. Donec ut dolor.",
        "mediaUrl": "https://res-3.cloudinary.com/dwpujv6in/image/upload/c_pad,dpr_2.0,f_auto,h_930,q_auto,w_930/v1/media/catalog/product/c/l/cl1_secktc_cl_view1-cleon-small-sectional-tait-charcoal.jpg",
        "comments": [
            {
                "_id": "5e30e70ff872f6e0cb7baf49",
                "user": {
                    "role": "user",
                    "_id": "5e2f8141aa5fe7ffa77cd9ad",
                    "name": "asd",
                    "email": "[email protected]",
                    "createdAt": "2020-01-28T00:33:05.399Z",
                    "updatedAt": "2020-01-28T00:33:05.399Z",
                    "__v": 0
                },
                "header": "Sixth comment",
                "content": "This is a comment content",
                "updated_at": "2020-01-29T01:59:43.052Z"
            },
            {
                "_id": "5e30e70af872f6e0cb7baf48",
                "user": {
                    "role": "user",
                    "_id": "5e2f8141aa5fe7ffa77cd9ad",
                    "name": "asd",
                    "email": "[email protected]",
                    "createdAt": "2020-01-28T00:33:05.399Z",
                    "updatedAt": "2020-01-28T00:33:05.399Z",
                    "__v": 0
                },
                "header": "Fifth comment",
                "content": "This is a comment content",
                "updated_at": "2020-01-29T01:59:38.710Z"
            },
            {
                "_id": "5e30e706f872f6e0cb7baf47",
                "user": {
                    "role": "user",
                    "_id": "5e2f8141aa5fe7ffa77cd9ad",
                    "name": "asdas",
                    "email": "[email protected]",
                    "createdAt": "2020-01-28T00:33:05.399Z",
                    "updatedAt": "2020-01-28T00:33:05.399Z",
                    "__v": 0
                },
                "header": "Fourth comment",
                "content": "This is a comment content",
                "updated_at": "2020-01-29T01:59:34.320Z"
            },
            {
                "_id": "5e30e6fff872f6e0cb7baf46",
                "user": {
                    "role": "user",
                    "_id": "5e2f8141aa5fe7ffa77cd9ad",
                    "name": "asdasd",
                    "email": "[email protected]",
                    "createdAt": "2020-01-28T00:33:05.399Z",
                    "updatedAt": "2020-01-28T00:33:05.399Z",
                    "__v": 0
                },
                "header": "Third comment",
                "content": "This is a comment content",
                "updated_at": "2020-01-29T01:59:27.070Z"
            }
        ]
    }
}

from class23-project.

msnmz avatar msnmz commented on May 1, 2024

the header is removed from the comment.

from class23-project.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.