This project consists in registering a user and checking some of it's data. The main idea of the architecture was based on the Clean Architecture, so I chose to follow the Hexagonal Architecture.
- It was only tested on Linux.
- Make
- Python 3.8+
- pyenv
This project uses Makefile
as automation tool. Replace edu-loan
label to your project name.
The following commands will install and set-up pyenv
tool (https://github.com/pyenv/pyenv) used to create/manage virtual environments:
Just replace
zshrc
with the configuration file of your interpreter, likebashrc
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc
$ exec "$SHELL"
$ git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
$ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshrc
$ exec "$SHELL"
After that, access the project directory and execute make create-venv
to create and recreate the virtual environment.
The environment will be create in your home directory:
$PROJECT_NAME
and$PYTHON_VERSION
are variables defined in the Makefile
$HOME/.pyenv/versions/$PROJECT_NAME-$PYTHON_VERSION/bin/python
/home/renan/.pyenv/versions/edu-loan-3.8.5/bin/python
- Tests will run with coverage minimum at 80%.
Running code style
➜ make code-convention
Running unit tests
➜ make test
Running code style and all tests
➜ make
There are some ways to run this project.
First, we need to setup a database. For this test we are just using a simple sqlite database.
➜ make setup-db
Now we can run the server, those are the options:
➜ flask run
or
➜ python wsgi.py
or
➜ make run
The server is accessible at the link below, despite there is no root endpoint:
The endpoints available are:
Creates the event flow
The idea here is that, each event represents the last part of the users endpoints. So this endpoint must be the first one executed, prior to any user registrations.
➜ curl -X POST http://127.0.0.1:5000/api/v1/event-flow -d '{"event_flow": ["cpf", "full-name", "birthday", "phone", "address", "amount"]}' -H 'Content-Type: application/json'
Registers a user
➜ curl -X POST http://127.0.0.1:5000/api/v1/auth/register -d '{"email": "juca@juca.com", "password": "mypass"}' -H 'Content-Type: application/json'
Login a user
➜ curl -X POST http://127.0.0.1:5000/api/v1/auth/login -d '{"email": "juca@juca.com", "password": "mypass"}' -H 'Content-Type: application/json'
Adds user CPF
➜ curl -X POST http://127.0.0.1:5000/api/v1/users/cpf -d '{"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6Imp1Y2FAanVjYS5jb20ifQ.RYgkYNzp43tXo9xLDfUFu4w4EMjuGhgjmZEv7WA16cY", "data": "68077335004"}' -H 'Content-Type: application/json'
Adds user Full Name
➜ curl -X POST http://127.0.0.1:5000/api/v1/users/full-name -d '{"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6Imp1Y2FAanVjYS5jb20ifQ.RYgkYNzp43tXo9xLDfUFu4w4EMjuGhgjmZEv7WA16cY", "data": "Juca da Silva"}' -H 'Content-Type: application/json'
Adds user Birthday
➜ curl -X POST http://127.0.0.1:5000/api/v1/users/birthday -d '{"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6Imp1Y2FAanVjYS5jb20ifQ.RYgkYNzp43tXo9xLDfUFu4w4EMjuGhgjmZEv7WA16cY", "data": "2020-03-07"}' -H 'Content-Type: application/json'
Adds user Phone
➜ curl -X POST http://127.0.0.1:5000/api/v1/users/phone -d '{"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6Imp1Y2FAanVjYS5jb20ifQ.RYgkYNzp43tXo9xLDfUFu4w4EMjuGhgjmZEv7WA16cY", "data": "51999999999"}' -H 'Content-Type: application/json'
Adds user Address
➜ curl -X POST http://127.0.0.1:5000/api/v1/users/address -d '{"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6Imp1Y2FAanVjYS5jb20ifQ.RYgkYNzp43tXo9xLDfUFu4w4EMjuGhgjmZEv7WA16cY", "data": "88035150,servid,22,apto 605,floripa,sc"}' -H 'Content-Type: application/json'
Adds user Amount
➜ curl -X POST http://127.0.0.1:5000/api/v1/users/amount -d '{"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6Imp1Y2FAanVjYS5jb20ifQ.RYgkYNzp43tXo9xLDfUFu4w4EMjuGhgjmZEv7WA16cY", "data": "123"}' -H 'Content-Type: application/json'