Skip to content

zenorachi/todo-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang License

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

  1. 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).

  1. Compile and run the project:
make
  1. 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

  • 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
}

2. Authentication

  • 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"
}

3. Refresh token

  • Request example:
curl -X 'GET' \
  'http://localhost:8080/api/v1/auth/refresh' \
  -H 'accept: application/json'
  • Response example:
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTMzMDc4NTIsInN1YiI6IjE0In0.cmXwc15TmNSI2mILSZjoqRhhtUN2AYZQu5had9OW07k"
}

Agenda

1. Create task

  • 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
}

2. Get task by ID

  • 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"
   }
}

3. Get all user tasks

  • 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"
      }
  ]
}

4. Get all tasks with pagination and specific status

  • 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".

5. Get all tasks by date

  • 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"
      }
   ]
}

6. Set task status

  • 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).

7. Delete task by ID

  • 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).

8. Delete all user tasks

  • 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).


Additional features

  1. Run tests
make test
  1. Run the linter
make lint
  1. Create migration files
make migrate-create
  1. Migrations up / down
make migrate-up
make migrate-down
  1. Stop all running containers
make stop

About

Simple TO-DO application written in Golang.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages