English | Russian
git clone git@github.com:zenorachi/todo-service.git
- 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.
- Request example:
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"
}'
- Response example:
{
"id": 1
}
- Request example:
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"
}'
- Response example:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTMzMDc4MjksInN1YiI6IjE0In0.N1QBZb1uVZQGJ7vROHhCdlaySu1o31yjTzFLnVk_XYw"
}
- Request example:
curl -X 'GET' \
'http://localhost:8080/api/v1/auth/refresh' \
-H 'accept: application/json'
- Response example:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTMzMDc4NTIsInN1YiI6IjE0In0.cmXwc15TmNSI2mILSZjoqRhhtUN2AYZQu5had9OW07k"
}
- Request example:
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"
}'
- Response example:
{
"id": 1
}
- Request example:
curl -X 'GET' \
'http://localhost:8080/api/v1/agenda/1' \
-H 'accept: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTU1Nzk1MzYsInN1YiI6IjIifQ.AhqXvtQPHMwp1Pv5Y9m6xXnMITUlRDnGo8oVm5DRvLU'
- Response example:
{
"task": {
"title": "Task 1",
"description": "Description",
"date": "2023-09-26T00:00:00Z",
"status": "not done"
}
}
- Request example:
curl -X 'GET' \
'http://localhost:8080/api/v1/agenda/get_all' \
-H 'accept: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTU1Nzk1MzYsInN1YiI6IjIifQ.AhqXvtQPHMwp1Pv5Y9m6xXnMITUlRDnGo8oVm5DRvLU'
- Response example:
{
"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"
}
]
}
- Request example:
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
}'
- Response example:
{
"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".
- Request example:
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
}'
- Response example:
{
"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"
}
]
}
- Request example:
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
}'
- Response example: None
Hint: if the updating was successful, the server will return code 204 (NO CONTENT).
- Request example:
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
}'
- Response example: None
Hint: if the deleting was successful, the server will return code 204 (NO CONTENT).
- Request example:
curl -X 'DELETE' \
'http://localhost:8080/api/v1/agenda/delete_all' \
-H 'accept: application/json' \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTU1Nzk1MzYsInN1YiI6IjIifQ.AhqXvtQPHMwp1Pv5Y9m6xXnMITUlRDnGo8oVm5DRvLU'
- Response example: None
Hint: if the deleting was successful, the server will return code 204 (NO CONTENT).
- 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