TaskManagerAPI is a backend application built using Go (Golang) to manage users, projects, and tasks. The API is designed to handle typical operations like creating, updating, deleting, and retrieving data for users, projects, and tasks. It uses PostgreSQL as the database and GORM as the ORM.
- User Management: Create, retrieve, update, and delete users.
- Project Management: Create, retrieve, update, and delete projects.
- Task Management: Create, retrieve, update, and delete tasks.
- Relational Data: Projects belong to users, and tasks belong to projects.
- Go: Version 1.20 or higher
- Docker: For containerized PostgreSQL and application
- Make: To streamline project commands
-
Clone the repository:
git clone https://github.com/talyx/TaskManagerApi.git cd TaskManagerApi
-
Start PostgreSQL using Docker:
make up
This will run PostgreSQL in a Docker container.
-
Install dependencies:
go mod tidy
-
Start the application in debug mode:
make run-debug
-
Start the application in production mode:
make run-production
The server will run on
http://localhost:8005
by default.
make up
: Start PostgreSQL in a Docker containermake down
: Stop and remove PostgreSQL containermake psql
: To connect to a container with PostgreSQL and start an interactive psql sessionmake status
: To check the status of a database containermake reset-db:
: To reset database containermake run-debug
: Run the application in debug modemake run-production
: Run the application in production mode
Below are the available API endpoints for managing Users, Projects, and Tasks.
Method | Endpoint | Description | Request Body |
---|---|---|---|
POST | /register |
Create a new user | { "names": "John Doe", "email": "[email protected]", "passwordhash": "securepassword"} |
GET | /users |
Retrieve all users | |
GET | /user/{id} |
Retrieve a user by ID | |
PUT | /user/{id} |
Update a user by ID | { "names": "Jane Doe", "email": "[email protected]", "passwordhash": "newpassword"} |
DELETE | /user/{id} |
Delete a user by ID |
Note: When creating a user, the passwordhash
field should contain a securely hashed password.
Method | Endpoint | Description | Request Body |
---|---|---|---|
POST | /project |
Create a new project | { "name": "Project Alpha", "description": "This is the first project."} |
GET | /projects |
Retrieve all projects | |
GET | /project/{id} |
Retrieve a project by ID | |
PUT | /project/{id} |
Update a project by ID | { "name": "Project Beta", "description": "Updated project description."} |
DELETE | /project/{id} |
Delete a project by ID |
Note: The UserID
is automatically associated with the authenticated user when creating a project.
Method | Endpoint | Description | Request Body |
---|---|---|---|
POST | /task |
Create a new task | { "title": "Task One", "description": "This is the first task.", "ProjectID": 1} |
GET | /tasks |
Retrieve all tasks | |
GET | /task/{id} |
Retrieve a task by ID | |
PUT | /task/{id} |
Update a task by ID | { "name": "Task Two", "description": "Updated task description."} |
DELETE | /task/{id} |
Delete a task by ID |
Note: The ProjectID
field is used to associate the task with a specific project.
- Authentication: Most endpoints require authentication. Use the
/login
endpoint to obtain a session or token. - Authorization: Ensure that the authenticated user has the necessary permissions to perform actions on resources.
curl -X POST http://localhost:8005/register \
-H "Content-Type: application/json" \
-d '{
"names": "John Doe",
"email": "[email protected]",
"passwordhash": "securepassword"
}'
curl -v -X POST http://localhost:8005/login \
-H "Content-type: application/json" \
-d '{"login":"[email protected]", "password":"securepassword"}' \
-c cookies.txt
curl -X GET http://localhost:8005/users -b cookies.txt
curl -X POST http://localhost:8005/project \
-H "Content-Type: application/json" \
-d '{
"name": "Project Alpha",
"description": "This is the first project."
}' \
-b cookies.txt
curl -X GET http://localhost:8005/projects -b cookies.txt
curl -X POST http://localhost:8005/task \
-H "Content-Type: application/json" \
-d '{
"title": "Task One",
"description": "This is the first task.",
"ProjectID": 1
}' \
-b cookies.txt
curl -X GET http://localhost:8005/tasks/1 -b cookies.txt