A clone of Tokopedia Play (Backend) built using Node.js, Express.js, and MongoDB. This is a project of Fullstack Track in Generasi Gigih 3.0.
Link to the backend repository: tokopediaplay-fe-clone
Consists of 3 collections: Video, Product, and Comment.
Relationship
- Embedding
products
in theVideo
to store list ofproductID
, the product(s) of the video. - Only referencing
videoID
in theComment
document and not embedding it in theVideo
.
Schema
- Video
- _id: ObjectID : Unique ID of the video
- title: String : Title of the video
- urlThumbnail: String : URL of the video thumbnail
- urlVideo: String : URL of the video
- products: Array of ObjectID / : List of productID (embedding), used to populate
{
"_id": <ObjectID>,
"title": String,
"urlThumbnail": String,
"urlVideo": String,
"products": [<ObjectID>, <ObjectID>, ...],
}
- Product
- _id: ObjectID : Unique ID of the product
- videoID: ObjectID : Identifier to the video associated with the product
- linkProduct: String : Link to the product
- title: String : Title of the product
- price: Number : Price of the product
{
"_id": <ObjectID>,
"videoID": <ObjectID>,
"linkProduct": String,
"title": String,
"price": Number,
}
- Comment
- _id: ObjectID : Unique ID of the product
- videoID: ObjectID : Identifier to the video associated with the comment
- username: String : Username of the commenter
- comment: String : Comment text
- createdAt: Date : Date of the comment creation
- updatedAt: Date : Date of the comment update
{
"_id": <ObjectID>,
"videoID": <ObjectID>,
"username": String,
"comment": String,
"createdAt": Date,
"updatedAt": Date,
}
Start with /api/ as the base URL. There are 3 parent endpoints: /videos, /products, and /comments.
- videos
- products
- comments
Returns all videos in the system.
- URL Params
None - Data Params
None - Query Params:
- query-search : String : Search query to filter videos by title
- Headers
Content-Type: application/json - Success Response:
- Code: 200
- Content:
{
videos: [
{<video_object>},
{<video_object>},
{<video_object>}
]
}
- Error Response:
- Code: 500
Content:{ error : error.message }
- Code: 500
Returns the specified video.
- URL Params
Required:videoID=[string]
- Data Params
None - Headers
Content-Type: application/json - Success Response:
- Code: 200
Content:{ <video_object> }
=> with populated products - Error Response:
- Code: 400
Content:{ error : "Invalid VideoID parameter" }
OR - Code: 404
Content:{ error : "Video doesn't exist" }
OR - Code: 500
Content:{ error : error.message }
- Code: 400
Creates a new Video and returns the new object.
- URL Params
None - Headers
Content-Type: application/json - Data Params
{
title: String,
urlThumbnail: String,
urlVideo: String,
}
- Success Response:
- Code: 201
Content:{ <user_object> }
- Error Response:
- Code: 400
Content:OR{ error : "Missing the following fields: *field(s)", emptyFields, }
- Code: 500
Content:{ error : error.message }
- Code: 400
Returns all products of the specified videoID.
- URL Params
Required:videoID=[string]
- Data Params
None - Headers
Content-Type: application/json - Success Response:
- Code: 200
- Content:
{
products: [
{<product_object>},
{<product_object>},
{<product_object>}
]
}
- Error Response:
- Code: 400
Content:{ error : "Invalid VideoID parameter" }
OR - Code: 404
Content:{ error : "Video doesn't exist" }
OR - Code: 500
Content:{ error : error.message }
- Code: 400
Returns all comments of the specified videoID.
- URL Params
Required:videoID=[string]
- Data Params
None - Headers
Content-Type: application/json - Success Response:
- Code: 200
- Content:
{
amount: Number,
comments: [
{<comment_object>},
{<comment_object>},
{<comment_object>}
]
}
- Error Response:
- Code: 400
Content:{ error : "Invalid VideoID parameter" }
OR - Code: 404
Content:{ error : "Video doesn't exist" }
OR - Code: 500
Content:{ error : error.message }
- Code: 400
Creates a new Product and returns the new object.
- URL Params
None - Data Params
{
videoID: String,
linkProduct: String,
title: String,
price: String,
}
- Headers
Content-Type: application/json - Success Response:
- Code: 201
- Content:
{ <product_object> }
- Error Response:
- Code: 400
Content:OR{ error : "Missing the following fields: *field(s)", emptyFields, }
- Code: 404
Content:{ error : "Unable to add the product because the video doesn't exist" }
OR - Code: 500
Content:{ error : error.message }
- Code: 400
Creates a new Comment and returns the new object.
- URL Params
None - Data Params
{
videoID: String,
username: String,
comment: String,
}
- Headers
Content-Type: application/json - Success Response:
- Code: 201
- Content:
{
status: "Success",
comment: {<comment_object>}
}
- Error Response:
- Code: 400
- Content:
OR{ status: "Fail", error : "Missing the following fields: *field(s)", emptyFields, }
- Code: 404
Content:{ status: "Fail", error : "Unable to add the product because the video doesn't exist" }
OR - Code: 500
Content:{ status: "Fail", error : error.message }
Pre-requisites: Node.js, npm, MongoDB
- Clone the Repository
- Open terminal to that repo then Install Dependencies
npm install
- Rename .env.example file into .env
- In .env file, change the value of ORIGIN to your frontend URL, MONGO_URI to your MongoDB URI, and PORT to your desired port number
- (OPTIONAL) You can seed the database with sample data, it will delete all existing data in the database and replace it with the sample data
npm run seed:local
- Run the server using the following command
npm run dev
- Websocket for real-time comments
- Search feature for videos