A Go-based task management application that interfaces with MongoDB. This console application allows you to manage tasks using a REST API built with Gin. Tasks are stored and managed in MongoDB.
- CRUD Operations: Create, Read, Update, and Delete tasks.
- Persistent Storage: Tasks are stored in a MongoDB database.
- Error Handling: Consistent error responses and handling.
- Go 1.18 or higher
- MongoDB (local or remote instance)
go.mongodb.org/mongo-driverpackage for MongoDB integrationgithub.com/gin-gonic/ginpackage for RESTful routing
-
Clone the repository:
git clone [https://github.com/Simret101/TaskManagementWithMongodb]
-
Navigate to the project directory:
cd task-manager-console -
Install dependencies:
go mod tidy
-
Build the application:
go build -o task-manager
-
MongoDB URI: Update the MongoDB URI in
main.goto point to your MongoDB instance.mongoURI := "mongodb://localhost:27017"
-
Run the application:
./task-manager
-
API Endpoints:
- GET
/tasks: Retrieve all tasks. - GET
/tasks/:id: Retrieve a task by ID. - POST
/tasks: Create a new task. Requires JSON payload withtitle,description,duedate, andstatus. - PUT
/tasks/:id: Update an existing task by ID. Requires JSON payload with updated task details. - DELETE
/tasks/:id: Delete a task by ID.
- GET
curl -X POST http://localhost:9090/tasks -H "Content-Type: application/json" -d '{"title": "Finish project", "description": "Complete the project by end of the month", "duedate": "2024-08-31", "status": "inprogress"}'curl http://localhost:9090/taskscurl http://localhost:9090/tasks/your_task_idcurl -X PUT http://localhost:9090/tasks/your_task_id -H "Content-Type: application/json" -d '{"title": "Updated title", "description": "Updated description", "duedate": "2024-09-01", "status": "completed"}'curl -X DELETE http://localhost:9090/tasks/your_task_idThe application returns appropriate HTTP status codes and messages for various errors:
- 404 Not Found: When a task is not found.
- 400 Bad Request: For invalid input data.
- 500 Internal Server Error: For unexpected server errors.
-
Test API Endpoints: Use tools like Postman or
curlto test the CRUD operations. -
Direct MongoDB Queries: Verify data using MongoDB Compass or the MongoDB shell.
Feel free to fork the repository and submit pull requests for improvements or bug fixes.