--- id: express-mongo-exercise author: Vinh Duong, Tuan Hoang --- # CoderCars *Cars listing API for practicing express and mongobdb:car: .* ## Overview For this exercise, you are going to build an api with Node, Express, and Mongo. You will be practicing all the keys concept that learnt in this topic. Including collect and process dataset, building schema, design endpoints of a CRUD process .. As for the front end with React , we already have a version for you. However, feel free to make your own version and turn this into a Full Stack M.E.R.N (Mongo, Express, React and Node) project. ## Description You are building a backend server with enpoints that allow: - CREATE: User can add new cars to the database. - READ: User can see a paginated list of all the cars in the database. - UPDATE: User can edit existing cars. - DELETE: User can delete cars. Update the api request in the [Front end repo](https://github.com/coderschool/codercars-fe) with your work. Checkout this [demo](https://codercars.netlify.app/) for references. ## Feature requirements ### Get list of cars ![](https://i.imgur.com/xvBsd2z.jpg) - As users visit the page, the front-end will make a Get request to the backend server to read all information of car. - User see cars infos includes name, style, size,tranmission type, price, year - User see buttons to interact with each car (Edit/Delete) - User see a portion of the result only and able to paginate through ### Add new car ![](https://i.imgur.com/ogeWERI.jpg) - User can create a new car with infos - User can see the added car imediately and in all future reading request. ### Edit a car ![](https://i.imgur.com/4karJud.jpg) - User can edit a specific car infos - User can see this update imediately and in any future reading request ### Delete a car* ![](https://i.imgur.com/qgF9OfO.png) - User can delete a car - User can no longer see the deleted car imediately and in any future reading request. - **Note:** The simplest form of delete process is to , well, delete. Meaning removing something out of your database. This is call hard delete. However, in real life programming, we usually prefer soft delete when making this function. In soft delete, we assume delete is simply a status of a document. By changing it status and combine with filter condition when query, we could achieve the same result. One of the reason for this is that data is precious and remove something for good is dangerous. What if we want to undo ? restore ? ... re-activate your deactivated facebook account? For now, let's just try building hard delete controller to your api then challenge your self with the rockets later. ### Rocket :rocket: - Turn hard delete into soft delete - <details> <summary>Hints</summary> -> try adding isDeleted to each car. Then make sure all re </details> - Make a full stack search by car name feature. ## Starter ### Template To help you get start quick and effectively, here is the template for your [backend project](https://github.com/coderschool/codercars-be). ### Instructions - Clone the template - Checkout to template branch - Rename .`env.example` to `.env` and supply your own `MongoDB URI` or leave as is to use your `local MongoDB URI`. - Based on the provided schema, parse and import the data from [this dataset](https://www.kaggle.com/datasets/CooperUnion/cardataset) into your database. - Fill in the missing logic in the controller. Remember to consider and handle all possible errors. - Test and make sure it works with the provided frontend. - Use Thunder or Postman or any other client to ease your development process. ## Endpoints Here are the response structure according to each endpoint. ### CREATE `POST /car` Expected body of request: ```json= { "make": "Plymouth", "model": "Colt", "release_date": 2002, "transmission_type": "MANUAL", "size": "Compact", "style": "Coupe", "price": 23000 } ``` Expected response: ```json= { "message": "Create Car Successfully!", "car": { "make": "Plymouth", "model": "Colt", "release_date": 2002, "transmission_type": "MANUAL", "size": "Compact", "style": "Coupe", "price": 23000, } } ``` ### READ `GET /car` Expected response: ```json= { "message": "Get Car List Successfully!", "cars": [ //car objects ], "page": 1, // total pages "total": 1192 } ``` ### UPDATE `PUT /car/:id` Expected response: ```json= { "message": "Update Car Successfully!", { //car object } } ``` ### DELETE `DELETE /car/:id` Expected response: ```json= { "message": "Delete Car Successfully!", { //car object } } ``` ## The end. You will start this project with 120/100 points. Pass grade is 80. | Grade | Description | | ----- | ----------------------------------------------------- | | - 5 | Missing rocket | | - 5 | Response data structure incorrect lead to error in front-end app | | | - 10 | Missing any of other requirements that are not rocket | Don't worry if you fail this assignment, as we allowing unlimited attempts. Good luck have fun coding !