Este projeto tem por finalidade demonstrar todas as habilidades técnicas solicitadas no README-CODEVANCE.md
- Python 3.9
- Pipenv
- Redis
git clone https://github.com/mroratobaptista/work-at-codevance.gitcd work-at-codevancecp contrib/.env-sample .mv .env-sample .envpipenv sync -dpipenv shellpython manage.py collectstaticpython manage.py migratepython manage.py createsuperuserpython manage.py runserverAbra outra aba ou terminal e execute
pipenv run celery -A work_at_codevance beatAbra outra aba ou terminal e execute
pipenv run celery -A work_at_codevance worker- Acesse Django Admin.
- Crie 2 grupos.
- Operador
- Fornecedor
- Inclua o grupo Operador no usuário Admin criado anteriormente e/ou em outro usuário que gostaria.
- Crie os usuários dos fornecedores e adicione o grupo Fornecedor em cada um deles.
- Crie os fornecedores e selecione seus respectivos usuários.
- Crie os pagamentos e selecione seus respectivos fornecedores.
A API tem 2 endpoints, além dos tradicionais /api/token/ e /api/token/refresh/ do Django Rest Framework.
- /api/pagamentos/
- /api/solicitar-adiantamento/
Primeiramente é necessário pegar o token para ter acesso a API através do endpoint /api/token/.
Retorna access_token e refresh_token
Requisição
curl \
-X POST \
-H "Content-Type: application/json" \
-d '{"email": "email@email.com", "password": "password"}' \
http://localhost:8000/api/token/Resposta
{
"refresh": "refresh_token",
"access": "access_token"
}Retorna todos os pagamentos do usuário.
Requisição
curl \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ACCESS_TOKEN" \
http://localhost:8000/api/pagamentos/Resposta
{
"count": 5,
"payments": [
{
"id": 1,
"provider__cnpj": 1,
"date_issuance": "2019-10-01",
"date_due": "2019-10-01",
"date_anticipation": "2019-09-15",
"value_original": 1000.0,
"discount": 16.0,
"value_with_discount": 984.0,
"status": "AGUAR",
"created_at": "2022-06-26T22:14:36.749954Z",
"updated_at": "2022-06-27T18:52:20.563004Z"
},
{
"id": 2,
"provider__cnpj": 1,
"date_issuance": "2022-06-26",
"date_due": "2022-07-25",
"date_anticipation": "2022-07-15",
"value_original": 156.0,
"discount": 1.56,
"value_with_discount": 154.44,
"status": "APROV",
"created_at": "2022-06-26T22:14:48.121456Z",
"updated_at": "2022-06-27T18:52:37.286695Z"
},
{
"id": 3,
"provider__cnpj": 1,
"date_issuance": "2022-06-26",
"date_due": "2022-07-25",
"date_anticipation": "2022-07-24",
"value_original": 4650.0,
"discount": 4.65,
"value_with_discount": 4645.35,
"status": "NEGAD",
"created_at": "2022-06-26T22:14:56.239657Z",
"updated_at": "2022-06-27T18:52:48.313093Z"
},
{
"id": 4,
"provider__cnpj": 1,
"date_issuance": "2022-06-26",
"date_due": "2022-07-25",
"date_anticipation": null,
"value_original": 98789.0,
"discount": null,
"value_with_discount": null,
"status": "DISPO",
"created_at": "2022-06-26T22:15:06.115609Z",
"updated_at": "2022-06-27T18:39:11.135126Z"
},
{
"id": 5,
"provider__cnpj": 1,
"date_issuance": "2022-06-26",
"date_due": "2022-06-27",
"date_anticipation": null,
"value_original": 98.8,
"discount": null,
"value_with_discount": null,
"status": "INDIS",
"created_at": "2022-06-26T22:15:16.424598Z",
"updated_at": "2022-06-27T18:53:57.131479Z"
}
]
}Retorna todos os pagamentos do usuário DISPONÍVEIS para adiantamento.
Requisição
curl \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ACCESS_TOKEN" \
http://localhost:8000/api/pagamentos/DISPO/Resposta
{
"count": 1,
"payments": [
{
"id": 4,
"provider__cnpj": 1,
"date_issuance": "2022-06-26",
"date_due": "2022-07-25",
"date_anticipation": null,
"value_original": 98789.0,
"discount": null,
"value_with_discount": null,
"status": "DISPO",
"created_at": "2022-06-26T22:15:06.115609Z",
"updated_at": "2022-06-27T18:39:11.135126Z"
}
]
}Retorna todos os pagamentos do usuário INDISPONÍVEIS para adiantamento.
Requisição
curl \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ACCESS_TOKEN" \
http://localhost:8000/api/pagamentos/INDIS/Resposta
{
"count": 1,
"payments": [
{
"id": 5,
"provider__cnpj": 1,
"date_issuance": "2022-06-26",
"date_due": "2022-06-27",
"date_anticipation": null,
"value_original": 98.8,
"discount": null,
"value_with_discount": null,
"status": "INDIS",
"created_at": "2022-06-26T22:15:16.424598Z",
"updated_at": "2022-06-27T18:53:57.131479Z"
}
]
}Retorna todos os pagamentos do usuário AGUARDANDO CONFIRMAÇÃO para adiantamento.
Requisição
curl \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ACCESS_TOKEN" \
http://localhost:8000/api/pagamentos/AGUAR/Resposta
{
"count": 1,
"payments": [
{
"id": 1,
"provider__cnpj": 1,
"date_issuance": "2019-10-01",
"date_due": "2019-10-01",
"date_anticipation": "2019-09-15",
"value_original": 1000.0,
"discount": 16.0,
"value_with_discount": 984.0,
"status": "AGUAR",
"created_at": "2022-06-26T22:14:36.749954Z",
"updated_at": "2022-06-27T18:52:20.563004Z"
}
]
}Retorna todos os pagamentos do usuário APROVADOS para adiantamento.
Requisição
curl \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ACCESS_TOKEN" \
http://localhost:8000/api/pagamentos/APROV/Resposta
{
"count": 1,
"payments": [
{
"id": 2,
"provider__cnpj": 1,
"date_issuance": "2022-06-26",
"date_due": "2022-07-25",
"date_anticipation": "2022-07-15",
"value_original": 156.0,
"discount": 1.56,
"value_with_discount": 154.44,
"status": "APROV",
"created_at": "2022-06-26T22:14:48.121456Z",
"updated_at": "2022-06-27T18:52:37.286695Z"
}
]
}Retorna todos os pagamentos do usuário NEGADOS para adiantamento.
Requisição
curl \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ACCESS_TOKEN" \
http://localhost:8000/api/pagamentos/NEGAD/Resposta
{
"count": 1,
"payments": [
{
"id": 3,
"provider__cnpj": 1,
"date_issuance": "2022-06-26",
"date_due": "2022-07-25",
"date_anticipation": "2022-07-24",
"value_original": 4650.0,
"discount": 4.65,
"value_with_discount": 4645.35,
"status": "NEGAD",
"created_at": "2022-06-26T22:14:56.239657Z",
"updated_at": "2022-06-27T18:52:48.313093Z"
}
]
}Solicita o adiantamento para o ID_PAGAMENTO para a DATA_ANTECIPAÇÃO.
O Formato usado em DATA_ANTECIPAÇÃO é ANO-MES-DIA, ou seja, 2020-05-30.
Requisição
curl \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ACCESS_TOKEN" \
http://localhost:8000/api/solicitar-adiantamento/1/2019-09-15/Resposta
{
"payment": {
"id": 1,
"provider_cnpj": 1,
"date_issuance": "2019-10-01",
"date_due": "2019-10-01",
"date_anticipation": "2019-09-15",
"value_original": 1000.0,
"discount": 16.0,
"value_with_discount": 984.0,
"status": "AGUAR",
"created_at": "2022-06-26T22:14:36.749954Z",
"updated_at": "2022-06-27T19:02:52.097965Z"
}
}Para testar com as migrações realizadas execute
pipenv run pytest --covCaso não tenha realizados as migrações execute
pipenv run pytest --nomigrations --cov