Gopher ToDo List API is a REST API developed to manage a to-do list. The API was developed using Go and PostgreSQL. The API is available on Render.
I developed this API with the purpose of putting into practice my studies of the Go language, as well as my knowledge of software architecture. In this specific API, I used the clean architecture to separate the responsibilities of each layer of the application and make it more decoupled. In this API, it's possible to replace, for example, the database without many side effects, since everything is interconnected through interfaces.
The project was developed using the following technologies:
To run the project locally, you must have installed:
- Go - v1.20
- PostgreSQL - (or use Docker)
To run the project into a container, you must have installed:
-
Clone this repository and install all dependencies.
$ git clone https://https://github.com/WillianBL99/gopher-todo-list.git $ cd gopher-todo-list $ go mod download
-
Create and configure the
.env
file based on the.env.example
file. -
Create a PostgreSQL database with any name you like, or create a container with Docker. The repository contains the
create-tables.sql
file that is ininternal/infra/db/postgresql
for creating the tables. Remember to correctly configure the.env
file.# Create tables with the create-tables.sql file $ psql -U postgres -d <database-name> -a -f create-tables.sql # Or create a container with Docker $ docker run --name <container-name> -e POSTGRES_PASSWORD=<password> -p 5432:5432 -d postgres
-
Run the API
$ go run ./cmd/todolist
The API will display Server running on port <port>
, if everything is correct.
-
Run the command below to run the tests.
$ go test ./...
There are two ways to run the API using docker. The first is running the script start.sh
that is in the root of the project. The second is running the docker-compose file.
-
Run the command below to run the script.
# Give permission to the script $ chmod +x start.sh # Run the script $ ./start.sh
-
Run the command below to run the docker-compose file.
$ docker-compose up
-
Create the tables in the database.
$ docker exec -it pg_db psql -U postgres -d todo_list -a -f create-tables.sql
-
Run the command below to run the tests.
$ docker exec -it go_api go test ./...
For to run the API in production, you must have installed Docker and Docker Compose.
-
Update the
.env
file with the production environment variables. Provide the connection variables to the PostgreSQL database. -
Run the command below to run the docker-compose file.
$ docker-compose -f docker-compose.prod.yml up
Above are the available routes in the API. For more details, see the documentation available at gopher-todolist.onrender.com.
GET /
: See the API documentation.GET /health
: Check the API health.
POST /auth/sign-up
: Create a new user.POST /auth/sign-in
: Authenticate a user.
GET /tasks
: Get all tasks.POST /task
: Create a new task.GET /task/{id}
: Get a task by id.PUT /task/{id}
: Update a task by id.PATCH /task/{id}/done
: Mark a task as done.PATCH /task/{id}/undone
: Mark a task as undone.DELETE /task/{id}
: Delete a task by id.
The repository has some scripts to automate some processes.
-
start.sh
: [Linux] Script to start the API. It's possible to start the API and execute the cron jobs to generate the backups of the database.# Start the API $ ./start.sh # Or start the API and execute cron jobs $ ./start.sh --cron
-
cron.sh
: [Linux] Script to execute the cron jobs to generate the backups of the database.# Execute cron jobs $ ./cron.sh # Execute cron jobs and set the time interval $ ./cron.sh -t 3 # 3 hours # Or execute cron jobs only once $ ./cron.sh -o
- Add unit tests for the use cases
- Add unit tests for the repository implementation
- Add unit tests for the controllers
- Add unit tests for the handlers
- Add integration tests
- Add OAuth2 authentication
- Dockerize the API
- Integrate with logging tools
- Add CI/CD
This project is under the MIT license
Desenvolvido por Paulo Uilian Barros Lago🧑🏻💻