Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into merge/main-staging-po…
Browse files Browse the repository at this point in the history
…st-rr
  • Loading branch information
roguenet committed Nov 1, 2024
2 parents 16347cf + d6b0d21 commit 87be98f
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 0 deletions.
61 changes: 61 additions & 0 deletions app/Console/Commands/DeleteDummyBufferedPolygons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Console\Commands;

use App\Models\V2\PolygonGeometry;
use App\Models\V2\Sites\SitePolygon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class DeleteDummyBufferedPolygons extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'delete:dummy-buffered-polygons {siteId : The UUID of the site to delete polygons for}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete dummy buffered polygons for a specified site';

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$siteId = $this->argument('siteId');

DB::beginTransaction();

try {

$sitePolygons = SitePolygon::where('site_id', $siteId)->get();

foreach ($sitePolygons as $sitePolygon) {
$polygonGeometry = PolygonGeometry::where('uuid', $sitePolygon->poly_id)->first();
if ($polygonGeometry) {
$polygonGeometry->deleteWithRelated();
}
}

DB::commit();

$this->info("Dummy buffered polygons for site ID $siteId have been successfully deleted.");

} catch (\Exception $e) {
DB::rollBack();
$this->error('Failed to delete dummy buffered polygons: ' . $e->getMessage());

return Command::FAILURE;
}

return Command::SUCCESS;
}
}
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 @@ -2533,6 +2533,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 @@ -92103,6 +92103,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 @@ -330,6 +331,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 87be98f

Please sign in to comment.