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\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use Laravel\Sanctum\Exceptions\MissingAbilityException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
@ -47,7 +48,7 @@ class Handler extends ExceptionHandler
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
private function messageCustom(\Throwable $ex): array
|
||||
private function messageCustom(\Throwable $ex): array
|
||||
{
|
||||
|
||||
$messageCustom = [];
|
||||
@ -95,7 +96,7 @@ class Handler extends ExceptionHandler
|
||||
Response::HTTP_INTERNAL_SERVER_ERROR
|
||||
],
|
||||
|
||||
MissingAbilityException::class => fn($_) => [
|
||||
MissingAbilityException::class => fn ($_) => [
|
||||
'Unauthorized',
|
||||
Response::HTTP_UNAUTHORIZED
|
||||
]
|
||||
@ -117,6 +118,8 @@ class Handler extends ExceptionHandler
|
||||
return $messageCustom;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Register the exception handling callbacks for the application.
|
||||
*
|
||||
@ -125,7 +128,13 @@ class Handler extends ExceptionHandler
|
||||
public function register()
|
||||
{
|
||||
$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;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -21,18 +21,19 @@ class Helpers
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function orderByDate($result, $format ='M/Y', $field = 'mes'): array
|
||||
public static function orderByDate($result, $format = 'M/Y', $field = 'mes'): array
|
||||
{
|
||||
return collect($result)
|
||||
->transform(fn($value) => Arr::set(
|
||||
->transform(fn ($value) => Arr::set(
|
||||
$value,
|
||||
$field,
|
||||
Carbon::createFromFormat('ym', $value[$field])->locale('pt-BR')
|
||||
->translatedFormat($format)))
|
||||
->translatedFormat($format)
|
||||
))
|
||||
->all();
|
||||
}
|
||||
|
||||
public static function formatOfFooter($result, $format ='d/m/Y H:i', $field = 'day_formatted'): array
|
||||
public static function formatOfFooter($result, $format = 'd/m/Y H:i', $field = 'day_formatted'): array
|
||||
{
|
||||
return collect($result)->transform(function ($item) use ($field, $format) {
|
||||
|
||||
@ -52,15 +53,30 @@ class Helpers
|
||||
public static function checkDate($value): array
|
||||
{
|
||||
|
||||
$year = collect($value)->transform(fn($item, $value) => collect(Str::of($item['mes'])
|
||||
->explode('-')->offsetGet(0)))->unique()->toArray();
|
||||
$month = collect($value)->transform(fn($item, $value) => collect(Str::of($item['mes'])
|
||||
->explode('-')->offsetGet(1)))->unique()->toArray();
|
||||
$year = collect($value)
|
||||
->transform(
|
||||
fn ($item, $value) => collect(Str::of($item['mes'])
|
||||
->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);
|
||||
$date_stat = current($year);
|
||||
$date_end = end($year);
|
||||
|
||||
if (!$date_stat) return [];
|
||||
|
||||
$start_date = date_create("{$date_stat[0]}-01-01");
|
||||
$end_date = date_create("{$date_end[0]}-{$month_stat[0]}-30");
|
||||
|
||||
@ -88,6 +104,4 @@ class Helpers
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -21,10 +21,9 @@ class AuthController extends Controller
|
||||
abort(401, 'Inavalid Credentials');
|
||||
}
|
||||
|
||||
$user = User::with('roles')->firstWhere('email', $credentials['email']);
|
||||
$role = $user->roles()->first();
|
||||
$user = User::with('roles')->where('email', $credentials['email'])->firstOrFail();
|
||||
|
||||
$token = $user->createToken('API Token', [$role->name]);
|
||||
$token = $user->createToken('API Token', $user->roles->pluck('name')->toArray());
|
||||
|
||||
return response()->json([
|
||||
'token' => $token->plainTextToken,
|
||||
|
||||
@ -17,70 +17,42 @@ class EconomyController extends Controller
|
||||
|
||||
public function __construct(
|
||||
protected EconomyContractInterface $economyContract
|
||||
)
|
||||
{
|
||||
) {
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$response = $this->economyContract->search($request->all());
|
||||
|
||||
try {
|
||||
$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
|
||||
{
|
||||
try {
|
||||
$response = $this->economyContract->getGrossAnnualEconomy($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);
|
||||
}
|
||||
$response = $this->economyContract->getGrossAnnualEconomy($request->all());
|
||||
|
||||
return response()->json($response, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function grossMonthlyEconomy(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$response = $this->economyContract->getGrossMonthlyEconomy($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);
|
||||
}
|
||||
|
||||
$response = $this->economyContract->getGrossMonthlyEconomy($request->all());
|
||||
|
||||
return response()->json($response, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function captiveMonthlyEconomy(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$response = $this->economyContract->getCaptiveMonthlyEconomy($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);
|
||||
}
|
||||
$response = $this->economyContract->getCaptiveMonthlyEconomy($request->all());
|
||||
|
||||
return response()->json($response, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function costMWhEconomy(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
$response = $this->economyContract->getCostMWhEconomy($request->all());
|
||||
|
||||
return response()->json($response, Response::HTTP_OK);
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,14 +34,11 @@ class UserController extends Controller
|
||||
*/
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
try {
|
||||
$response = $this->user->getOrdered();
|
||||
return (new UserResource($response))
|
||||
->response()
|
||||
->setStatusCode(Response::HTTP_OK);
|
||||
} catch (\Exception $ex) {
|
||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
$response = $this->user->getOrdered();
|
||||
|
||||
return (new UserResource($response))
|
||||
->response()
|
||||
->setStatusCode(Response::HTTP_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,25 +49,22 @@ class UserController extends Controller
|
||||
*/
|
||||
public function store(StoreUserRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$data = $request->all();
|
||||
$data['password'] = bcrypt($request->password);
|
||||
$data = $request->all();
|
||||
$data['password'] = $request->password;
|
||||
|
||||
if (!$request->hasFile('profile_picture')) {
|
||||
return $this->errorResponse(false, '', 500);
|
||||
}
|
||||
$file = $request->file('profile_picture');
|
||||
$path = $file->storeAs('avatars', $file->hashName(), 's3');
|
||||
|
||||
$data['profile_picture'] = Storage::disk('s3')->url($path);
|
||||
$response = $this->user->create($data);
|
||||
$response->roles()->sync($data['role']);
|
||||
return (new UserResource($response))
|
||||
->response()
|
||||
->setStatusCode(Response::HTTP_CREATED);
|
||||
} catch (\Exception $ex) {
|
||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
if (!$request->hasFile('profile_picture')) {
|
||||
return $this->errorResponse(false, '', 500);
|
||||
}
|
||||
$file = $request->file('profile_picture');
|
||||
$path = $file->storeAs('avatars', $file->hashName(), 's3');
|
||||
|
||||
$data['profile_picture'] = Storage::disk('s3')->url($path);
|
||||
$response = $this->user->create($data);
|
||||
$response->roles()->sync($data['role']);
|
||||
|
||||
return (new UserResource($response))
|
||||
->response()
|
||||
->setStatusCode(Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,14 +75,11 @@ class UserController extends Controller
|
||||
*/
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
$response = $this->user->find($id);
|
||||
return (new UserResource($response))
|
||||
->response()
|
||||
->setStatusCode(Response::HTTP_OK);
|
||||
} catch (\Exception $ex) {
|
||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
$response = $this->user->find($id);
|
||||
|
||||
return (new UserResource($response))
|
||||
->response()
|
||||
->setStatusCode(Response::HTTP_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,16 +91,13 @@ class UserController extends Controller
|
||||
*/
|
||||
public function update(Request $request, $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
$data = $request->all();
|
||||
$data['password'] = bcrypt($request->password);
|
||||
$response = $this->user->update($data, $id);
|
||||
return (new UserResource($response))
|
||||
->response()
|
||||
->setStatusCode(Response::HTTP_ACCEPTED);
|
||||
} catch (\Exception $ex) {
|
||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
$data = $request->all();
|
||||
$data['password'] = $request->password;
|
||||
$response = $this->user->update($data, $id);
|
||||
|
||||
return (new UserResource($response))
|
||||
->response()
|
||||
->setStatusCode(Response::HTTP_ACCEPTED);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -120,12 +108,9 @@ class UserController extends Controller
|
||||
*/
|
||||
public function destroy($id): JsonResponse
|
||||
{
|
||||
try {
|
||||
$response = $this->user->destroy($id);
|
||||
return response()->json($response, Response::HTTP_NO_CONTENT);
|
||||
} catch (\Exception $ex) {
|
||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
$response = $this->user->destroy($id);
|
||||
|
||||
return response()->json($response, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function importUserControll(ImportUsersWithSmartUsersRequest $request): JsonResponse
|
||||
|
||||
@ -31,6 +31,7 @@ class DadosCadastrais extends Model implements Auditing
|
||||
'status_unidade',
|
||||
'data_de_migracao',
|
||||
'cod_smart_cliente',
|
||||
'cod_smart_unidade',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
|
||||
@ -15,19 +15,19 @@ class UserTableSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
User::query()->create([
|
||||
'client_id' => null,
|
||||
'name' => 'Admin',
|
||||
'email' => 'admin@admin.com',
|
||||
'password' => bcrypt('password'),
|
||||
'remember_token' => null,
|
||||
]);
|
||||
// User::query()->create([
|
||||
// 'client_id' => null,
|
||||
// 'name' => 'Admin',
|
||||
// 'email' => 'admin@admin.com',
|
||||
// 'password' => 'password',
|
||||
// 'remember_token' => null,
|
||||
// ]);
|
||||
|
||||
User::query()->create([
|
||||
'client_id' => null,
|
||||
'name' => 'Admin',
|
||||
'email' => 'admin2@admin.com',
|
||||
'password' => bcrypt('password'),
|
||||
'password' => 'password',
|
||||
'remember_token' => null,
|
||||
]);
|
||||
|
||||
@ -35,7 +35,7 @@ class UserTableSeeder extends Seeder
|
||||
'client_id' => 180103211,
|
||||
'name' => 'Client',
|
||||
'email' => 'client@client.com',
|
||||
'password' => bcrypt('password'),
|
||||
'password' => 'password',
|
||||
'remember_token' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user