
TO-DO service
A microservice written in the Go programming language is designed to plan your daily tasks.
English | Russian
Technologies used:
Navigation
Installation
git clone git@github.com:zenorachi/todo-service.git
Getting started
- Setting up environment variables (create a .env file in the project root):
# Database
export DB_HOST=
export DB_PORT=
export DB_USER=
export DB_NAME=
export DB_SSLMODE=
export DB_PASSWORD=
# Local database
export LOCAL_DB_PORT=
# Postgres service
export POSTGRES_PASSWORD=
# Password Hasher
export HASH_SALT=
export HASH_SECRET=
# GIN mode (optional, default - release)
export GIN_MODE=
Hint:
if you are running the project using Docker, set DB_HOST
to "postgres" (as the service name of Postgres in the docker-compose).
- Compile and run the project:
make
- To test the service's functionality, you can navigate to the address
http://localhost:8080/docs/index.html to access the Swagger documentation.
Hint: to complete the authorization in Swagger UI after receiving the JWT token, you need
to enter Bearer <your_token>
(without "<" and ">" symbols) in the input field.
Examples of requests
Users
1. Registration
curl -X 'POST' \
'http://localhost:8080/api/v1/auth/sign-up' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"login": "maksim-go",
"email": "maksim-go@gmail.com",
"password": "qwerty123"
}'
{
"id": 1
}
2. Authentication
curl -X 'POST' \
'http://localhost:8080/api/v1/auth/sign-in' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"login": "maksim-go",
"password": "qwerty123"
}'
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTMzMDc4MjksInN1YiI6IjE0In0.N1QBZb1uVZQGJ7vROHhCdlaySu1o31yjTzFLnVk_XYw"
}
3. Refresh token
curl -X 'GET' \
'http://localhost:8080/api/v1/auth/refresh' \
-H 'accept: application/json'
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTMzMDc4NTIsInN1YiI6IjE0In0.cmXwc15TmNSI2mILSZjoqRhhtUN2AYZQu5had9OW07k"
}
Agenda
1. Create task
curl -X 'POST' \
'http://localhost:8080/api/v1/agenda/create' \
-H 'accept: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTU1Nzk1MzYsInN1YiI6IjIifQ.AhqXvtQPHMwp1Pv5Y9m6xXnMITUlRDnGo8oVm5DRvLU' \
-H 'Content-Type: application/json' \
-d '{
"date": "2023-Sep-26",
"description": "Description",
"status": "not done",
"title": "Task 1"
}'
{
"id": 1
}
2. Get task by ID
curl -X 'GET' \
'http://localhost:8080/api/v1/agenda/1' \
-H 'accept: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTU1Nzk1MzYsInN1YiI6IjIifQ.AhqXvtQPHMwp1Pv5Y9m6xXnMITUlRDnGo8oVm5DRvLU'
{
"task": {
"title": "Task 1",
"description": "Description",
"date": "2023-09-26T00:00:00Z",
"status": "not done"
}
}
3. Get all user tasks
curl -X 'GET' \
'http://localhost:8080/api/v1/agenda/get_all' \
-H 'accept: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTU1Nzk1MzYsInN1YiI6IjIifQ.AhqXvtQPHMwp1Pv5Y9m6xXnMITUlRDnGo8oVm5DRvLU'
{
"tasks": [
{
"id": 1,
"title": "Task 1",
"description": "Description",
"date": "2023-09-26T00:00:00Z",
"status": "not done"
},
{
"id": 2,
"title": "Task 2",
"description": "Description",
"date": "2023-09-26T00:00:00Z",
"status": "not done"
}
]
}
4. Get all tasks with pagination and specific status
curl -X 'GET' \
'http://localhost:8080/api/v1/agenda/get_by_date?page=5&status=done' \
-H 'accept: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTU1Nzk1MzYsInN1YiI6IjIifQ.AhqXvtQPHMwp1Pv5Y9m6xXnMITUlRDnGo8oVm5DRvLU' \
-H 'Content-Type: application/json' \
-d '{
"limit": 2,
"offset": 2
}'
{
"tasks": [
{
"id": 1,
"title": "some task2",
"description": "desc",
"date": "2023-09-26T00:00:00Z",
"status": "done"
},
{
"id": 2,
"title": "some task3",
"description": "desc",
"date": "2023-09-26T00:00:00Z",
"status": "done"
}
]
}
Hint: by default, the status is set to "not done".
5. Get all tasks by date
curl -X 'GET' \
'http://localhost:8080/api/v1/agenda/get_by_date' \
-H 'accept: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTU1Nzk1MzYsInN1YiI6IjIifQ.AhqXvtQPHMwp1Pv5Y9m6xXnMITUlRDnGo8oVm5DRvLU' \
-H 'Content-Type: application/json' \
-d '{
"date": "2023-Sep-26",
"limit": 5,
"offset": 1
}'
{
"tasks": [
{
"id": 1,
"title": "some task1",
"description": "desc",
"date": "2023-09-26T00:00:00Z",
"status": "not done"
},
{
"id": 2,
"title": "some task2",
"description": "desc",
"date": "2023-09-26T00:00:00Z",
"status": "not done"
},
{
"id": 3,
"title": "some task3",
"description": "desc",
"date": "2023-09-26T00:00:00Z",
"status": "not done"
}
]
}
6. Set task status
curl -X 'PUT' \
'http://localhost:8080/api/v1/agenda/set_status' \
-H 'accept: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTU1Nzk1MzYsInN1YiI6IjIifQ.AhqXvtQPHMwp1Pv5Y9m6xXnMITUlRDnGo8oVm5DRvLU' \
-H 'Content-Type: application/json' \
-d '{
"status": "done",
"task_id": 10
}'
Hint: if the updating was successful, the server will return code 204 (NO CONTENT).
7. Delete task by ID
curl -X 'DELETE' \
'http://localhost:8080/api/v1/agenda/delete_by_id' \
-H 'accept: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTU1Nzk1MzYsInN1YiI6IjIifQ.AhqXvtQPHMwp1Pv5Y9m6xXnMITUlRDnGo8oVm5DRvLU' \
-H 'Content-Type: application/json' \
-d '{
"task_id": 10
}'
Hint: if the deleting was successful, the server will return code 204 (NO CONTENT).
8. Delete all user tasks
curl -X 'DELETE' \
'http://localhost:8080/api/v1/agenda/delete_all' \
-H 'accept: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTU1Nzk1MzYsInN1YiI6IjIifQ.AhqXvtQPHMwp1Pv5Y9m6xXnMITUlRDnGo8oVm5DRvLU'
Hint: if the deleting was successful, the server will return code 204 (NO CONTENT).
Additional features
- Run tests
make test
- Run the linter
make lint
- Create migration files
make migrate-create
- Migrations up / down
make migrate-up
make migrate-down
- Stop all running containers
make stop