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

DanielMaia/Development #48

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added .DS_Store
Binary file not shown.
Binary file added laravel/.DS_Store
Binary file not shown.
18 changes: 18 additions & 0 deletions laravel/.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 laravel/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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_DISK=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="[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 laravel/.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
18 changes: 18 additions & 0 deletions laravel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/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
9 changes: 9 additions & 0 deletions laravel/.styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
php:
preset: laravel
disabled:
- no_unused_imports
finder:
not-name:
- index.php
js: true
css: true
27 changes: 27 additions & 0 deletions laravel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400"></a></p>

## Documentação API em Laravel

Esta aplicação é responsável por realizar o controle de um investmento, sendo possível criar um investmento, sacar e visualizar.

Bibliotecas e versões utilizadas nesse sistema:

- "php": ^8.0.2,
- "laravel/framework": 9.19


Abaixo segue o passo a passo para executar o projeto e realizar os testes

### Passo a Passo

- Realizar o download do repositório
- Abrir o CMD no diretório root do projeto e executar "composer update"
- Executar comando para criar o .env e "application key" no .env "cp .env.example .env" e em seguida "php artisan key:generate"
- Atualizar as informações do arquivo .env com a sua conexão de banco de dados
- Executar os migrations para o sistema criar a base de dados "php artisan migrate"
- Iniciar o ambiente de desenvolvimento do laravel "php artisan serve"

#### Rotas e Funcionalidades

- Documentação das Rotas:
- https://documenter.getpostman.com/view/9534004/2s8YsqUuEy
Binary file added laravel/app/.DS_Store
Binary file not shown.
32 changes: 32 additions & 0 deletions laravel/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');
}
}
53 changes: 53 additions & 0 deletions laravel/app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace App\Exceptions;

use App\Traits\ApiResponser;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
use ApiResponser;

/**
* A list of exception types with their corresponding custom log levels.
*
* @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
*/
protected $levels = [
//
];

/**
* A list of the exception types that are not reported.
*
* @var array<int, class-string<\Throwable>>
*/
protected $dontReport = [
//
];

/**
* A list of the inputs that are never flashed to the session on validation exceptions.
*
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];

/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register()
{
$this->reportable(function (Throwable $e) {
//
});
}
}
Binary file added laravel/app/Http/.DS_Store
Binary file not shown.
13 changes: 13 additions & 0 deletions laravel/app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
121 changes: 121 additions & 0 deletions laravel/app/Http/Controllers/InvestmentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\InvestmentRequest;
use App\Models\Investment;
use App\Models\Owner;
use App\Repositories\InvestmentRepository;
use App\Repositories\OwnerRepository;
use App\Traits\ApiResponser;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Support\Facades\Validator;

class InvestmentController extends Controller
{
use ApiResponser;

/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
try {
$investmentRepo = new InvestmentRepository;
$allInvestments = $investmentRepo->getInvestmentByOwner($request->owner_id);

return $this->success($allInvestments, "Investmento criado com sucesso");
} catch (\Exception $e) {
return $this->error("Houve um erro interno ao buscar a lista de todos os investimentos.", 500, ["detail" => $e->getMessage()]);
}
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
try {
$ownerRepo = new OwnerRepository;
$ownerId = $ownerRepo->setOwner($request->owner_id, $request->owner_name);

$investmentRepo = new InvestmentRepository;
$investmentRepo->setInvestment($request->invesment, $ownerId);

return $this->success($request->input(), "Investmento criado com sucesso");
} catch (\Exception $e) {
return $this->error("Houve um erro interno ao criar um investimento.", 500, ["detail" => $e->getMessage()]);
}
}

/**
* Display the specified resource.
*
* @param int $ownerId
* @return \Illuminate\Http\Response
*/
public function show(int $investmentId)
{
try {
$validator = Validator::make(["investmentId" => $investmentId], [
'investmentId' => 'required|numeric',
]);
if ($validator->fails()) {
return $this->error(
'Falha ao realizar ao consultar um investmento.',
Response::HTTP_BAD_REQUEST,
$validator->errors()
);
}
$investmentRepo = new InvestmentRepository;
$investment = $investmentRepo->getInvestmentById($investmentId);
$investmentGain = $investmentRepo->getValueWithGain($investment);

return $this->success($investmentGain, "Investmento consultado com sucesso");
} catch (\Exception $e) {
return $this->error("Houve um erro interno ao buscar um investimento.", Response::HTTP_INTERNAL_SERVER_ERROR, ["detail" => $e->getMessage()]);
}
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Investment $investment
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Investment $investment)
{
try {
$validator = Validator::make(
[
"investmentId" => $investment->id,
"date" => $request->date
],
[
'investmentId' => 'required|numeric|exists:investments,id',
'date' => 'required'
]);
if ($validator->fails()) {
return $this->error(
'Falha ao realizar a retirada de um investmento.',
Response::HTTP_BAD_REQUEST,
$validator->errors()
);
}
$investmentRepo = new InvestmentRepository;
$investment = $investmentRepo->withdrawalInvestment($investment, $request->date);

return $this->success($investment, "Investmento retirado com sucesso");
} catch (\Exception $e) {
return $this->error("Houve um erro interno ao retirar um investimento.", Response::HTTP_INTERNAL_SERVER_ERROR, ["detail" => $e->getMessage()]);
}

}
}
Loading