You have been hired by a local restaurant to extend the backend system for managing their online menu. In addition to creating and reading menu items, the restaurant needs the following functionality:
- Update existing menu items in the database.
- Delete menu items that are no longer needed or are discontinued.
Basic express template was given
You need to install all the necessary packages required for the task.
- name (String, required)
- description (String)
- price (Number, required)
- Create a MongoDB Atlas account and set up a free cluster. Use Mongoose to connect your Express server to the MongoDB Atlas cluster.
Implement Update & Delete
-
PUT /menu/:id: Updates an existing menu item.
- Accepts
name,description, andprice(or any subset) in the request body. - Responds with the updated object (or an error message if something goes wrong).
- Accepts
-
DELETE /menu/:id: Deletes an existing menu item.
- Responds with a success message if the item is deleted (or an error if the
idis invalid or not found).
- Responds with a success message if the item is deleted (or an error if the
Error Handling & Validation
- Validate incoming data to ensure required fields are not empty.
- Respond with a descriptive error message if the item cannot be updated or deleted.
Testing
- Use Postman (or a similar tool) to test:
- PUT requests to update an existing menu item.
- DELETE requests to remove a specific menu item.
- You will be provided with a StackBlitz link for the assignment.
- Open the link in your browser and click on the Fork button in StackBlitz.
This will create a copy of the repository in your StackBlitz account.
- After forking, you can download the project or push it directly to your personal GitHub repository:
- Option 1: Download and Push
- Download the repository files from StackBlitz.
- Open your terminal/command prompt, navigate to the project folder, and run:
Replace
git init git remote add origin <your_github_repo_url>
<your_github_repo_url>with your personal GitHub repository URL. - Commit and push the files to your GitHub repository:
git add . git commit -m "Completed the assignment" git push -u origin main
- Option 2: Push Directly
- Use the Push to GitHub option in StackBlitz to directly connect and push the repository to your GitHub account.
- Option 1: Download and Push
- Once your code is successfully pushed to GitHub:
- Copy the link to your GitHub repository.
- Submit the link on the assignment submission portal.
The link should follow this format:
https://github.com/<your_username>/<repository_name>
If your GitHub username is johnDoe and the repository name is assignment-repo, the submission link would look like this:
https://github.com/johnDoe/assignment-repo