Skip to content

Development back-end test #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cc0bb0a
start project
lauroappelt Feb 12, 2022
064815a
criado migrations tabelas.
lauroappelt Feb 13, 2022
88b3d2d
criação models investimento e rendimento
lauroappelt Feb 13, 2022
e500b28
criado investimento controller e teste unitario.
lauroappelt Feb 13, 2022
8ece195
ajuste gitignore
lauroappelt Feb 13, 2022
747b998
delete test exemplo
lauroappelt Feb 13, 2022
b24dc01
criação rota para criar investimento
lauroappelt Feb 13, 2022
df1e6a5
ajuste validação da criação de investimento e criacao de teste para i…
lauroappelt Feb 13, 2022
07221b7
cria service para calcular investimento
lauroappelt Feb 13, 2022
a6529d4
criação rota e método para visualizar um investimento, criado testes …
lauroappelt Feb 13, 2022
55ebab1
alterado cpf para cpf fake
lauroappelt Feb 13, 2022
ae938d8
altera atributo para constante
lauroappelt Feb 13, 2022
5427571
ajuste na validação de parametros e criação método para resgate
lauroappelt Feb 13, 2022
7d853d7
ajuste parametro da rota
lauroappelt Feb 13, 2022
362c4a0
criacao metodo para resgate e cálculo do imposto
lauroappelt Feb 13, 2022
9f8d09f
ajuste nos testes, criacao teste resgate
lauroappelt Feb 13, 2022
8246e6c
criação teste resgate data futura e teste resgate data inferior
lauroappelt Feb 13, 2022
6bb6c2a
ajuste para tratar data de resgate do investimento
lauroappelt Feb 15, 2022
fc9fde6
valida resgate de investimento já resgatado
lauroappelt Feb 15, 2022
bdd4875
criação método para listar todos investimentos de um investidor
lauroappelt Feb 15, 2022
71bef6c
ajuste paginação
lauroappelt Feb 15, 2022
1b5b025
documentação README
lauroappelt Feb 15, 2022
1e25230
ajustes de enviroment
lauroappelt Feb 16, 2022
94d937f
adicionado virtual host apache
lauroappelt Feb 16, 2022
ddffb16
ajuste no valor de resgate
lauroappelt Feb 16, 2022
aeab569
ajuste no readme
lauroappelt Feb 16, 2022
8147ab6
remocao model e migration nao utilizada
lauroappelt Feb 16, 2022
759200d
documentação
lauroappelt Feb 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[docker-compose.yml]
indent_size = 4
52 changes: 52 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:xEuoE4G/OgUuURL8MsWIffI8p03ltbv/nhJImwr2fUE=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=pgsql
DB_HOST=db
DB_PORT=5432
DB_DATABASE=backend
DB_USERNAME=postgres
DB_PASSWORD=postgres

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
52 changes: 52 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
52 changes: 52 additions & 0 deletions .env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:xEuoE4G/OgUuURL8MsWIffI8p03ltbv/nhJImwr2fUE=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=pgsql
DB_HOST=db
DB_PORT=5432
DB_DATABASE=backend_test
DB_USERNAME=postgres
DB_PASSWORD=postgres

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
* text=auto

*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php

/.github export-ignore
CHANGELOG.md export-ignore
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
.env.backup
.phpunit.result.cache
docker-compose.override.yml
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
/.idea
/.vscode
.env.example
14 changes: 14 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
php:
preset: laravel
version: 8
disabled:
- no_unused_imports
finder:
not-name:
- index.php
- server.php
js:
finder:
not-name:
- webpack.mix.js
css: true
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM ubuntu:20.04

# Utilities
RUN dpkg --add-architecture i386 && \
apt-get update -y && \
DEBIAN_FRONTEND="noninteractive" apt-get install -y apt-transport-https software-properties-common build-essential unzip curl git vim apache2 php libapache2-mod-php php-pgsql php-dev php-xml php-curl php-soap php-mbstring php-gd php-intl php-xsl php-pear php7.4-zip python-dev wget java-common --no-install-recommends

# Change image time zone
ENV TZ 'America/Sao_Paulo'
RUN echo $TZ > /etc/timezone && \
apt-get update && apt-get install -y tzdata && \
rm /etc/localtime && \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata && \
apt-get clean

# Composer PHP
ENV COMPOSER_ALLOW_SUPERUSER 1
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
php composer-setup.php --install-dir=/usr/bin --filename=composer

# Virtualhost
RUN a2enmod rewrite
RUN a2enmod proxy_html
COPY ./VirtualHost.conf /etc/apache2/sites-available/000-default.conf

# Volume
RUN mkdir /var/www/html/backend
VOLUME ["/var/www/html/backend"]
WORKDIR /var/www/html/backend
COPY . .
96 changes: 14 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,88 +1,20 @@
# Back End Test Project <img src="https://coderockr.com/assets/images/coderockr.svg" align="right" height="50px" />
# Back End Test Project

You should see this challenge as an opportunity to create an application following modern development best practices (given the stack of your choice), but also feel free to use your own architecture preferences (coding standards, code organization, third-party libraries, etc). It’s perfectly fine to use vanilla code or any framework or libraries.
Teste para desenvolvedor back-end na Coderockr, objetivando atender os requisitos da forma mais simples possível.

## Scope
Foi utilizado no desenvolvimento desta aplicação o framework Laravel 8 e como SGBD o Postgres 13.

In this challenge you should build an API for an application that stores and manages investments, it should have the following features:
## Execução e testes

1. __Creation__ of an investment with an owner, a creation date and an amount.
1. The creation date of an investment can be today or a date in the past.
2. An investment should not be or become negative.
2. __View__ of an investment with its initial amount and expected balance.
1. Expected balance should be the sum of the invested amount and the [gains][].
3. __Withdrawal__ of a investment.
1. The withdraw will always be the sum of the initial amount and its gains,
partial withdrawn is not supported.
2. Withdrawals can happen in the past or today, but can't happen before the investment creation or the future.
3. [Taxes][taxes] need to be applied to the withdrawals before showing the
final value.
4. __List__ of a person's investments
1. This list should have pagination.
* Faça o clone deste projeto
* Na raiz do projeto execute o comando <b>docker-compose up --build</b> para subir a aplicação. A aplicação estará disponpivel em http://127.0.0.1:8000
* Execução dos testes de unidade:
- Execute o comando <b>docker ps</b> para visualizar os containers rodando e identificar o container da aplicação,
a saída do comando deverá ser algo como: <pre> CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1ddb822f08c1 backend-test_backend "bash -c 'composer i…" 2 hours ago Up 22 seconds 0.0.0.0:8000->80/tcp, :::8000->80/tcp backend-test_backend_1
efafcf4c470d postgres:13 "docker-entrypoint.s…" 2 hours ago Up 23 seconds 0.0.0.0:5433->5432/tcp, :::5433->5432/tcp backend-test_db_1</pre>
- execute o camando <b>docker exec -it {{id_container}} php artisan test</b> para rodar os testes, informando o id do container da aplicação. ex: docker exec -it 1ddb822f08c1 php artisan test

__NOTE:__ the implementation of an interface will not be evaluated.
* A documentação da API está disponpivel em: https://documenter.getpostman.com/view/17234193/UVkgwyce


### Gain Calculation

The investment will pay 0.52% every month in the same day of the investment creation.

Given that the gain is paid every month, it should be treated as [compound gain][], which means that every new period (month) the amount gained will become part of the investment balance for the next payment.

### Taxation

When money is withdrawn, tax is triggered. Taxes apply only to the profit/gain portion of the money withdrawn. For example, if the initial investment was 1000.00, the current balance is 1200.00, then the taxes will be applied to the 200.00.

The tax percentage changes according to the age of the investment:
* If it is less than one year old, the percentage will be 22.5% (tax = 45.00).
* If it is between one and two years old, the percentage will be 18.5% (tax = 37.00).
* If older than two years, the percentage will be 15% (tax = 30.00).

## Requirements
1. Create project using any technology of your preference. It’s perfectly OK to use vanilla code or any framework or libraries;
2. Although you can use as many dependencies as you want, you should manage them wisely;
3. It is not necessary to send the notification emails, however, the code required for that would be welcome;
4. The API must be documented in some way.

## Deliverables
The project source code and dependencies should be made available in GitHub. Here are the steps you should follow:
1. Fork this repository to your GitHub account (create an account if you don't have one, you will need it working with us).
2. Create a "development" branch and commit the code to it. Do not push the code to the main branch.
3. Include a README file that describes:
- Special build instructions, if any
- List of third-party libraries used and short description of why/how they were used
- A link to the API documentation.
4. Once the work is complete, create a pull request from "development" into "main" and send us the link.
5. Avoid using huge commits hiding your progress. Feel free to work on a branch and use `git rebase` to adjust your commits before submitting the final version.

## Coding Standards
When working on the project be as clean and consistent as possible.

## Project Deadline
Ideally you'd finish the test project in 5 days. It shouldn't take you longer than a entire week.

## Quality Assurance
Use the following checklist to ensure high quality of the project.

### General
- First of all, the application should run without errors.
- Are all requirements set above met?
- Is coding style consistent?
- The API is well documented?
- The API has unit tests?

## Submission
1. A link to the Github repository.
2. Briefly describe how you decided on the tools that you used.

## Have Fun Coding 🤘
- This challenge description is intentionally vague in some aspects, but if you need assistance feel free to ask for help.
- If any of the seems out of your current level, you may skip it, but remember to tell us about it in the pull request.

## Credits

This coding challenge was inspired on [kinvoapp/kinvo-back-end-test](https://github.com/kinvoapp/kinvo-back-end-test/blob/2f17d713de739e309d17a1a74a82c3fd0e66d128/README.md)

[gains]: #gain-calculation
[taxes]: #taxation
[interest]: #interest-calculation
[compound gain]: https://www.investopedia.com/terms/g/gain.asp
16 changes: 16 additions & 0 deletions VirtualHost.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<VirtualHost *:80>
ServerName backend
DocumentRoot /var/www/html/backend/public
<Directory /var/www/html/backend/public>
allow from all
order allow,deny
AllowOverride All
php_admin_value error_reporting 22517
php_admin_value memory_limit 8192M
php_admin_value max_input_vars 2000
php_admin_value max_input_time 300
php_admin_value max_execution_time 300
php_admin_value post_max_size 2048M
php_admin_value upload_max_filesize 300M
</Directory>
</VirtualHost>
Loading