From ba6ed3c74727a17a8f62c97f74e72bde2bff95ed Mon Sep 17 00:00:00 2001 From: Djonathan Date: Wed, 22 Jun 2022 18:58:01 -0300 Subject: [PATCH] Switching PLD Endpoints, Operation Summary. --- .../Controllers/InfoSectorialController.php | 31 ++++++++++++++++--- app/Http/Controllers/PldController.php | 4 ++- .../Requests/UploadInfoSectorialRequest.php | 2 +- ..._22_185209_create_info_sectorial_table.php | 3 +- routes/api.php | 6 ++-- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/InfoSectorialController.php b/app/Http/Controllers/InfoSectorialController.php index 9d9a230..6e985eb 100644 --- a/app/Http/Controllers/InfoSectorialController.php +++ b/app/Http/Controllers/InfoSectorialController.php @@ -3,19 +3,42 @@ namespace App\Http\Controllers; use App\Http\Requests\UploadInfoSectorialRequest; -use Illuminate\Http\Request; +use App\Traits\ApiResponse; +use Illuminate\Support\Str; class InfoSectorialController extends Controller { + use ApiResponse; + public function updateFile(UploadInfoSectorialRequest $uploadInfoSectorialRequest) { + $data = $uploadInfoSectorialRequest->all(); - dd($uploadInfoSectorialRequest->validated()); + if (!$uploadInfoSectorialRequest->hasFile('reportfile')) { + return $this->errorResponse( false, '', 500); + } + + $file = $uploadInfoSectorialRequest->file('reportfile'); + + $data['name'] = Str::of($file->getClientOriginalName())->explode('.')->offsetGet(0); + $extension = $file->getClientOriginalExtension(); + + $data['reportfile'] = $file->storeAs('file', $data['name'].".{$extension}"); + + dd($data); } - public function download(){ + public function download() + { + $file = public_path("/file/Clockify_Time_Report_Detailed_01_05_2022-31_05_2022.pdf"); - return response()->download(); + $path = storage_path("public/file/Clockify_Time_Report_Detailed_01_05_2022-31_05_2022.pdf"); + + + $headers = ['Content-Type: application/pdf']; + $newName = 'itsolutionstuff-pdf-file-'.time().'.pdf'; + + return response()->download($path, $newName, $headers); } } diff --git a/app/Http/Controllers/PldController.php b/app/Http/Controllers/PldController.php index c134152..ab53c2f 100644 --- a/app/Http/Controllers/PldController.php +++ b/app/Http/Controllers/PldController.php @@ -12,7 +12,6 @@ use Illuminate\Http\Response; class PldController extends Controller { - use ApiResponse; public function __construct( @@ -23,6 +22,9 @@ class PldController extends Controller { try { $response = $this->pldContract->search($request->all()); + + dd($response); + return (new PldResource($response)) ->response() ->setStatusCode(Response::HTTP_OK); diff --git a/app/Http/Requests/UploadInfoSectorialRequest.php b/app/Http/Requests/UploadInfoSectorialRequest.php index 25f3ac6..5f71bdb 100644 --- a/app/Http/Requests/UploadInfoSectorialRequest.php +++ b/app/Http/Requests/UploadInfoSectorialRequest.php @@ -13,7 +13,7 @@ class UploadInfoSectorialRequest extends FormRequest */ public function authorize() { - return false; + return true; } /** diff --git a/database/migrations/2022_06_22_185209_create_info_sectorial_table.php b/database/migrations/2022_06_22_185209_create_info_sectorial_table.php index fb12fff..d3e9c79 100644 --- a/database/migrations/2022_06_22_185209_create_info_sectorial_table.php +++ b/database/migrations/2022_06_22_185209_create_info_sectorial_table.php @@ -15,7 +15,8 @@ return new class extends Migration { Schema::create('info_sectorial', function (Blueprint $table) { $table->id(); - $table->string('file_url'); + $table->string('title'); + $table->string('path'); $table->timestamps(); $table->softDeletes(); }); diff --git a/routes/api.php b/routes/api.php index 4dd377a..c96c9a7 100644 --- a/routes/api.php +++ b/routes/api.php @@ -25,6 +25,10 @@ Route::middleware(['auth:sanctum', 'verified'])->group(function () { Route::get('faq', [\App\Http\Controllers\FaqController::class, 'index']); Route::get('faq/{faq}', [\App\Http\Controllers\FaqController::class, 'show']); + + Route::post('operation', [\App\Http\Controllers\OperationSummaryController::class, 'index']); + + Route::post('pld', [\App\Http\Controllers\PldController::class, 'index']); }); Route::middleware(['auth:sanctum', 'ability:Admin'])->group(function () { @@ -42,7 +46,6 @@ Route::middleware(['auth:sanctum', 'ability:Admin'])->group(function () { }); Route::middleware(['auth:sanctum', 'ability:Client'])->group(function () { - Route::post('pld', [\App\Http\Controllers\PldController::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']); @@ -55,7 +58,6 @@ Route::middleware(['auth:sanctum', 'ability:Client'])->group(function () { Route::post('economy/MWh', [\App\Http\Controllers\EconomyController::class, 'costMWhEconomy']); Route::post('operation/summary', [\App\Http\Controllers\OperationSummaryController::class, 'operationSummary']); - Route::post('operation', [\App\Http\Controllers\OperationSummaryController::class, 'index']); Route::post('download', [\App\Http\Controllers\InfoSectorialController::class, 'download']); });