Skip to content
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

bruno-holanda15 / investment_api #51

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
763974b
First commit
bruno-holanda15 Nov 19, 2022
1ab3978
Added docker settings
bruno-holanda15 Nov 19, 2022
0af3504
Removing .docker from git
bruno-holanda15 Nov 19, 2022
29d46c1
Changing uid from user
bruno-holanda15 Nov 19, 2022
14b97e5
Correcting location of laravel.conf
bruno-holanda15 Nov 19, 2022
a8c1a28
Started database initial structure
bruno-holanda15 Nov 20, 2022
2db4045
Started base to register/create investment flow
bruno-holanda15 Nov 20, 2022
4953644
Feature related to Owner creation with tests
bruno-holanda15 Nov 20, 2022
202e53b
Created database to run tests
bruno-holanda15 Nov 21, 2022
cccb6de
Created flow to create Investment
bruno-holanda15 Nov 22, 2022
9afd39b
Return amount expected from investment
bruno-holanda15 Nov 23, 2022
8590478
Created flow to return investments by owner
bruno-holanda15 Nov 24, 2022
66d6509
Created flow to withdrawal investment with tests
bruno-holanda15 Nov 25, 2022
e8e07c4
Fix return messages
bruno-holanda15 Nov 25, 2022
7e7be61
Added laravel-request-docs
bruno-holanda15 Nov 25, 2022
e8e96ee
Started README.md
bruno-holanda15 Nov 25, 2022
94440fb
Incremented README.md
bruno-holanda15 Nov 25, 2022
3658c71
Fixing variables at .envs
bruno-holanda15 Nov 25, 2022
d36c476
Fixing get investments by owner
bruno-holanda15 Nov 25, 2022
6eaef13
Added tests at readme.md
brunomendesup Nov 25, 2022
f47c1fc
Adding collumns to gains and taxes
bruno-holanda15 Nov 25, 2022
723a519
Reducing length of the line
bruno-holanda15 Nov 25, 2022
9616f95
Small fixes
bruno-holanda15 Nov 25, 2022
a7dc4e0
Small fixes
bruno-holanda15 Nov 26, 2022
b757475
Removing queue from docker-compose
bruno-holanda15 Nov 26, 2022
db6a551
resolving conflict
bruno-holanda15 Nov 26, 2022
b63aab9
Returned id when creating investment
bruno-holanda15 Dec 7, 2022
9a14caa
Created accessor details and changing format in show method
bruno-holanda15 Dec 8, 2022
2cd8805
Fixing get investments by owner
bruno-holanda15 Dec 10, 2022
2d1ac63
Increasing min amount to create investment
bruno-holanda15 Dec 10, 2022
c19ac78
Adding pint
bruno-holanda15 Dec 13, 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
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

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

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

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=investment_api
DB_USERNAME=root
DB_PASSWORD=root

BROADCAST_DRIVER=log
CACHE_DRIVER=redis
FILESYSTEM_DISK=local
QUEUE_CONNECTION=redis
SESSION_DRIVER=redis
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=redis
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="[email protected]"
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_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1

VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
58 changes: 58 additions & 0 deletions .env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:r9zZNVfbTyoLntfNno54GeNJcyTRnR5oh70+//AJCU0=
APP_DEBUG=true
APP_URL=http://localhost:8989

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=mysql_test
DB_PORT=3306
DB_DATABASE=investment_api
DB_USERNAME=root
DB_PASSWORD=root

BROADCAST_DRIVER=log
CACHE_DRIVER=redis
FILESYSTEM_DISK=local
QUEUE_CONNECTION=redis
SESSION_DRIVER=redis
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=redis
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="[email protected]"
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_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1

VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* 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
.styleci.yml export-ignore
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/node_modules
/public/build
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.env.backup
.env.production
.phpunit.result.cache
Homestead.json
Homestead.yaml
auth.json
npm-debug.log
yarn-error.log
/.fleet
/.idea
/.vscode
/.docker
/.docker_test
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM php:8.1.1-fpm

# Arguments
ARG user=bruninho
ARG uid=1000

# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd sockets

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user && \
chown -R $user:$user /var/www

# Install redis
RUN pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis

# Set working directory
WORKDIR /var/www

USER $user
102 changes: 36 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,88 +1,58 @@
# Back End Test Project <img src="https://coderockr.com/assets/images/coderockr.svg" align="right" height="50px" />
# Investment API

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.
&nbsp;
## Description

## Scope
This documentation has the purpose to guide the readers, on how to install and run the application, and some information about routes and the design thought through the development.
The idea of this API is to create, list and withdrawal investments which increases 0,52% per month.

In this challenge you should build an API for an application that stores and manages investments, it should have the following features:
&nbsp;
## How to Install

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][].
2. If an investment was already withdrawn then the balance must reflect the gains of that investment
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.
> Require [docker](https://docs.docker.com/get-docker/)

__NOTE:__ the implementation of an interface will not be evaluated.
> Clone the repository [investment_api](https://github.com/bruno-holanda15/investment_api/tree/development)

### Gain Calculation
&nbsp;
### RUN
Start the containers from docker-compose:
> `docker-compose up -d`

The investment will pay 0.52% every month in the same day of the investment creation.
Enter inside de container:
> `docker-compose exec app bash`

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.
Install dependecies inside the container:
> `composer install`

### Taxation
Generate the key to laravel app:
> `php artisan key:generate`

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.
Run migrations to construct database:
> `php artisan migrate && php artisan migrate --env=testing`

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).
&nbsp;
## Routes
We use [laravel-request-docs](https://github.com/rakutentech/laravel-request-docs) to document and test this API via http://localhost:8989/request-docs, but above we are going to explain the flow to create investment:

## 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.
- '/api/owner' - POST method - create an owner, passing e-mail(unique in database and helps us to validate) and name as parameters.

## 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.
- '/api/investment' - POST method - create an investment, passing e-mail(the same e-mail used to create owner), creation_date (format 'Y-m-d' Example:2020-02-02), date could be a date in the past or today, amount (money invested).

## Coding Standards
When working on the project be as clean and consistent as possible.
- '/api/investment' - GET method - return the value expected from the investment in the current date.

## Project Deadline
Ideally you'd finish the test project in 5 days. It shouldn't take you longer than a entire week.
- '/api/owners_investments' - GET method - return all the investments from owner - pass e-mail as parameter.

## Quality Assurance
Use the following checklist to ensure high quality of the project.
- '/api/withdrawal' - POST method - withdrawal the investment, passing the id of the investment and withdrawal_date(format 'Y-m-d' Example:2020-02-02).

### 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?
## Tests
We use [pest](https://pestphp.com/docs/installation) to run tests developed inside tests/Feature folder,
run `composer pest` inside the container to verify assertions created at files tests.

## Format
We use [pint](https://laravel.com/docs/9.x/pint) to to ensure that your code style stays clean and consistent, run
`./vendor/bin/pint` inside our container.

## 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
32 changes: 32 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
}

/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');

require base_path('routes/console.php');
}
}
Loading