update project Heroku.

This commit is contained in:
Djonathan 2022-06-13 12:37:24 -03:00
parent cb407102d2
commit f997d062de
73 changed files with 2877 additions and 211 deletions

View File

@ -1,38 +0,0 @@
<?php
namespace App\Actions;
use App\Interface\ActionInterface;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
class UserAction implements ActionInterface
{
public function list(): User
{
return User::all();
}
public function create(array $params): Builder|Model
{
return User::query()->create($params);
}
public function show($id): User
{
return User::query()->find($id);
}
public function update(array $params, $id): int
{
return User::query()->find($id)->update($params);
}
public function delete($id)
{
// TODO: Implement delete() method.
}
}

28
app/Helper/Helpers.php Normal file
View File

@ -0,0 +1,28 @@
<?php
namespace App\Helper;
class Helpers
{
public static function object_to_array($object)
{
if (!is_object($object) && !is_array($object)) {
return $object;
}
return array_map([__CLASS__, 'object_to_array'], (array) $object);
}
public static function array_enkeyize($array, $iten): array
{
$keized = [];
foreach ($array as $key => $value) {
foreach ($value as $v_key => $v_value) {
if ($v_key === $iten) {
$keized[$v_value] = $array[$key];
}
}
}
return $keized;
}
}

View File

@ -0,0 +1,135 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\Helper\Model;
/**
* Description of EntityJson
*
* @author renan
*/
abstract class EntityJson implements \JsonSerializable
{
public function jsonToObject(\stdClass $jsonData)
{
$vars = get_object_vars($jsonData);
foreach ($vars as $key => $value) {
$this->$key = $value;
}
}
public function jsonSerialize()
{
$vars = get_object_vars($this);
$obj = new \stdClass();
foreach ($vars as $key => $value) {
$obj->$key = $value;
}
return $obj;
}
public function jsonSerializeUpperKey()
{
$vars = get_object_vars($this);
$obj = new \stdClass();
foreach ($vars as $key => $value) {
$key = strtoupper($key);
$obj->$key = $value;
}
return $obj;
}
public function jsonSerializeLowerKey()
{
$vars = get_object_vars($this);
$obj = new \stdClass();
foreach ($vars as $key => $value) {
$key = strtolower($key);
$obj->$key = $value;
}
return $obj;
}
public function jsonSetObject(\stdClass $jsonData)
{
$vars = get_object_vars($jsonData);
foreach ($vars as $key => $value) {
$method = "set" . ucfirst($key);
if (method_exists($this, $method)) {
$this->$method($value);
} else {
if (property_exists(get_class($this), $key)) {
$this->$key = $value;
}
}
}
}
public function fill(\stdClass $jsonData)
{
$vars = get_object_vars($jsonData);
foreach ($vars as $key => $value) {
$campo = strtolower($key);
$method = "set" . ucfirst($campo);
if (method_exists($this, $method)) {
$this->$method($value);
} else {
if (property_exists(get_class($this), $campo)) {
$this->$campo = $value;
}
}
}
}
public function toArray()
{
$vars = get_object_vars($this);
$result = array();
foreach ($vars as $key => $value) {
$method = "get" . ucfirst($key);
$key = strtoupper($key);
$valor = $value;
if (method_exists($this, $method)) {
$valor = $this->$method();
}
$result[$key] = $valor;
}
return $result;
}
/**
* Converte um array de objeto stdClass para uma entidade
* @param $className
* @param array $arrayOfObject
* @return array
*/
protected function arrayObjectCast($className, array $arrayOfObject) : array
{
$arr = [];
if (!empty($arrayOfObject)) {
// verificando o elemento do array
$obj = $arrayOfObject[0];
// se for um array associativo converte para stdClass
if (is_array($obj) && count(array_filter(array_keys($obj), 'is_string')) > 0) {
$obj = (object) $obj;
}
if (get_class($obj) == "stdClass") {
foreach ($arrayOfObject as $item) {
$e = new $className();
if (method_exists($e, 'jsonSetObject')) {
$e->jsonSetObject($item);
$arr[] = $e;
}
}
} elseif (get_class($obj) == $className) {
return $arrayOfObject;
}
}
return $arr;
}
}

View File

@ -0,0 +1,97 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\Helper\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Collection;
/**
* Description of ModelExtractor
*
* @author renan
*/
class ModelExtractor extends TableExtractor
{
/**
*
* @var string
*/
private $modelClass = '';
/**
* @var Model
*/
private $model;
public function __construct(string $modelClass)
{
parent::__construct();
$this->modelClass = $modelClass;
$this->instanceModel();
}
public function getAttributeFromMethod($method, array $parameters = [])
{
if (method_exists($this->model, $method)) {
if (count($parameters) > 0) {
$result = [$this->model, $method](...$parameters);
} else {
$result = [$this->model, $method]();
}
if (isset($result)) {
if ($result instanceof $this->modelClass) {
$this->setAttributeFromDataArray($result->toArray(), $this->model->getCasts());
return $this->getAttributes();
} elseif ($result instanceof Collection) {
$this->setAttributeFromCollection($result);
return $this->getAttributes();
} elseif (is_array($result)) {
$this->setAttributeFromDataArray((array) $result[0], $this->model->getCasts());
return $this->getAttributes();
} elseif (is_object($result)) {
$this->setAttributeFromDataArray((array) $result, $this->model->getCasts());
return $this->getAttributes();
} else {
throw new \Exception('Nao foi possivel converter esse tipo de retorno verificar ');
}
}
} else {
throw new \Exception('Method not found for this class');
}
}
private function setAttributeFromCollection(Collection $collection)
{
$casts = $this->model->getCasts();
$this->setAttributeFromDataArray($collection->toArray()[0], $casts);
}
private function setAttributeFromDataArray(array $data, array $casts = [])
{
$attributes = [];
foreach ($data as $key => $value) {
if (!empty($casts) && isset($casts[$key])) {
$attributes[] = $this->createColumn($key, $casts[$key]);
} else {
$attributes[] = $this->createColumn($key, $this->getDataTypeByValue($value));
}
}
$this->attributes = $attributes;
}
private function instanceModel()
{
$this->model = new $this->modelClass;
$this->setTable($this->model->getTable());
$this->setOwner($this->model->getConnectionName());
}
}

View File

@ -0,0 +1,201 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\Helper\Model;
use Illuminate\Support\Facades\DB;
/**
* Description of TableExtractor
*
* @author renan
*/
class TableExtractor
{
/**
* @var string
*/
private $tableName;
/**
* @var string
*/
private $owner;
/**
* Default empty space
* @var type
*/
private $e = " ";
protected $attributes = [];
private $_sql_filterExtractor = "SELECT
COLUMN_NAME,
case when DATA_TYPE = 'NUMBER' THEN
decode(data_scale,0,'INTEGER','FLOAT')
when DATA_TYPE = 'DATE' THEN
'DATE'
else
'STRING'
end as DATA_TYPE
FROM all_tab_columns where table_name = ?
and owner = ?
order by column_id";
public function __construct(string $tableName = '', string $owner = 'KDB1')
{
$this->setTable($tableName);
$this->setOwner($owner);
}
public function getAttributes() : array
{
if (count($this->attributes) === 0) {
$result = DB::select(DB::raw($this->_sql_filterExtractor), array(
$this->tableName,
$this->owner,
));
foreach ($result as $r) {
$r->column_name = strtolower($r->column_name);
$r->data_type = strtolower($r->data_type);
}
$this->attributes = $result;
}
return $this->attributes;
}
public function toPhpProperties() : array
{
$attributes = $this->getAttributes();
return array_map(function ($r) {
return
"{$this->e}/**". PHP_EOL .
"{$this->e}* @var ".$this->getDataTypePhp($r->data_type). PHP_EOL.
"{$this->e}*/" . PHP_EOL .
"{$this->e}protected $" . strtolower($r->column_name).';' . PHP_EOL;
}, $attributes);
}
public function toSetters() : array
{
$attributes = $this->getAttributes();
return array_map(function ($r) {
return
"{$this->e}public function set" . ucfirst($r->column_name) . "(" . $this->getDataTypePhp($r->data_type) . " $".$r->column_name.")" . PHP_EOL .
"{$this->e}{" . PHP_EOL .
"{$this->e}{$this->e}\$this->".strtolower($r->column_name). " = $" . $r->column_name . ";" . PHP_EOL .
"{$this->e}}" . PHP_EOL;
}, $attributes);
}
public function toGetters() : array
{
$attributes = $this->getAttributes();
return array_map(function ($r) {
return
"{$this->e}public function get" . ucfirst($r->column_name) . "()" . $this->getDataTypePhp($r->data_type, true) . PHP_EOL .
"{$this->e}{" . PHP_EOL .
"{$this->e}{$this->e}return \$this->".strtolower($r->column_name). ";" . PHP_EOL .
"{$this->e}}" . PHP_EOL;
}, $attributes);
}
public function toSwaggerAnnotation($entityName = 'Entity')
{
$swagger = "";
$attributes = $this->getAttributes();
$swagger.='/**' . PHP_EOL;
$swagger.=' * @OA\Schema(' . PHP_EOL;
$swagger.=' * schema="'.$entityName.'",' . PHP_EOL;
$swagger.=' * type="object",' . PHP_EOL;
$swagger.=' * description="'.$entityName.' entity",' . PHP_EOL;
$swagger.=' * title="'.$entityName.' entity",' . PHP_EOL;
foreach ($attributes as $at) {
$type = 'type="'.$at->data_type.'"';
if ($at->data_type === 'float') {
$type = 'type="number", format="float", example="15.99"';
}
if ($at->data_type === 'date') {
$type = 'type="string", format="date", example="dd/mm/YYYY"';
}
$swagger.=' * @OA\Property(property="'.$at->column_name.'", '.$type.', description="'.ucfirst($at->column_name).'"),' . PHP_EOL;
}
$swagger.=" * )" . PHP_EOL;
$swagger.=" */";
return $swagger;
}
public function getDataTypePhp($dataType, $return = false)
{
$valor = "";
switch ($dataType):
case 'string':
$valor = 'string';
break;
case 'float':
$valor = 'float';
break;
case 'integer':
$valor = 'int';
break;
case 'array':
$valor = 'array';
break;
default:
$valor = '';
break;
endswitch;
if ($return === true && !empty($valor)) {
$valor = ' : ' . $valor;
}
return $valor;
}
protected function setTable($table)
{
$this->tableName = strtoupper($table);
}
protected function setOwner($owner)
{
$this->owner = strtoupper($owner);
}
protected function createColumn($columName, $dataType) : \stdClass
{
$obj = new \stdClass();
$obj->column_name = strtolower($columName);
$obj->data_type = strtolower($dataType);
return $obj;
}
protected function getDataTypeByValue($value)
{
// verificando se é numerico
if (is_object($value)===false && is_numeric(str_replace(',', '.', $value))) {
// verificando se é float
if (strpos($value, ",")!==false || strpos($value, ".")!==false) {
return "float";
} else {
return "integer";
}
} elseif (is_string($value)) {
return "string";
} elseif (is_array($value)) {
return "array";
} else {
return "";
}
}
}

View File

@ -0,0 +1,26 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\Helper\Model\filter;
class FieldFilterBuilder extends FilterBuilder
{
/**
* @var string[]
*/
protected array $fields = [];
public function getFields() : array
{
return $this->fields;
}
public function setFields(array $fields)
{
$this->fields = $fields;
}
}

View File

@ -0,0 +1,159 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\Helper\Model\filter;
use App\Helper\Model\EntityJson;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator;
/**
* @OA\Schema(
* schema="FilterBuilder",
* type="object",
* description="FilterBuilder entity",
* title="FilterBuilder entity",
* @OA\Property(property="filters", type="object", ref="#/components/schemas/FilterItemFilterList"),
* @OA\Property(property="limit", type="integer", example="10",description="Limit da paginação"),
* @OA\Property(property="offset", type="integer", example="0", description="Valor da offset da paginação"),
* @OA\Property(property="order", type="object", ref="#/components/schemas/OrderItemFilterList"),
* )
*/
/**
* @OA\Schema(
* schema="FilterBuilderResponse",
* type="object",
* description="FilterBuilderReponse entity",
* title="FilterBuilderReponse entity",
* allOf={
* @OA\Schema(ref="#/components/schemas/FilterBuilder")
* },
* @OA\Property(property="data", type="array", type="object", example="[{...}]", description="Array de objetos do resultado da query"),
* @OA\Property(property="total", type="integer", example="100", description="Resultado do total de linhas sem a paginação"),
* )
*/
/**
* @OA\Schema(
* schema="FieldFilterBuilder",
* type="object",
* description="FieldFilterBuilder entity",
* title="FieldFilterBuilder entity",
* allOf={
* @OA\Schema(ref="#/components/schemas/FilterBuilder")
* },
* @OA\Property(property="fields", type="array", type="string", example="['cd_pessoa','nm_pessoa']"),
* )
*/
class FilterBuilder extends EntityJson implements IFilterBuilder
{
/**
* @var FilterItem[]
*/
protected array $filters = [];
/**
* @var int
*/
protected int $limit = 10;
/**
* @var int
*/
protected int $offset = 0;
/**
* @var OrderItem[]
*/
protected array $order = [];
/**
* @var string[]
*/
protected array $fields = [];
public function applyFilter(Builder $builder): Builder
{
if (empty($this->getFilters()) === false) {
foreach ($this->getFilters() as $filter) {
$builder = FilterType::filter($builder, $filter);
}
}
// estilo antigo
//$builder->limit($this->getLimit());
//$builder->offset($this->getOffset());
/**
* Estilo novo com paginate
* Vantagem q o paginate retorna o total
*/
$currentPage = $this->getOffset();
\Illuminate\Pagination\Paginator::currentPageResolver(function () use ($currentPage) {
return $currentPage;
});
foreach ($this->getOrder() as $order) {
$builder->orderBy($order->getField(), $order->getDirection());
}
return $builder;
}
public function getOrder(): array
{
return $this->order;
}
public function setOrder(array $orders)
{
$this->order = $this->arrayObjectCast(OrderItem::class, $orders);
}
public function getFilters(): array
{
return $this->filters;
}
public function getLimit(): int
{
return $this->limit;
}
public function getOffset(): int
{
return $this->offset;
}
public function setFilters(array $filters)
{
$this->filters = $this->arrayObjectCast(FilterItem::class, $filters);
}
public function addFilter(FilterItem $filter)
{
$this->filters[] = $filter;
}
public function setLimit(int $limit)
{
$this->limit = $limit;
}
public function setOffset(int $offset)
{
$this->offset = $offset;
}
public function getFields() : array
{
return $this->fields;
}
public function setFields(array $fields)
{
$this->fields = $fields;
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace App\Helper\Model\filter;
class FilterBuilderFactory
{
public static function createFilterBuilderResponse(FilterBuilder $filter, array $data = []) : FilterBuilderResponse
{
$json = json_decode(json_encode($filter));
$response = new FilterBuilderResponse();
$response->jsonSetObject($json);
$response->setData($data);
return $response;
}
}

View File

@ -0,0 +1,42 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\Helper\Model\filter;
class FilterBuilderResponse extends FilterBuilder
{
/**
* @var array
*/
protected $data = [];
/**
* @var int
*/
protected $total = 0;
public function getData() : array
{
return $this->data;
}
public function setData(array $data)
{
$this->data = $data;
}
public function getTotal() : int
{
return $this->total;
}
public function setTotal(int $total)
{
$this->total = $total;
}
}

View File

@ -0,0 +1,111 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\Helper\Model\filter;
use App\Helper\Model\EntityJson;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\Expression;
use Illuminate\Support\Facades\DB;
/**
* FilterItem
*
* Objeto utilizado para base dos filtros, por padrão ele possui um estrutura json nesse formato
* { type: "=", field: "id_produto", value: 18832 }
* @author renan
*/
/**
* @OA\Schema(
* schema="FilterItemFilter",
* type="object",
* description="FilterItemFilter entity",
* title="FilterItemFilter entity",
* @OA\Property(property="type", type="string", example=">=", description="Tipo do filtro podendo ser: =,<>,>,>=,<,<=,between,not_between,like,not_like,in,not_in"),
* @OA\Property(property="field", type="string", description="Campo a ser ordernado (tem ser um campo valido)"),
* @OA\Property(property="value", type="string", example="30", description="Valor a ser filtrado. No between e in usar array nos outros casos usar um valor normal (sem ser numerico)."),
* )
*
* @OA\Schema(
* schema="FilterItemFilterList",
* allOf={
* @OA\Schema(ref="#/components/schemas/FilterItemFilter")
* }
* )
*/
class FilterItem extends EntityJson
{
/**
* @var string
*/
protected $type = "=";
/**
* @var string
*/
protected $field;
/**
*
* @var mixed
*/
protected $value;
/**
* @var bool
*/
protected bool $row = false;
/**
* @return bool
*/
public function getRow(): bool
{
return $this->row;
}
/**
* @param bool $row
*/
public function setRow(bool $row): void
{
$this->row = $row;
}
public function getType() : string
{
return $this->type;
}
public function getField() :Expression|string
{
return $this->field;
}
public function getValue()
{
return $this->value;
}
public function setType(string $type)
{
$this->type = $type;
}
public function setField($field)
{
$this->field = $field;
}
public function setValue($value)
{
$this->value = $value;
}
}

View File

@ -0,0 +1,120 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\Helper\Model\filter;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
/**
* Description of FilterType
* Filtros padrãos do laravel builder
* @author renan
*/
class FilterType
{
const WHERE_FILTER = array(
"=",
"<>",
">",
">=",
"<",
"<=",
"like",
"not_like"
);
const IN_FILTER = array(
"in",
"not_in"
);
const BETWEEN_FILTER = array(
"between",
"not_between"
);
const NULL_FILTER = array(
"null",
"not_null"
);
const DATE_FILTER = [
];
public static function filter(Builder $builder, FilterItem $filter) : Builder
{
if (in_array($filter->getType(), self::WHERE_FILTER)) {
return self::MAKE_WHERE_FILTER($builder, $filter);
}
if (in_array($filter->getType(), self::IN_FILTER)) {
return self::MAKE_IN_FILTER($builder, $filter);
}
if (in_array($filter->getType(), self::BETWEEN_FILTER)) {
return self::MAKE_BETWEEN_FILTER($builder, $filter);
}
if (in_array($filter->getType(), self::NULL_FILTER)) {
return self::MAKE_NULL_FILTER($builder, $filter);
}
if (in_array($filter->getType(), self::DATE_FILTER)){
}
return $builder;
}
private static function MAKE_WHERE_FILTER(Builder $builder, FilterItem $filter) : Builder
{
$fType = $filter->getType();
// filtro not_like sem o underscore (deixo o _ por padrao)
if ($fType === 'not_like') {
$fType = 'not like';
}
$field = ($filter->getRow()) ? DB::raw($filter->getField()) : $filter->getField();
return $builder->where($field, $fType, $filter->getValue());
}
private static function MAKE_IN_FILTER(Builder $builder, FilterItem $filter) : Builder
{
if ($filter->getType() === "in") {
return $builder->whereIn($filter->getField(), $filter->getValue());
} elseif ($filter->getType() === "not_in") {
return $builder->whereNotIn($filter->getField(), $filter->getValue());
}
return $builder;
}
private static function MAKE_BETWEEN_FILTER(Builder $builder, FilterItem $filter) : Builder
{
if ($filter->getType() === "between") {
return $builder->whereBetween($filter->getField(), $filter->getValue());
} elseif ($filter->getType() === "not_between") {
return $builder->whereNotBetween($filter->getField(), $filter->getValue());
}
return $builder;
}
private static function MAKE_NULL_FILTER(Builder $builder, FilterItem $filter) : Builder
{
if ($filter->getType() === "null") {
return $builder->whereNull($filter->getField());
} elseif ($filter->getType() === "not_null") {
return $builder->whereNotNull($filter->getField());
}
return $builder;
}
}

View File

@ -0,0 +1,15 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\Helper\Model\filter;
use Illuminate\Database\Eloquent\Builder;
interface IFilterBuilder
{
public function applyFilter(Builder $builder) : Builder;
}

View File

@ -0,0 +1,72 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\Helper\Model\filter;
use App\Entity\EntityJson;
/**
* OrderItem
*
* Objeto utilizado para base dos filtros, por padrão ele possui um estrutura json nesse formato
* { field: "id_produto", direction: "asc" }
* @author renan
*/
/**
* @OA\Schema(
* schema="OrderItemFilter",
* type="object",
* description="OrderItemFilter entity",
* title="OrderItemFilter entity",
* @OA\Property(property="field", type="string", description="Campo a ser ordernado (tem ser um campo valido)"),
* @OA\Property(property="direction", type="string", example="asc", description="Direção da ordenação (asc|desc)"),
* )
*
* @OA\Schema(
* schema="OrderItemFilterList",
* allOf={
* @OA\Schema(ref="#/components/schemas/OrderItemFilter")
* }
* )
*/
class OrderItem extends EntityJson
{
/**
* @var string
*/
protected $field;
/**
*
* @var string
*/
protected $direction = "asc";
public function getField() : string
{
return $this->field;
}
public function setField(string $field)
{
$this->field = $field;
}
public function getDirection() : string
{
return $this->direction;
}
public function setDirection(string $direction="asc")
{
$this->direction = $direction;
}
}

View File

@ -10,7 +10,7 @@ use Laravel\Sanctum\PersonalAccessToken;
class AuthController extends Controller
{
public function login(LoginResquest $request)
public function login(LoginResquest $request): JsonResponse
{
$credentials = $request->only('email', 'password');
@ -29,21 +29,6 @@ class AuthController extends Controller
}
public function login2(LoginResquest $request): JsonResponse
{
$credentials = $request->only('email', 'password');
if (!auth()->attempt($credentials))
{
abort(401, 'Inavalid Credentials');
}
$request->session()->regenerate();
return response()->json([], 200);
}
public function logout(Request $request): JsonResponse
{
$requestToken = $request->header('authorization');

View File

@ -1,14 +0,0 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class RegisterController extends Controller
{
public function store()
{
}
}

View File

@ -2,9 +2,15 @@
namespace App\Http\Controllers;
use App\Actions\EconomyAction;
use App\Helper\Model\filter\FilterBuilder;
use App\Http\Requests\AzuxRequest;
use App\Models\DadosCadastrais;
use App\Models\Economy;
use App\Repositories\Economy\EconomyContractInterface;
use App\Repository\Economy\EconomyRepository;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Gate;
use Symfony\Component\HttpFoundation\Response as ResponseAlias;
@ -12,15 +18,44 @@ use Symfony\Component\HttpFoundation\Response as ResponseAlias;
class EconomyController extends Controller
{
public function index(): JsonResponse
public function __construct(
protected EconomyContractInterface $economyContract
)
{
}
abort_if(Gate::denies('teste-index'), ResponseAlias::HTTP_FORBIDDEN, '403 Forbidden');
$result = DadosCadastrais::query()->limit(10)->get();
return response()->json($result, 200);
public function __invoke(Request $request)
{
try {
$this->economyContract->execute($request);
} catch (\Exception $exception) {
return \response()->json([], ResponseAlias::HTTP_INTERNAL_SERVER_ERROR);
}
}
// public function index(): JsonResponse
// {
//
// Economy::query()->select();
// abort_if(Gate::denies('teste-index'), ResponseAlias::HTTP_FORBIDDEN, '403 Forbidden');
//
// $result = DadosCadastrais::query()->limit(10)->get();
//
// return response()->json($result, 200);
//
// }
//
//
// public function teste(Request $request): JsonResponse
// {
// try {
// $data = (new EconomyRepository())->execute($request->all());
// return \response()->json($data, ResponseAlias::HTTP_OK);
// } catch (\Exception $exception) {
// return \response()->json([], ResponseAlias::HTTP_INTERNAL_SERVER_ERROR);
// }
//
// }
}

View File

@ -2,9 +2,67 @@
namespace App\Http\Controllers;
use App\Repositories\Faqs\FaqContractInterface;
use App\Traits\ApiResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class FaqController extends Controller
{
//
}
use ApiResponse;
public function __construct(
protected FaqContractInterface $faq
){}
public function index(): JsonResponse
{
try {
$response = $this->faq->all();
return response()->json($response, 200);
} catch (\Exception $ex) {
return $this->errorResponse(false, $ex->getMessage(), 404);
}
}
public function store(Request $notificationRequest): JsonResponse
{
try {
$response = $this->faq->create($notificationRequest->all());
return response()->json($response, 200);
} catch (\Exception $ex) {
return $this->errorResponse(false, $ex->getMessage(), 404);
}
}
public function show(int $id): JsonResponse
{
try {
$response = $this->faq->find($id);
return response()->json($response, 200);
}catch (\Exception $ex){
return $this->errorResponse(false, $ex->getMessage(), 404);
}
}
public function update(Request $request, $id): JsonResponse
{
try {
$response = $this->faq->update($request->all(), $id);
return response()->json($response, 200);
}catch (\Exception $ex){
return $this->errorResponse(false, $ex->getMessage(), 404);
}
}
public function destroy($id): JsonResponse
{
try {
$response = $this->faq->destroy($id);
return response()->json($response, 200);
}catch (\Exception $ex){
return $this->errorResponse(false, $ex->getMessage(), 404);
}
}
}

View File

@ -1,8 +0,0 @@
<?php
namespace App\Http\Controllers;
class NewsController extends Controller
{
//
}

View File

@ -0,0 +1,74 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\StoreNotificationRequest;
use App\Http\Resources\NotificationResource;
use App\Repositories\Notifications\NotificationContractInterface;
use App\Traits\ApiResponse;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
class NotificationController extends Controller
{
use ApiResponse;
public function __construct(
protected NotificationContractInterface $notification
){}
public function index(): JsonResponse
{
try {
$response = $this->notification->all();
return response()->json($response, 200);
} catch (\Exception $ex) {
return $this->errorResponse(false, $ex->getMessage(), 404);
}
}
public function store(StoreNotificationRequest $request): JsonResponse
{
try {
$response = $this->notification->create($request->validated());
$response->users()->sync($request->input('users.*.user_id', []));
return (new NotificationResource($response))
->response()
->setStatusCode(Response::HTTP_CREATED);
} catch (\Exception $ex) {
return $this->errorResponse(false, $ex->getMessage(), 404);
}
}
public function show(int $id): JsonResponse
{
try {
$response = $this->notification->find($id);
return response()->json($response, 200);
}catch (\Exception $ex){
return $this->errorResponse(false, $ex->getMessage(), 404);
}
}
public function update(Request $request, $id): JsonResponse
{
try {
$response = $this->notification->update($request->all(), $id);
return response()->json($response, 200);
}catch (\Exception $ex){
return $this->errorResponse(false, $ex->getMessage(), 404);
}
}
public function destroy($id): JsonResponse
{
try {
$response = $this->notification->destroy($id);
return response()->json($response, 200);
}catch (\Exception $ex){
return $this->errorResponse(false, $ex->getMessage(), 404);
}
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PldController extends Controller
{
public function overviewByRegion()
{
dd('oii');
}
public function listConsumption()
{
dd('oii');
}
public function consumptionByDaily()
{
dd('oii');
}
public function consumptionBySchedule()
{
dd('oii');
}
}

View File

@ -1,13 +1,25 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers;
use App\Actions\UserAction;
use App\Http\Requests\StoreUserRequest;
use App\Http\Resources\UserResource;
use App\Repositories\Users\UserContractInterface;
use App\Traits\ApiResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class UserController extends Controller
{
use ApiResponse;
public function __construct(
protected UserContractInterface $user
){}
/**
* Display a listing of the resource.
*
@ -16,10 +28,10 @@ class UserController extends Controller
public function index(): JsonResponse
{
try {
$list = (new UserAction())->list();
$list = $this->user->withRelationsByAll('roles');
return response()->json($list, 200);
}catch (\Exception $ex){
return response()->json(['message' => $ex->getMessage()], 500);
return $this->errorResponse(false, $ex->getMessage(), 404);
}
}
@ -27,45 +39,68 @@ class UserController extends Controller
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
* @param StoreUserRequest $request
* @return JsonResponse
*/
public function store(Request $request)
public function store(StoreUserRequest $request): JsonResponse
{
//
try {
$response = $this->user->create($request->all());
return (new UserResource($response))
->response()
->setStatusCode(Response::HTTP_CREATED);
}catch (\Exception $ex){
return $this->errorResponse(false, $ex->getMessage(), 404);
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
* @param int $id
* @return JsonResponse
*/
public function show($id)
public function show(int $id): JsonResponse
{
//
try {
$response = $this->user->find($id);
return response()->json($response, 200);
}catch (\Exception $ex){
return $this->errorResponse(false, $ex->getMessage(), 404);
}
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
* @param Request $request
* @param $id
* @return JsonResponse
*/
public function update(Request $request, $id)
public function update(Request $request, $id): JsonResponse
{
//
try {
$response = $this->user->update($request->all(), $id);
return response()->json($response, 200);
}catch (\Exception $ex){
return $this->errorResponse(false, $ex->getMessage(), 404);
}
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
* @param $id
* @return JsonResponse
*/
public function destroy($id)
public function destroy($id): JsonResponse
{
//
try {
$response = $this->user->destroy($id);
return response()->json($response, 200);
}catch (\Exception $ex){
return $this->errorResponse(false, $ex->getMessage(), 404);
}
}
}

View File

@ -0,0 +1,46 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\Http\Requests;
use Exception;
use Illuminate\Http\Request;
use App\Helper\Model\filter\FieldFilterBuilder;
use App\Helper\Model\filter\FilterBuilder;
/**
* Description of AzuxRequest
*
* @author renan
*/
class AzuxRequest extends Request
{
public function getJsonObject($className)
{
$jsonData = json_decode($this->getContent());
if (isset($jsonData)) {
$obj = new $className;
if (method_exists($obj, 'jsonToObject')) {
$obj->jsonSetObject($jsonData);
return $obj;
}
} else {
throw new Exception("Request inválido");
}
}
public function getFilterBuilder() : ?FilterBuilder
{
return $this->getJsonObject(FilterBuilder::class);
}
public function getFieldFilterBuilder() : ?FieldFilterBuilder
{
return $this->getJsonObject(FieldFilterBuilder::class);
}
}

View File

@ -4,16 +4,16 @@ namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class RegisterUserResquest extends FormRequest
class StoreNotificationRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
public function authorize(): bool
{
return false;
return true;
}
/**
@ -24,7 +24,12 @@ class RegisterUserResquest extends FormRequest
public function rules()
{
return [
//
'title' => 'required|string',
'body' => 'required',
'users.*.user_i' => [
'integer',
'exists:users,user_id',
],
];
}
}

View File

@ -4,7 +4,7 @@ namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UserLoginRequest extends FormRequest
class StoreUserRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
@ -13,7 +13,7 @@ class UserLoginRequest extends FormRequest
*/
public function authorize()
{
return false;
return true;
}
/**
@ -24,7 +24,10 @@ class UserLoginRequest extends FormRequest
public function rules()
{
return [
//
'name' => 'required|string',
'email' => 'required|string|email|max:255|unique:users',
'password'=> 'required|string|min:6|confirmed',
'client_id' => 'required'
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class NotificationResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Http\Resources;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use JsonSerializable;
class UserResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param Request $request
* @return array|Arrayable|JsonSerializable
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@ -1,13 +0,0 @@
<?php
namespace App\Interface;
interface ActionInterface
{
public function list();
public function create(array $params);
public function show($id);
public function update(array $params, $id);
public function delete($id);
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\Interface;
interface RepositoryInterfaces
{
public function list();
public function create(array $params);
public function find(int $id);
public function update(array $params, int $id);
public function delete(int $id);
}

View File

@ -14,4 +14,5 @@ class Economy extends Model implements Auditing
use HasFactory, SoftDeletes, Auditable;
protected $table = 'economia';
}

View File

@ -1,19 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use OwenIt\Auditing\Contracts\Auditable as Auditing;
use OwenIt\Auditing\Auditable;
class News extends Model implements Auditing
{
use HasFactory, SoftDeletes, Auditable;
protected $fillable = [
'title',
'text'
];
}

View File

@ -2,10 +2,33 @@
namespace App\Models;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Notifications extends Model
{
use HasFactory;
protected $table = 'notificacoes';
protected $guarded = ['id'];
protected $fillable = [
'title',
'body',
'user_id'
];
protected function serializeDate(DateTimeInterface $date): string
{
return $date->format('d/m/Y H:i:s');
}
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class, 'notificacoes_users', 'notification_id', 'user_id', );
}
}

View File

@ -2,6 +2,7 @@
namespace App\Models;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
@ -28,6 +29,11 @@ class Role extends Model implements Auditing
'deleted_at',
];
protected function serializeDate(DateTimeInterface $date): string
{
return $date->format('d/m/Y H:i:s');
}
public function permissions(): BelongsToMany
{
return $this->belongsToMany(Permission::class);

View File

@ -2,6 +2,7 @@
namespace App\Models;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
@ -15,11 +16,10 @@ class User extends Authenticatable implements Auditing
{
use HasApiTokens, HasFactory, Notifiable, SoftDeletes, Auditable;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $table = "users";
protected $guarded = ['id'];
protected $fillable = [
'name',
'email',
@ -29,28 +29,27 @@ class User extends Authenticatable implements Auditing
'deleted_at',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
protected function serializeDate(DateTimeInterface $date): string
{
return $date->format('d/m/Y H:i:s');
}
public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class);
}
public function notifications(): BelongsToMany
{
return $this->belongsToMany(Notifications::class, 'notificacoes_users', 'notification_id', 'user_id');
}
}

View File

@ -2,6 +2,16 @@
namespace App\Providers;
use App\Repositories\Economy\EconomyContractInterface;
use App\Repositories\Economy\EconomyRepository;
use App\Repositories\Faqs\FaqContractInterface;
use App\Repositories\Faqs\FaqRepository;
use App\Repositories\Notifications\NotificationContractInterface;
use App\Repositories\Notifications\NotificationRepository;
use App\Repositories\Pld\PldContractInterface;
use App\Repositories\Pld\PldRepository;
use App\Repositories\Users\UserContractInterface;
use App\Repositories\Users\UserRepository;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
@ -11,9 +21,28 @@ class AppServiceProvider extends ServiceProvider
*
* @return void
*/
public function register()
public function register(): void
{
//
$this->app->bind(
UserContractInterface::class,
UserRepository::class
);
$this->app->bind(
NotificationContractInterface::class,
NotificationRepository::class
);
$this->app->bind(
FaqContractInterface::class,
FaqRepository::class
);
$this->app->bind(
PldContractInterface::class,
PldRepository::class
);
$this->app->bind(
EconomyContractInterface::class,
EconomyRepository::class
);
}
/**

View File

@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
namespace App\Repositories;
use Exception;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Traits\ForwardsCalls;
abstract class AbstractRepository
{
use MethodsTrait, ForwardsCalls;
protected AbstractRepository|Model $model;
/**
* @throws BindingResolutionException
*/
public function __construct(Model $model = null)
{
$this->model = $model ?? $this::resolveModel();
}
public function __call($name, $arguments)
{
$result = $this->forwardCallTo($this->model, $name, $arguments);
if ($result === $this->model) {
return $this;
}
return $result;
}
public function __get($name)
{
return $this->model->{$name};
}
/**
* @throws BindingResolutionException
* @throws Exception
*/
final protected function resolveModel(): AbstractRepository
{
$model = app()->make($this->model);
if (!$model instanceof Model) {
throw new Exception(
"Class {$this->model} must be an instance of Illuminate\\Database\\Eloquent\\Model"
);
}
return (new static)->$model;
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\Repositories;
interface ContractInterface
{
public function all();
public function find($id);
public function create(array $params);
public function update(array $params, $id);
public function destroy($id);
public function withRelationsByAll($relations);
}

View File

@ -0,0 +1,12 @@
<?php
namespace App\Repositories\Economy;
use App\Repositories\ContractInterface;
interface EconomyContractInterface extends ContractInterface
{
public function execute($params);
}

View File

@ -0,0 +1,63 @@
<?php
namespace App\Repositories\Economy;
use App\Models\Economy;
use App\Repositories\AbstractRepository;
use App\Repository\Repository;
use App\Support\FilterQueryBuilder;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class EconomyRepository extends AbstractRepository implements EconomyContractInterface
{
public function __construct(Economy $economy)
{
parent::__construct($economy);
}
public function execute($params)
{
$test = FilterQueryBuilder::for($params);
dd($test);
$query = $this->model
->select(
$this->getRowField()
)
->join(
"dados_cadastrais",
"dados_cadastrais.cod_smart_unidade",
"=",
"economia.cod_smart_unidade",
);
dd( $query->limit(5)->get());
}
protected function where($query)
{
return $query->where(
DB::raw(
)
);
}
protected function getRowField(): array
{
return [
DB::raw("TO_CHAR(TO_DATE(economia.mes, 'YYMM'), 'MM/YYYY') as mes"),
DB::raw("TRIM(TO_CHAR(economia.custo_cativo, '99999999.99')) as custo_cativo"),
DB::raw("TRIM(TO_CHAR(economia.custo_livre, '99999999.99')) as custo_livre"),
DB::raw("COALESCE(economia.economia_mensal / NULLIF(economia.custo_livre, 0), 0) as custo")
];
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace App\Repositories\Faqs;
use App\Repositories\ContractInterface;
interface FaqContractInterface extends ContractInterface
{
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Repositories\Faqs;
use App\Models\Faq;
use App\Repositories\AbstractRepository;
class FaqRepository extends AbstractRepository implements FaqContractInterface
{
public function __construct(Faq $faq)
{
parent::__construct($faq);
}
public function intdex()
{
}
public function store()
{
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace App\Repositories;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\DB;
trait MethodsTrait
{
public function all()
{
return $this->model->all();
}
public function find($id)
{
return $this->model->find($id);
}
public function create(array $params)
{
return $this->model->create($params);
}
public function update(array $params, $id)
{
($model = $this->model->findOrFail($id))->update($params);
return $model;
}
public function destroy($id)
{
return $this->model::find($id)->delete();
}
public function withRelationsByAll($relations): Collection|array
{
return $this->model->with($relations)->get();
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace App\Repositories\Notifications;
use App\Repositories\ContractInterface;
interface NotificationContractInterface extends ContractInterface
{
}

View File

@ -0,0 +1,16 @@
<?php
namespace App\Repositories\Notifications;
use App\Models\Notifications;
use App\Repositories\AbstractRepository;
class NotificationRepository extends AbstractRepository implements NotificationContractInterface
{
public function __construct(Notifications $notification)
{
parent::__construct($notification);
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace App\Repositories\Pld;
use App\Repositories\ContractInterface;
interface PldContractInterface extends ContractInterface
{
}

View File

@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace App\Repositories\Pld;
use App\Models\Pld;
use App\Repositories\AbstractRepository;
class PldRepository extends AbstractRepository implements PldContractInterface
{
public function __construct(Pld $pld)
{
parent::__construct($pld);
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace App\Repositories\Users;
use App\Repositories\ContractInterface;
interface UserContractInterface extends ContractInterface
{
}

View File

@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace App\Repositories\Users;
use App\Models\User;
use App\Repositories\AbstractRepository;
class UserRepository extends AbstractRepository implements UserContractInterface
{
public function __construct(User $user)
{
parent::__construct($user);
}
}

View File

@ -0,0 +1,67 @@
<?php
namespace App\Repository;
use App\Helper\Model\filter\FilterBuilder;
use Exception;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Database\Eloquent\Model;
abstract class AbstractRepository
{
protected Model $model;
abstract protected function model();
/**
* @throws BindingResolutionException
*/
public function __construct()
{
$this->model = $this->resolveModel();
}
public function getJsonObject($json, $className)
{
try {
$jsonData = json_decode(json_encode($json), false);
$obj = new $className;
if (!isset($jsonData) && method_exists($obj, 'jsonToObject'))
{
throw new Exception("Request inválido");
}
$obj->jsonSetObject($jsonData);
return $obj;
} catch (Exception $ex) {
return $ex->getMessage();
}
}
public function __get($name)
{
return $this->model->{$name};
}
/**
* @throws BindingResolutionException
* @throws Exception
*/
protected function resolveModel(): Model
{
$model = app()->make($this->model());
if (!$model instanceof Model) {
throw new Exception(
"Class {$this->model()} must be an instance of Illuminate\\Database\\Eloquent\\Model"
);
}
return $model;
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace App\Repository\Economy;
use App\Models\Economy;
use App\Repository\Repository;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\DB;
class EconomyRepository extends Repository
{
public function execute($params): LengthAwarePaginator
{
$filter = $this->getFilterBuilder($params);
foreach ($filter->getFilters() as $filters)
{
if (!$filters->getRow())
{
continue;
}
$filters->setField(DB::raw("TO_CHAR(TO_DATE(economia.mes, 'YYMM'), 'MM/YYYY')"));
}
$field = collect($filter->getFields())->merge($this->getRowField())->all();
$query = $this->model->newQuery()
->select($field)
->join(
"dados_cadastrais",
"dados_cadastrais.cod_smart_unidade",
"=",
"economia.cod_smart_unidade",
);
$res = $filter->applyFilter($query);
return $res->paginate();
}
public function getRowField(): array
{
return [
DB::raw("TO_CHAR(TO_DATE(economia.mes, 'YYMM'), 'MM/YYYY') as mes"),
DB::raw("TRIM(TO_CHAR(economia.custo_cativo, '99999999.99')) as custo_cativo"),
DB::raw("TRIM(TO_CHAR(economia.custo_livre, '99999999.99')) as custo_livre"),
DB::raw("COALESCE(economia.economia_mensal / NULLIF(economia.custo_livre, 0), 0) as custo")
];
}
protected function model(): string
{
return Economy::class;
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace App\Repository\Med5min;
use App\Models\Med5min;
use App\Repository\Repository;
class Med5minRepository extends Repository
{
protected function getModel(): string
{
return Med5min::class;
}
protected function model()
{
// TODO: Implement model() method.
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace App\Repository\Pld;
use App\Models\Pld;
use App\Repository\Repository;
class PldRepository extends Repository
{
protected function getModel(): string
{
return Pld::class;
}
protected function model()
{
// TODO: Implement model() method.
}
}

View File

@ -0,0 +1,54 @@
<?php
namespace App\Repository;
use App\Helper\Model\filter\FilterBuilder;
use App\Interface\RepositoryInterfaces;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
abstract class Repository extends AbstractRepository implements RepositoryInterfaces
{
public function list(): Collection
{
return $this->model->all();
}
public function create(array $params)
{
return $this->model->create($params);
}
public function find(int $id)
{
// TODO: Implement find() method.
}
public function update(array $params, int $id)
{
return $this->model->find($id)->update( $params);
}
public function delete(int $id)
{
// TODO: Implement delete() method.
}
public function getFilterBuilder($json): ?FilterBuilder
{
return $this->getJsonObject($json, FilterBuilder::class);
}
static function logQuery($query, $type = 'get')
{
DB::enableQueryLog();
$query->$type();
dd(DB::getQueryLog());
}
}

View File

@ -0,0 +1,54 @@
<?php
namespace App\Support;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
class FilterQueryBuilder
{
protected $request;
public function __construct($request)
{
$this->initializeRequest($request);
}
// public function __construct($class)
// {
// $this->class = $class;
//
// return $this;
// }
public static function for($request)
{
return (new static($request));
}
protected function initializeRequest(?Request $request = null): static
{
$this->request = $request
? QueryBuilderRequest::fromRequest($request)
: app(QueryBuilderRequest::class);
return $this;
}
public function __get($name)
{
return $this->class->{$name};
}
public function __set($name, $value)
{
$this->class->{$name} = $value;
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace App\Support;
trait FiltersQuery
{
}

View File

@ -0,0 +1,201 @@
<?php
namespace App\Support;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
class QueryBuilderRequest extends Request
{
private static $includesArrayValueDelimiter = ',';
private static $appendsArrayValueDelimiter = ',';
private static $fieldsArrayValueDelimiter = ',';
private static $sortsArrayValueDelimiter = ',';
private static $filterArrayValueDelimiter = ',';
public static function setArrayValueDelimiter(string $delimiter): void
{
static::$filterArrayValueDelimiter = $delimiter;
static::$includesArrayValueDelimiter = $delimiter;
static::$appendsArrayValueDelimiter = $delimiter;
static::$fieldsArrayValueDelimiter = $delimiter;
static::$sortsArrayValueDelimiter = $delimiter;
}
public static function fromRequest(Request $request): self
{
return static::createFrom($request, new self());
}
public function includes(): Collection
{
$includeParameterName = config('query-builder.parameters.include');
$includeParts = $this->getRequestData($includeParameterName);
if (is_string($includeParts)) {
$includeParts = explode(static::getIncludesArrayValueDelimiter(), $includeParts);
}
return collect($includeParts)->filter();
}
public function appends(): Collection
{
$appendParameterName = config('query-builder.parameters.append');
$appendParts = $this->getRequestData($appendParameterName);
if (! is_array($appendParts) && ! is_null($appendParts)) {
$appendParts = explode(static::getAppendsArrayValueDelimiter(), $appendParts);
}
return collect($appendParts)->filter();
}
public function fields(): Collection
{
$fieldsParameterName = config('query-builder.parameters.fields');
$fieldsPerTable = collect($this->getRequestData($fieldsParameterName));
if ($fieldsPerTable->isEmpty()) {
return collect();
}
return $fieldsPerTable->map(function ($fields) {
return explode(static::getFieldsArrayValueDelimiter(), $fields);
});
}
public function sorts(): Collection
{
$sortParameterName = config('query-builder.parameters.sort');
$sortParts = $this->getRequestData($sortParameterName);
if (is_string($sortParts)) {
$sortParts = explode(static::getSortsArrayValueDelimiter(), $sortParts);
}
return collect($sortParts)->filter();
}
public function filters(): Collection
{
$filterParameterName = config('query-builder.parameters.filter');
$filterParts = $this->getRequestData($filterParameterName, []);
if (is_string($filterParts)) {
return collect();
}
$filters = collect($filterParts);
return $filters->map(function ($value) {
return $this->getFilterValue($value);
});
}
/**
* @param $value
*
* @return array|bool
*/
protected function getFilterValue($value)
{
if (is_array($value)) {
return collect($value)->map(function ($valueValue) {
return $this->getFilterValue($valueValue);
})->all();
}
if (Str::contains($value, static::getFilterArrayValueDelimiter())) {
return explode(static::getFilterArrayValueDelimiter(), $value);
}
if ($value === 'true') {
return true;
}
if ($value === 'false') {
return false;
}
return $value;
}
protected function getRequestData(?string $key = null, $default = null)
{
if (config('query-builder.request_data_source') === 'body') {
return $this->input($key, $default);
}
return $this->get($key, $default);
}
public static function setIncludesArrayValueDelimiter(string $includesArrayValueDelimiter): void
{
static::$includesArrayValueDelimiter = $includesArrayValueDelimiter;
}
public static function setAppendsArrayValueDelimiter(string $appendsArrayValueDelimiter): void
{
static::$appendsArrayValueDelimiter = $appendsArrayValueDelimiter;
}
public static function setFieldsArrayValueDelimiter(string $fieldsArrayValueDelimiter): void
{
static::$fieldsArrayValueDelimiter = $fieldsArrayValueDelimiter;
}
public static function setSortsArrayValueDelimiter(string $sortsArrayValueDelimiter): void
{
static::$sortsArrayValueDelimiter = $sortsArrayValueDelimiter;
}
public static function setFilterArrayValueDelimiter(string $filterArrayValueDelimiter): void
{
static::$filterArrayValueDelimiter = $filterArrayValueDelimiter;
}
public static function getIncludesArrayValueDelimiter(): string
{
return static::$includesArrayValueDelimiter;
}
public static function getAppendsArrayValueDelimiter(): string
{
return static::$appendsArrayValueDelimiter;
}
public static function getFieldsArrayValueDelimiter(): string
{
return static::$fieldsArrayValueDelimiter;
}
public static function getSortsArrayValueDelimiter(): string
{
return static::$sortsArrayValueDelimiter;
}
public static function getFilterArrayValueDelimiter(): string
{
return static::$filterArrayValueDelimiter;
}
public static function resetDelimiters(): void
{
self::$includesArrayValueDelimiter = ',';
self::$appendsArrayValueDelimiter = ',';
self::$fieldsArrayValueDelimiter = ',';
self::$sortsArrayValueDelimiter = ',';
self::$filterArrayValueDelimiter = ',';
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Traits;
use Illuminate\Http\JsonResponse;
trait ApiResponse
{
protected function successResponse ($data, string $message = null, int $code = 200): JsonResponse
{
return response()->json([
'status' => 'Success',
'message' => $message,
'data' => $data
], $code);
}
protected function errorResponse ($data, string $message, int $code): JsonResponse
{
return response()->json([
'status' => 'Error',
'message' => $message,
'data' => $data
], $code);
}
}

View File

@ -10,7 +10,8 @@
"laravel/framework": "^9.11",
"laravel/sanctum": "^2.14.1",
"laravel/tinker": "^2.7",
"owen-it/laravel-auditing": "^13.0"
"owen-it/laravel-auditing": "^13.0",
"umbrellio/laravel-pg-extensions": "^5.3"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",

475
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "8d22be6a885e9930e292c80a7eee9a14",
"content-hash": "d8590635104440a9a9893816079d3e83",
"packages": [
{
"name": "brick/math",
@ -141,6 +141,353 @@
},
"time": "2021-08-13T13:06:58+00:00"
},
{
"name": "doctrine/cache",
"version": "2.1.1",
"source": {
"type": "git",
"url": "https://github.com/doctrine/cache.git",
"reference": "331b4d5dbaeab3827976273e9356b3b453c300ce"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/cache/zipball/331b4d5dbaeab3827976273e9356b3b453c300ce",
"reference": "331b4d5dbaeab3827976273e9356b3b453c300ce",
"shasum": ""
},
"require": {
"php": "~7.1 || ^8.0"
},
"conflict": {
"doctrine/common": ">2.2,<2.4"
},
"require-dev": {
"alcaeus/mongo-php-adapter": "^1.1",
"cache/integration-tests": "dev-master",
"doctrine/coding-standard": "^8.0",
"mongodb/mongodb": "^1.1",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
"predis/predis": "~1.0",
"psr/cache": "^1.0 || ^2.0 || ^3.0",
"symfony/cache": "^4.4 || ^5.2 || ^6.0@dev",
"symfony/var-exporter": "^4.4 || ^5.2 || ^6.0@dev"
},
"suggest": {
"alcaeus/mongo-php-adapter": "Required to use legacy MongoDB driver"
},
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
},
{
"name": "Johannes Schmitt",
"email": "schmittjoh@gmail.com"
}
],
"description": "PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.",
"homepage": "https://www.doctrine-project.org/projects/cache.html",
"keywords": [
"abstraction",
"apcu",
"cache",
"caching",
"couchdb",
"memcached",
"php",
"redis",
"xcache"
],
"support": {
"issues": "https://github.com/doctrine/cache/issues",
"source": "https://github.com/doctrine/cache/tree/2.1.1"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fcache",
"type": "tidelift"
}
],
"time": "2021-07-17T14:49:29+00:00"
},
{
"name": "doctrine/dbal",
"version": "3.3.6",
"source": {
"type": "git",
"url": "https://github.com/doctrine/dbal.git",
"reference": "9e7f76dd1cde81c62574fdffa5a9c655c847ad21"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/dbal/zipball/9e7f76dd1cde81c62574fdffa5a9c655c847ad21",
"reference": "9e7f76dd1cde81c62574fdffa5a9c655c847ad21",
"shasum": ""
},
"require": {
"composer-runtime-api": "^2",
"doctrine/cache": "^1.11|^2.0",
"doctrine/deprecations": "^0.5.3|^1",
"doctrine/event-manager": "^1.0",
"php": "^7.3 || ^8.0",
"psr/cache": "^1|^2|^3",
"psr/log": "^1|^2|^3"
},
"require-dev": {
"doctrine/coding-standard": "9.0.0",
"jetbrains/phpstorm-stubs": "2022.1",
"phpstan/phpstan": "1.6.3",
"phpstan/phpstan-strict-rules": "^1.2",
"phpunit/phpunit": "9.5.20",
"psalm/plugin-phpunit": "0.16.1",
"squizlabs/php_codesniffer": "3.6.2",
"symfony/cache": "^5.2|^6.0",
"symfony/console": "^2.7|^3.0|^4.0|^5.0|^6.0",
"vimeo/psalm": "4.23.0"
},
"suggest": {
"symfony/console": "For helpful console commands such as SQL execution and import of files."
},
"bin": [
"bin/doctrine-dbal"
],
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\DBAL\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
}
],
"description": "Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.",
"homepage": "https://www.doctrine-project.org/projects/dbal.html",
"keywords": [
"abstraction",
"database",
"db2",
"dbal",
"mariadb",
"mssql",
"mysql",
"oci8",
"oracle",
"pdo",
"pgsql",
"postgresql",
"queryobject",
"sasql",
"sql",
"sqlite",
"sqlserver",
"sqlsrv"
],
"support": {
"issues": "https://github.com/doctrine/dbal/issues",
"source": "https://github.com/doctrine/dbal/tree/3.3.6"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdbal",
"type": "tidelift"
}
],
"time": "2022-05-02T17:21:01+00:00"
},
{
"name": "doctrine/deprecations",
"version": "v1.0.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/deprecations.git",
"reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/deprecations/zipball/0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de",
"reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de",
"shasum": ""
},
"require": {
"php": "^7.1|^8.0"
},
"require-dev": {
"doctrine/coding-standard": "^9",
"phpunit/phpunit": "^7.5|^8.5|^9.5",
"psr/log": "^1|^2|^3"
},
"suggest": {
"psr/log": "Allows logging deprecations via PSR-3 logger implementation"
},
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.",
"homepage": "https://www.doctrine-project.org/",
"support": {
"issues": "https://github.com/doctrine/deprecations/issues",
"source": "https://github.com/doctrine/deprecations/tree/v1.0.0"
},
"time": "2022-05-02T15:47:09+00:00"
},
{
"name": "doctrine/event-manager",
"version": "1.1.1",
"source": {
"type": "git",
"url": "https://github.com/doctrine/event-manager.git",
"reference": "41370af6a30faa9dc0368c4a6814d596e81aba7f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/event-manager/zipball/41370af6a30faa9dc0368c4a6814d596e81aba7f",
"reference": "41370af6a30faa9dc0368c4a6814d596e81aba7f",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
"conflict": {
"doctrine/common": "<2.9@dev"
},
"require-dev": {
"doctrine/coding-standard": "^6.0",
"phpunit/phpunit": "^7.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Doctrine\\Common\\": "lib/Doctrine/Common"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
},
{
"name": "Johannes Schmitt",
"email": "schmittjoh@gmail.com"
},
{
"name": "Marco Pivetta",
"email": "ocramius@gmail.com"
}
],
"description": "The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.",
"homepage": "https://www.doctrine-project.org/projects/event-manager.html",
"keywords": [
"event",
"event dispatcher",
"event manager",
"event system",
"events"
],
"support": {
"issues": "https://github.com/doctrine/event-manager/issues",
"source": "https://github.com/doctrine/event-manager/tree/1.1.x"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fevent-manager",
"type": "tidelift"
}
],
"time": "2020-05-29T18:28:51+00:00"
},
{
"name": "doctrine/inflector",
"version": "2.0.4",
@ -2161,6 +2508,55 @@
],
"time": "2021-12-04T23:24:31+00:00"
},
{
"name": "psr/cache",
"version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/cache.git",
"reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf",
"reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf",
"shasum": ""
},
"require": {
"php": ">=8.0.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Cache\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for caching libraries",
"keywords": [
"cache",
"psr",
"psr-6"
],
"support": {
"source": "https://github.com/php-fig/cache/tree/3.0.0"
},
"time": "2021-02-03T23:26:27+00:00"
},
{
"name": "psr/container",
"version": "2.0.2",
@ -4960,6 +5356,79 @@
},
"time": "2021-12-08T09:12:39+00:00"
},
{
"name": "umbrellio/laravel-pg-extensions",
"version": "5.3.2",
"source": {
"type": "git",
"url": "https://github.com/umbrellio/laravel-pg-extensions.git",
"reference": "c20048f51cf29a6a87cd2ba7ed0a92579f90cf18"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/umbrellio/laravel-pg-extensions/zipball/c20048f51cf29a6a87cd2ba7ed0a92579f90cf18",
"reference": "c20048f51cf29a6a87cd2ba7ed0a92579f90cf18",
"shasum": ""
},
"require": {
"doctrine/dbal": "^2.9|^3.0",
"laravel/framework": "^5.8|^6.0|^7.0|^8.0|^9.0",
"php": "^7.2|^7.3|^7.4|^8.0"
},
"require-dev": {
"codeception/codeception": "^3.0|^4.0",
"orchestra/testbench": "^3.5|^6.0|^4.0",
"php-coveralls/php-coveralls": "^2.1",
"umbrellio/code-style-php": "^1.0"
},
"suggest": {
"umbrellio/laravel-common-objects": "Package with helpers for common Laravel components",
"umbrellio/laravel-ltree": "Package for working with Postgres LTree extension"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Umbrellio\\Postgres\\UmbrellioPostgresProvider"
]
}
},
"autoload": {
"psr-4": {
"Umbrellio\\Postgres\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Vitaliy Lazeev",
"email": "vetal@umbrellio.biz"
},
{
"name": "Korben Dallas",
"email": "pvsaintpe@umbrellio.biz"
}
],
"description": "Extensions for Postgres Laravel",
"keywords": [
"builder",
"extension",
"laravel",
"migrations",
"php",
"postgres",
"postgresql",
"schema"
],
"support": {
"issues": "https://github.com/umbrellio/laravel-pg-extensions/issues",
"source": "https://github.com/umbrellio/laravel-pg-extensions"
},
"time": "2022-02-24T12:46:20+00:00"
},
{
"name": "vlucas/phpdotenv",
"version": "v5.4.1",
@ -7840,8 +8309,8 @@
"prefer-stable": true,
"prefer-lowest": false,
"platform": {
"php": "^8.0.2"
"php": "^8.1"
},
"platform-dev": [],
"plugin-api-version": "2.1.0"
"plugin-api-version": "2.3.0"
}

View File

@ -5,7 +5,7 @@ namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\News>
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Question>
*/
class NewsFactory extends Factory
{

View File

@ -15,6 +15,7 @@ return new class extends Migration
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->bigInteger('client_id', false, true)->unique()->nullable();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
@ -22,6 +23,8 @@ return new class extends Migration
$table->rememberToken();
$table->timestamps();
$table->softDeletes();
$table->index(['client_id']);
});
}

View File

@ -11,10 +11,12 @@ return new class extends Migration
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('faqs', function (Blueprint $table) {
$table->id();
$table->string('question');
$table->text('answer');
$table->timestamps();
$table->softDeletes();
});

View File

@ -14,16 +14,16 @@ return new class extends Migration
public function up(): void
{
Schema::create('dados_cadastrais', function (Blueprint $table) {
$table->bigIncrements('cod_smart_unidade');
$table->text('cliente');
$table->text('unidade');
$table->text('codigo_scde');
$table->decimal('demanda_p');
$table->decimal('demanda_fp');
$table->text('status_empresa');
$table->text('status_unidade');
$table->decimal('data_de_migracao');
$table->bigInteger('cod_smart_cliente');
$table->bigInteger('cod_smart_unidade', false)->primary()->default(null);
$table->text('cliente')->nullable();
$table->text('unidade')->nullable();
$table->text('codigo_scde')->nullable();
$table->numeric('demanda_p')->nullable();
$table->numeric('demanda_fp')->nullable();
$table->text('status_empresa')->nullable();
$table->text('status_unidade')->nullable();
$table->numeric('data_de_migracao')->nullable();
$table->bigInteger('cod_smart_cliente')->nullable();
$table->timestamps();
$table->softDeletes();
});

View File

@ -14,20 +14,23 @@ return new class extends Migration
public function up(): void
{
Schema::create('economia', function (Blueprint $table) {
$table->bigIncrements('cod_econ');
$table->bigInteger('cod_smart_unidade');
$table->text('mes text');
$table->decimal('custo_cativo');
$table->decimal('custo_livre');
$table->decimal('economia_mensal');
$table->decimal('economia_acumulada');
$table->decimal('custo_unit');
$table->boolean('dad_estimado');
$table->bigInteger('cod_te')->unsigned();
$table->bigInteger('cod_smart_unidade')->unsigned();
$table->text('mes')->nullable()->default(null);
$table->numeric('custo_cativo')->nullable();
$table->numeric('custo_livre')->nullable();
$table->numeric('economia_mensal')->nullable();
$table->numeric('economia_acumulada')->nullable();
$table->numeric('custo_unit')->nullable();
$table->boolean('dad_estimado')->nullable();
$table->timestamps();
$table->softDeletes();
$table->foreign('cod_smart_unidade', 'economia_cod_smart_unidade_fkey')
->references('cod_smart_unidade')->on('dados_cadastrais');
->references('cod_smart_unidade')->on('dados_cadastrais')->onDelete('no action')->onUpdate('no action')->notValid();
$table->primary(['cod_te','cod_smart_unidade']);
});
}

View File

@ -15,12 +15,12 @@ return new class extends Migration
{
Schema::create('pld', function (Blueprint $table) {
$table->integerIncrements('id');
$table->decimal('dia_num')->nullable();
$table->decimal('hora')->nullable();
$table->numeric('dia_num')->nullable();
$table->numeric('hora')->nullable();
$table->text('submercado')->nullable();
$table->decimal('valor')->nullable();
$table->numeric('valor')->nullable();
$table->string('mes_ref')->nullable();
$table->decimal('dia_da_semana')->nullable();
$table->numeric('dia_da_semana')->nullable();
$table->timestamps();
$table->softDeletes();
});

View File

@ -15,14 +15,14 @@ return new class extends Migration
{
Schema::create('med_5min', function (Blueprint $table) {
$table->bigIncrements('id');
$table->text('origem');
$table->decimal('dia_num');
$table->integer('minuto');
$table->decimal('ativa_consumo');
$table->decimal('ativa_geracao');
$table->decimal('reativa_consumo');
$table->decimal('reativa_geracao');
$table->text('ponto');
$table->text('origem')->nullable();
$table->decimal('dia_num')->nullable();
$table->integer('minuto')->nullable();
$table->numeric('ativa_consumo')->nullable();
$table->numeric('ativa_geracao')->nullable();
$table->numeric('reativa_consumo')->nullable();
$table->numeric('reativa_geracao')->nullable();
$table->text('ponto')->nullable();
$table->timestamps();
$table->softDeletes();
});

View File

@ -14,20 +14,22 @@ return new class extends Migration
public function up(): void
{
Schema::create('dados_te', function (Blueprint $table) {
$table->bigIncrements('cod_te');
$table->bigInteger('cod_smart_unidade')->nullable();
$table->text('mes')->nullable();;
$table->bigInteger('cod_te')->unsigned();
$table->bigInteger('cod_smart_unidade')->unsigned();
$table->text('mes')->nullable();
$table->text('operacao')->nullable();
$table->text('tipo')->nullable();
$table->decimal('montante_nf')->nullable();
$table->decimal('preco_nf')->nullable();
$table->decimal('nf_c_icms')->nullable();
$table->numeric('montante_nf')->nullable();
$table->numeric('preco_nf')->nullable();
$table->numeric('nf_c_icms')->nullable();
$table->text('perfil_contr')->nullable();
$table->timestamps();
$table->softDeletes();
$table->foreign('cod_smart_unidade', 'dados_te_cod_smart_unidade_fkey')
->references('cod_smart_unidade')->on('dados_cadastrais')->onDelete('no action')->onUpdate('no action');
->references('cod_smart_unidade')->on('dados_cadastrais')->onDelete('no action')->onUpdate('no action')->notValid();
$table->primary(['cod_te','cod_smart_unidade']);
});
}

View File

@ -15,10 +15,11 @@ return new class extends Migration
{
Schema::create('notificacoes', function (Blueprint $table) {
$table->id();
$table->string('cliente_id');
$table->text('texto');
$table->string('title');
$table->text('body')->nullable();
$table->timestamps();
$table->softDeletes();
});
}

View File

@ -15,7 +15,7 @@ return new class extends Migration
{
Schema::create('parametros', function (Blueprint $table) {
$table->integerIncrements('codigo');
$table->string('argumento');
$table->string('argumento')->nullable();
$table->timestamps();
$table->softDeletes();
});

View File

@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('notificacoes_users', function (Blueprint $table) {
// $table->id();
// $table->bigInteger('notification_id')->unsigned()->nullable();
// $table->foreign('notification_id')->references('id')->on('notificacoes')->onDelete('cascade');
// $table->bigInteger('user_id')->unsigned()->nullable();
// $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
//
//
$table->unsignedBigInteger('notification_id');
$table->unsignedBigInteger('user_id');
$table->foreign('notification_id')->references('id')->on('notificacoes')
->onUpdate('cascade')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')
->onUpdate('cascade')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('notificacoes_users');
}
};

View File

@ -10,5 +10,7 @@ class RoleUserTableSeeder extends Seeder
public function run()
{
User::findOrFail(1)->roles()->sync(1);
User::findOrFail(2)->roles()->sync(1);
User::findOrFail(3)->roles()->sync(2);
}
}

View File

@ -16,6 +16,7 @@ class UserTableSeeder extends Seeder
public function run(): void
{
User::query()->create([
'client_id' => null,
'name' => 'Admin',
'email' => 'admin@admin.com',
'password' => bcrypt('password'),
@ -23,6 +24,15 @@ class UserTableSeeder extends Seeder
]);
User::query()->create([
'client_id' => null,
'name' => 'Admin',
'email' => 'admin2@admin.com',
'password' => bcrypt('password'),
'remember_token' => null,
]);
User::query()->create([
'client_id' => 180103211,
'name' => 'Client',
'email' => 'client@client.com',
'password' => bcrypt('password'),

View File

@ -3,7 +3,7 @@ version: '3'
services:
laravel.test:
build:
context: ./docker/8.1
context: ./vendor/laravel/sail/runtimes/8.1
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'

View File

@ -17,12 +17,21 @@ use Illuminate\Support\Facades\Route;
Route::prefix('auth')->group(function (){
Route::post('login', [\App\Http\Controllers\Auth\AuthController::class, 'login']);
Route::post('logout', [\App\Http\Controllers\Auth\AuthController::class, 'logout']);
Route::post('register', [\App\Http\Controllers\Auth\RegisterController::class, 'store']);
});
Route::middleware(['auth:sanctum', 'verified'])->group(function () {
Route::get('teste', [\App\Http\Controllers\EconomyController::class, 'index']);
Route::post('pld/overview', [\App\Http\Controllers\PldController::class, 'overviewByRegion']);
Route::post('pld/list', [\App\Http\Controllers\PldController::class, 'listConsumption']);
Route::post('pld/daily', [\App\Http\Controllers\PldController::class, 'consumptionByDaily']);
Route::post('pld/schedule', [\App\Http\Controllers\PldController::class, 'consumptionBySchedule']);
Route::post('economy', \App\Http\Controllers\EconomyController::class);
Route::apiResource('user', \App\Http\Controllers\UserController::class);
Route::apiResource('notification', \App\Http\Controllers\NotificationController::class);
Route::apiResource('faq', \App\Http\Controllers\FaqController::class);
});