Merge branch 'master' of https://gitlab.com/kluppsoftware/smart-energia-api
This commit is contained in:
commit
c439b92326
@ -9,9 +9,10 @@ use Illuminate\Auth\AuthenticationException;
|
|||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use Illuminate\Auth\Access\AuthorizationException;
|
use Illuminate\Auth\Access\AuthorizationException;
|
||||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
use Laravel\Sanctum\Exceptions\MissingAbilityException;
|
use Laravel\Sanctum\Exceptions\MissingAbilityException;
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
@ -117,6 +118,8 @@ class Handler extends ExceptionHandler
|
|||||||
return $messageCustom;
|
return $messageCustom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the exception handling callbacks for the application.
|
* Register the exception handling callbacks for the application.
|
||||||
*
|
*
|
||||||
@ -125,7 +128,13 @@ class Handler extends ExceptionHandler
|
|||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
$this->reportable(function (\Throwable $ex) {
|
$this->reportable(function (\Throwable $ex) {
|
||||||
|
$message = "Message: {$ex->getMessage()} {n} Line: {$ex->getLine()} {n} File: {$ex->getFile()}{n}Track: {$ex->getTraceAsString()} {n} {n}";
|
||||||
|
|
||||||
|
$message = preg_replace("/\{n\}/", PHP_EOL, $message);
|
||||||
|
|
||||||
|
Log::error($message);
|
||||||
|
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,8 @@ class Helpers
|
|||||||
$value,
|
$value,
|
||||||
$field,
|
$field,
|
||||||
Carbon::createFromFormat('ym', $value[$field])->locale('pt-BR')
|
Carbon::createFromFormat('ym', $value[$field])->locale('pt-BR')
|
||||||
->translatedFormat($format)))
|
->translatedFormat($format)
|
||||||
|
))
|
||||||
->all();
|
->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,15 +53,30 @@ class Helpers
|
|||||||
public static function checkDate($value): array
|
public static function checkDate($value): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$year = collect($value)->transform(fn($item, $value) => collect(Str::of($item['mes'])
|
$year = collect($value)
|
||||||
->explode('-')->offsetGet(0)))->unique()->toArray();
|
->transform(
|
||||||
$month = collect($value)->transform(fn($item, $value) => collect(Str::of($item['mes'])
|
fn ($item, $value) => collect(Str::of($item['mes'])
|
||||||
->explode('-')->offsetGet(1)))->unique()->toArray();
|
->explode('-')
|
||||||
|
->offsetGet(0))
|
||||||
|
)
|
||||||
|
->unique()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
$month = collect($value)
|
||||||
|
->transform(
|
||||||
|
fn ($item, $value) => collect(Str::of($item['mes'])
|
||||||
|
->explode('-')
|
||||||
|
->offsetGet(1))
|
||||||
|
)
|
||||||
|
->unique()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
$month_stat = end($month);
|
$month_stat = end($month);
|
||||||
$date_stat = current($year);
|
$date_stat = current($year);
|
||||||
$date_end = end($year);
|
$date_end = end($year);
|
||||||
|
|
||||||
|
if (!$date_stat) return [];
|
||||||
|
|
||||||
$start_date = date_create("{$date_stat[0]}-01-01");
|
$start_date = date_create("{$date_stat[0]}-01-01");
|
||||||
$end_date = date_create("{$date_end[0]}-{$month_stat[0]}-30");
|
$end_date = date_create("{$date_end[0]}-{$month_stat[0]}-30");
|
||||||
|
|
||||||
@ -88,6 +104,4 @@ class Helpers
|
|||||||
|
|
||||||
return $arr;
|
return $arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,10 +21,9 @@ class AuthController extends Controller
|
|||||||
abort(401, 'Inavalid Credentials');
|
abort(401, 'Inavalid Credentials');
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = User::with('roles')->firstWhere('email', $credentials['email']);
|
$user = User::with('roles')->where('email', $credentials['email'])->firstOrFail();
|
||||||
$role = $user->roles()->first();
|
|
||||||
|
|
||||||
$token = $user->createToken('API Token', [$role->name]);
|
$token = $user->createToken('API Token', $user->roles->pluck('name')->toArray());
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'token' => $token->plainTextToken,
|
'token' => $token->plainTextToken,
|
||||||
|
|||||||
@ -17,70 +17,42 @@ class EconomyController extends Controller
|
|||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected EconomyContractInterface $economyContract
|
protected EconomyContractInterface $economyContract
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
try {
|
|
||||||
$response = $this->economyContract->search($request->all());
|
$response = $this->economyContract->search($request->all());
|
||||||
return (new EconomyResource($response))
|
|
||||||
->response()
|
|
||||||
->setStatusCode(Response::HTTP_OK);
|
|
||||||
} catch (\Exception $ex) {
|
|
||||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return response()->json($response, Response::HTTP_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function grossAnnualEconomy(Request $request): JsonResponse
|
public function grossAnnualEconomy(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
$response = $this->economyContract->getGrossAnnualEconomy($request->all());
|
$response = $this->economyContract->getGrossAnnualEconomy($request->all());
|
||||||
return (new EconomyResource($response))
|
|
||||||
->response()
|
return response()->json($response, Response::HTTP_OK);
|
||||||
->setStatusCode(Response::HTTP_OK);
|
|
||||||
} catch (\Exception $ex) {
|
|
||||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function grossMonthlyEconomy(Request $request): JsonResponse
|
public function grossMonthlyEconomy(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
$response = $this->economyContract->getGrossMonthlyEconomy($request->all());
|
$response = $this->economyContract->getGrossMonthlyEconomy($request->all());
|
||||||
return (new EconomyResource($response))
|
|
||||||
->response()
|
return response()->json($response, Response::HTTP_OK);
|
||||||
->setStatusCode(Response::HTTP_OK);
|
|
||||||
} catch (\Exception $ex) {
|
|
||||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function captiveMonthlyEconomy(Request $request): JsonResponse
|
public function captiveMonthlyEconomy(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
$response = $this->economyContract->getCaptiveMonthlyEconomy($request->all());
|
$response = $this->economyContract->getCaptiveMonthlyEconomy($request->all());
|
||||||
return (new EconomyResource($response))
|
|
||||||
->response()
|
return response()->json($response, Response::HTTP_OK);
|
||||||
->setStatusCode(Response::HTTP_OK);
|
|
||||||
} catch (\Exception $ex) {
|
|
||||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function costMWhEconomy(Request $request): JsonResponse
|
public function costMWhEconomy(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
$response = $this->economyContract->getCostMWhEconomy($request->all());
|
$response = $this->economyContract->getCostMWhEconomy($request->all());
|
||||||
return (new EconomyResource($response))
|
|
||||||
->response()
|
|
||||||
->setStatusCode(Response::HTTP_OK);
|
|
||||||
} catch (\Exception $ex) {
|
|
||||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return response()->json($response, Response::HTTP_OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,14 +34,11 @@ class UserController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function index(): JsonResponse
|
public function index(): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
$response = $this->user->getOrdered();
|
$response = $this->user->getOrdered();
|
||||||
|
|
||||||
return (new UserResource($response))
|
return (new UserResource($response))
|
||||||
->response()
|
->response()
|
||||||
->setStatusCode(Response::HTTP_OK);
|
->setStatusCode(Response::HTTP_OK);
|
||||||
} catch (\Exception $ex) {
|
|
||||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,9 +49,8 @@ class UserController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function store(StoreUserRequest $request): JsonResponse
|
public function store(StoreUserRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
$data['password'] = bcrypt($request->password);
|
$data['password'] = $request->password;
|
||||||
|
|
||||||
if (!$request->hasFile('profile_picture')) {
|
if (!$request->hasFile('profile_picture')) {
|
||||||
return $this->errorResponse(false, '', 500);
|
return $this->errorResponse(false, '', 500);
|
||||||
@ -65,12 +61,10 @@ class UserController extends Controller
|
|||||||
$data['profile_picture'] = Storage::disk('s3')->url($path);
|
$data['profile_picture'] = Storage::disk('s3')->url($path);
|
||||||
$response = $this->user->create($data);
|
$response = $this->user->create($data);
|
||||||
$response->roles()->sync($data['role']);
|
$response->roles()->sync($data['role']);
|
||||||
|
|
||||||
return (new UserResource($response))
|
return (new UserResource($response))
|
||||||
->response()
|
->response()
|
||||||
->setStatusCode(Response::HTTP_CREATED);
|
->setStatusCode(Response::HTTP_CREATED);
|
||||||
} catch (\Exception $ex) {
|
|
||||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,14 +75,11 @@ class UserController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function show(int $id): JsonResponse
|
public function show(int $id): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
$response = $this->user->find($id);
|
$response = $this->user->find($id);
|
||||||
|
|
||||||
return (new UserResource($response))
|
return (new UserResource($response))
|
||||||
->response()
|
->response()
|
||||||
->setStatusCode(Response::HTTP_OK);
|
->setStatusCode(Response::HTTP_OK);
|
||||||
} catch (\Exception $ex) {
|
|
||||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -100,16 +91,13 @@ class UserController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function update(Request $request, $id): JsonResponse
|
public function update(Request $request, $id): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
$data['password'] = bcrypt($request->password);
|
$data['password'] = $request->password;
|
||||||
$response = $this->user->update($data, $id);
|
$response = $this->user->update($data, $id);
|
||||||
|
|
||||||
return (new UserResource($response))
|
return (new UserResource($response))
|
||||||
->response()
|
->response()
|
||||||
->setStatusCode(Response::HTTP_ACCEPTED);
|
->setStatusCode(Response::HTTP_ACCEPTED);
|
||||||
} catch (\Exception $ex) {
|
|
||||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -120,12 +108,9 @@ class UserController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function destroy($id): JsonResponse
|
public function destroy($id): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
$response = $this->user->destroy($id);
|
$response = $this->user->destroy($id);
|
||||||
|
|
||||||
return response()->json($response, Response::HTTP_NO_CONTENT);
|
return response()->json($response, Response::HTTP_NO_CONTENT);
|
||||||
} catch (\Exception $ex) {
|
|
||||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function importUserControll(ImportUsersWithSmartUsersRequest $request): JsonResponse
|
public function importUserControll(ImportUsersWithSmartUsersRequest $request): JsonResponse
|
||||||
|
|||||||
@ -31,6 +31,7 @@ class DadosCadastrais extends Model implements Auditing
|
|||||||
'status_unidade',
|
'status_unidade',
|
||||||
'data_de_migracao',
|
'data_de_migracao',
|
||||||
'cod_smart_cliente',
|
'cod_smart_cliente',
|
||||||
|
'cod_smart_unidade',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
'deleted_at',
|
'deleted_at',
|
||||||
|
|||||||
@ -15,19 +15,19 @@ class UserTableSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
User::query()->create([
|
// User::query()->create([
|
||||||
'client_id' => null,
|
// 'client_id' => null,
|
||||||
'name' => 'Admin',
|
// 'name' => 'Admin',
|
||||||
'email' => 'admin@admin.com',
|
// 'email' => 'admin@admin.com',
|
||||||
'password' => bcrypt('password'),
|
// 'password' => 'password',
|
||||||
'remember_token' => null,
|
// 'remember_token' => null,
|
||||||
]);
|
// ]);
|
||||||
|
|
||||||
User::query()->create([
|
User::query()->create([
|
||||||
'client_id' => null,
|
'client_id' => null,
|
||||||
'name' => 'Admin',
|
'name' => 'Admin',
|
||||||
'email' => 'admin2@admin.com',
|
'email' => 'admin2@admin.com',
|
||||||
'password' => bcrypt('password'),
|
'password' => 'password',
|
||||||
'remember_token' => null,
|
'remember_token' => null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ class UserTableSeeder extends Seeder
|
|||||||
'client_id' => 180103211,
|
'client_id' => 180103211,
|
||||||
'name' => 'Client',
|
'name' => 'Client',
|
||||||
'email' => 'client@client.com',
|
'email' => 'client@client.com',
|
||||||
'password' => bcrypt('password'),
|
'password' => 'password',
|
||||||
'remember_token' => null,
|
'remember_token' => null,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user