Git Product home page Git Product logo

tokopedia-play-clone-server's Introduction

Tokopedia Play API

This API is a back-end service for a Tokopedia Play platform. It uses a MongoDB database to store video, product, and comment data. It utilizes Express.js for request routing, and socket.io for real-time updates of comments.

Database Structure

The database consists of three collections, each represented by a Mongoose schema:

  • Video: Stores details about each video, including a URL image, a thumbnail, and a unique video ID.

  • Product: Stores details about products associated with a video, such as a link to the product, the product's title, its price, and a reference to the associated video ID.

  • Comment: Stores comments made on a video. Each comment includes a username, the comment text, a timestamp of when the comment was made, and a reference to the associated video ID.

API Structure

The API is a RESTful API with endpoints for creating, retrieving, updating, and deleting Videos, Products, and Comments.

API Request and Response

Categories

Get all categories.

GET /categories

Response

{
    "_id": "ObjectId",
    "name": "string",
    "createdAt": "date",
    "updatedAt": "date",
},

POST /categories

Request

{
    "name": "string"
}

Videos

GET /videos Get all videos.

Response

[
    {
        "urlImage": "string",
        "thumbnail": "string",
        "_id": "ObjectId",
    },
    ...
]

POST /videos Create a new video.

Request

{
    "urlImage": "string",
    "thumbnail": "string",
}

Response

{
    "message": "Success"
}

PUT /videos/:id Updates a video.

Request

{
    "urlImage": "string",
    "thumbnail": "string",
}

Response

{
    "message": "Success",
    "video": {
        "urlImage": "string",
        "thumbnail": "string",
        "_id": "ObjectId",
    }
}

DELETE /videos/:id Deletes a video.

Response

{
    "message": "Success"
}

GET /videos/:id/views Get views.

Response

{
    message: "Views incremented",
    views: number
}

GET /videos/search Get videos search.

Query Params: search: string
{
    status: "200 OK",
    body: "Array of Video objects"
}

GET /videos/category/:categoryId Get videos by category.

{
    status: "200 OK",
    body: "Array of Video objects with populated categories"
}

Products

GET /products/:videoID Gets all products associated with a video.

Response

{
    "linkProduct": "string",
    "title": "string",
    "price": 0,
    "videoID": "ObjectId",
},

POST /products Creates a new product.

Request

{
    "linkProduct": "string",
    "title": "string",
    "price": 0,
    "videoID": "ObjectId",
},

Response


{
    "message": "Success"
}

PUT /products/:id Updates a product.

Request

{
    "linkProduct": "string",
    "title": "string",
    "price": 0,
    "videoID": "ObjectId",
}

Response

{
    "message": "Success",
    "product": {
        "linkProduct": "string",
        "title": "string",
        "price": 0,
        "videoID": "ObjectId",
    }
}

DELETE /products/:id Deletes a product.

Response


{
    "message": "Success"
}

Comments

GET /comments/:videoID Gets all comments for a video.

Response

{
    "username": "string",
    "comment": "string",
    "timestamp": "date",
    "videoID": "ObjectId",
},
...


POST /comments Creates a new comment.

Request

{
    "username": "string",
    "comment": "string",
    "videoID": "ObjectId",
}

Response

{
    "message": "Success"
}

PUT /comments/:id Updates a comment.

Request

{
    "username": "string",
    "comment": "string",
}

Response

{
    "message":
        "Success",
        "comment": {
            "username": "string",
            "comment": "string",
            "timestamp": "date",
            "videoID": "ObjectId",
        }
}

DELETE /comments/:id Deletes a comment.

Response

{
    "message": "Success"
}

How to Run Locally

Follow these steps to run this API locally:

  1. Clone this repository to your local machine.
  2. Navigate into the project directory:
cd project-directory
  1. Install the necessary dependencies:
npm install
  1. Setup environment variables by creating a .env file in the root directory. It should contain the following:
PORT=5000
MONGO_URL=your_mongodb_url
  1. Replace your_mongodb_url with your actual MongoDB connection URL.
  2. Run the server:
npm run dev

The server should now be running on:

http://localhost:5000.

tokopedia-play-clone-server's People

Contributors

rifkiramadhan avatar

Stargazers

 avatar

Watchers

 avatar

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.