Skip to content

Commit

Permalink
[TM-1434] add endpoint for downloading reports as s3 presigned urls (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pachonjcl authored Nov 1, 2024
1 parent 32739d5 commit d122125
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Controllers\V2\Exports;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class GeneratePreSignedURLDownloadReportController extends Controller
{
public function __invoke(Request $request, string $entity, string $framework)
{
$fileKey = 'exports/all-entity-records/'.$entity.'-'.$framework.'.csv';

$expiration = now()->addMinutes(60);

$presignedUrl = Storage::disk('s3')->temporaryUrl($fileKey, $expiration);

return response()->json(['url' => $presignedUrl]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
operationId: get-v2-admin-entity-presigned-url-framework.yml
summary: Export entities data
tags:
- V2 Projects
- V2 Sites
- V2 Nurseries
- V2 Project Reports
- V2 Site Reports
- V2 Nursery Reports
- Exports
parameters:
- type: string
name: ENTITY
in: path
required: true
description: allowed values projects/sites/nurseries/project-reports/site-reports/nursery-reports
- type: string
name: FRAMEWORK
in: path
required: true
description: allowed values terrafund/ppc
responses:
'200':
description: OK
schema:
type: object
properties:
url:
type: string
3 changes: 3 additions & 0 deletions openapi-src/V2/paths/_index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2530,6 +2530,9 @@
/v2/admin/{ENTITY}/export/{FRAMEWORK}:
get:
$ref: './Exports/get-v2-admin-entity-export-framework.yml'
/v2/admin/{ENTITY}/presigned-url/{FRAMEWORK}:
get:
$ref: './Exports/get-v2-admin-entity-presigned-url-framework.yml'
/v2/projects/{UUID}/{ENTITY}/export:
get:
$ref: './Exports/get-v2-projects-uuid-entity-export.yml'
Expand Down
31 changes: 31 additions & 0 deletions resources/docs/swagger-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92018,6 +92018,37 @@ paths:
description: OK
schema:
type: file
'/v2/admin/{ENTITY}/presigned-url/{FRAMEWORK}':
get:
operationId: get-v2-admin-entity-presigned-url-framework.yml
summary: Export entities data
tags:
- V2 Projects
- V2 Sites
- V2 Nurseries
- V2 Project Reports
- V2 Site Reports
- V2 Nursery Reports
- Exports
parameters:
- type: string
name: ENTITY
in: path
required: true
description: allowed values projects/sites/nurseries/project-reports/site-reports/nursery-reports
- type: string
name: FRAMEWORK
in: path
required: true
description: allowed values terrafund/ppc
responses:
'200':
description: OK
schema:
type: object
properties:
url:
type: string
'/v2/projects/{UUID}/{ENTITY}/export':
get:
operationId: get-v2-projects-uuid-entity-export.yml
Expand Down
2 changes: 2 additions & 0 deletions routes/api_v2.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
use App\Http\Controllers\V2\Exports\ExportImageController;
use App\Http\Controllers\V2\Exports\ExportProjectEntityAsProjectDeveloperController;
use App\Http\Controllers\V2\Exports\ExportReportEntityAsProjectDeveloperController;
use App\Http\Controllers\V2\Exports\GeneratePreSignedURLDownloadReportController;
use App\Http\Controllers\V2\Files\FilePropertiesController;
use App\Http\Controllers\V2\Files\Gallery\ViewNurseryGalleryController;
use App\Http\Controllers\V2\Files\Gallery\ViewNurseryReportGalleryController;
Expand Down Expand Up @@ -329,6 +330,7 @@
});

Route::get('/{entity}/export/{framework}', ExportAllMonitoredEntitiesController::class);
Route::get('/{entity}/presigned-url/{framework}', GeneratePreSignedURLDownloadReportController::class);

ModelInterfaceBindingMiddleware::with(EntityModel::class, function () {
Route::put('/{entity}/{status}', AdminStatusEntityController::class);
Expand Down

0 comments on commit d122125

Please sign in to comment.