git clone https://github.com/pintoter/todo-list.git
- Create .env file with filename ".env" in the project root and setting up environment your own variables:
# Database
export DB_USER = "user"
export DB_PASSWORD = "123456"
export DB_HOST = "postgres"
export DB_PORT = 5432
export DB_NAME = "dbname"
export DB_SSLMODE = "disable"
# Local database
export LOCAL_DB_PORT = 5432
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/swagger/index.html to access the Swagger documentation.
-
Project's structure
.
├── Dockerfile
├── Dockerfile.debug
├── Makefile
├── README.md
├── bin
├── cmd
│ └── app
│ └── main.go
├── configs
│ └── main.yml
├── docker-compose.debug.yml
├── docker-compose.yml
├── docs
│ ├── docs.go
│ ├── swagger.json
│ └── swagger.yaml
├── go.mod
├── go.sum
├── internal
│ ├── app
│ │ └── app.go
│ ├── config
│ │ └── config.go
│ ├── database
│ │ └── migrations.go
│ ├── entity
│ │ ├── errors.go
│ │ ├── note.go
│ │ ├── repository.go
│ │ ├── session.go
│ │ └── user.go
│ ├── repository
│ │ ├── dbrepo
│ │ │ ├── notes_create.go
│ │ │ ├── notes_create_test.go
│ │ │ ├── notes_delete.go
│ │ │ ├── notes_delete_test.go
│ │ │ ├── notes_get.go
│ │ │ ├── notes_get_test.go
│ │ │ ├── notes_update.go
│ │ │ ├── notes_update_test.go
│ │ │ ├── repository.go
│ │ │ ├── users.go
│ │ │ ├── users_create.go
│ │ │ ├── users_create_test.go
│ │ │ ├── users_get.go
│ │ │ ├── users_get_test.go
│ │ │ ├── users_set_session.go
│ │ │ └── users_set_session_test.go
│ │ └── repository.go
│ ├── server
│ │ └── server.go
│ ├── service
│ │ ├── mocks
│ │ │ └── mock.go
│ │ ├── notes.go
│ │ ├── service.go
│ │ └── users.go
│ └── transport
│ ├── handler.go
│ ├── middleware.go
│ ├── notes.go
│ ├── notes_test.go
│ ├── request.go
│ ├── response.go
│ └── users.go
├── migrations
│ ├── 20231128193639_create_notes.down.sql
│ ├── 20231128193639_create_notes.up.sql
│ ├── 20231218171050_create_users.down.sql
│ └── 20231218171050_create_users.up.sql
└── pkg
├── auth
│ └── manager.go
├── database
│ └── postgres
│ └── postgres.go
├── hash
│ └── hash.go
└── logger
└── logger.go
"title": "any, unique",
"description": "any",
"status": "done" / "not_done",
"date": "YYYY-MM-DD, e.g.: 2023-01-29",
"limit": "any, not negative"
- Request example:
curl -X 'POST' \
'http://localhost:8080/api/v1/note' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"date": "2020-02-20",
"description": "one description",
"status": "not_done",
"title": "one title"
}'
- Response example:
{
"message": "note created successfully"
}
- Request example:
curl -X 'GET' \
'http://localhost:8080/api/v1/note/1' \
-H 'accept: application/json'
- Response example:
{
"note": {
"title": "one title",
"description": "one description",
"date": "2020-02-20T00:00:00Z",
"status": "not_done"
}
}
- Request example:
curl -X 'PATCH' \
'http://localhost:8080/api/v1/note/2' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"description": "any",
"status": "not_done",
"title": "one title"
}'
- Response example:
{
"error": "note already exists with title: one title"
}
Hint: You can update partially (not all fields). if you want to update to an existing title, you will receive an error, as in the example above, otherwise:
{
"message": "note updated successfully"
}
- Request example:
curl -X 'DELETE' \
'http://localhost:8080/api/v1/note/1' \
-H 'accept: application/json'
- Response example:
{
"message": "note deleted succesfully"
}
- Request example:
curl -X 'GET' \
'http://localhost:8080/api/v1/notes' \
-H 'accept: application/json'
- Response example:
{
"notes": [
{
"id": 1,
"title": "one title",
"description": "one description",
"date": "2020-02-20T00:00:00Z",
"status": "not_done"
},
{
"id": 2,
"title": "two title",
"description": "two description",
"date": "2020-02-20T00:00:00Z",
"status": "not_done"
},
{
"id": 3,
"title": "three title",
"description": "three description",
"date": "2020-02-20T00:00:00Z",
"status": "not_done"
},
]
}
- Request example:
curl -X 'DELETE' \
'http://localhost:8080/api/v1/notes' \
-H 'accept: application/json'
- Response example:
{
"message": "notes deleted succesfully"
}
- Request example:
curl -X 'POST' \
'http://localhost:8080/api/v1/notes/1' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"date": "2020-02-20",
"limit": 0,
"status": "not_done"
}'
- Response example:
{
"notes": [
{
"id": 1,
"title": "one title",
"description": "one description",
"date": "2020-02-20T00:00:00Z",
"status": "not_done"
},
{
"id": 2,
"title": "two title",
"description": "two description",
"date": "2020-02-20T00:00:00Z",
"status": "not_done"
},
{
"id": 3,
"title": "three title",
"description": "three description",
"date": "2020-02-20T00:00:00Z",
"status": "not_done"
}
]
}
Hint: you can update partially (without any fields).
- Run tests
make test
- Create migration files
make migrate-create
- Migrations up / down
make migrate-up
make migrate-down
- Stop all running containers
make stop
- Run linter
make lint