From a87e794cb5c7649c627eab3c65f721324ab2eb96 Mon Sep 17 00:00:00 2001 From: cesarLima1 Date: Thu, 23 May 2024 15:34:11 -0400 Subject: [PATCH 01/17] [TM-846] Start up controller for Site Polygons data --- app/Helpers/GeometryHelper.php | 36 +++ .../V2/Sites/SitePolygonDataController.php | 41 ++++ openapi-src/V2/definitions/SitePolygon.yml | 55 +++++ .../definitions/SitePolygonsBboxResponse.yml | 5 + .../definitions/SitePolygonsDataResponse.yml | 4 + openapi-src/V2/definitions/_index.yml | 6 + .../paths/Sites/get-v2-sites-polygon-bbox.yml | 18 ++ .../Sites/get-v2-sites-polygons-data.yml | 18 ++ openapi-src/V2/paths/_index.yml | 6 + resources/docs/swagger-v2.yml | 222 ++++++++++++++++++ routes/api_v2.php | 3 + 11 files changed, 414 insertions(+) create mode 100644 app/Helpers/GeometryHelper.php create mode 100644 app/Http/Controllers/V2/Sites/SitePolygonDataController.php create mode 100644 openapi-src/V2/definitions/SitePolygon.yml create mode 100644 openapi-src/V2/definitions/SitePolygonsBboxResponse.yml create mode 100644 openapi-src/V2/definitions/SitePolygonsDataResponse.yml create mode 100644 openapi-src/V2/paths/Sites/get-v2-sites-polygon-bbox.yml create mode 100644 openapi-src/V2/paths/Sites/get-v2-sites-polygons-data.yml diff --git a/app/Helpers/GeometryHelper.php b/app/Helpers/GeometryHelper.php new file mode 100644 index 000000000..46df71528 --- /dev/null +++ b/app/Helpers/GeometryHelper.php @@ -0,0 +1,36 @@ +selectRaw('ST_ASGEOJSON(ST_Envelope(geom)) as envelope') + ->get(); + + $maxX = $maxY = PHP_INT_MIN; + $minX = $minY = PHP_INT_MAX; + + foreach ($envelopes as $envelope) { + $geojson = json_decode($envelope->envelope); + $coordinates = $geojson->coordinates[0]; + + foreach ($coordinates as $point) { + $x = $point[0]; + $y = $point[1]; + $maxX = max($maxX, $x); + $minX = min($minX, $x); + $maxY = max($maxY, $y); + $minY = min($minY, $y); + } + } + + $bboxCoordinates = [$minX, $minY, $maxX, $maxY]; + + return $bboxCoordinates; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/V2/Sites/SitePolygonDataController.php b/app/Http/Controllers/V2/Sites/SitePolygonDataController.php new file mode 100644 index 000000000..6e16f659a --- /dev/null +++ b/app/Http/Controllers/V2/Sites/SitePolygonDataController.php @@ -0,0 +1,41 @@ +get(); + return response()->json($sitePolygons); + } catch (\Exception $e) { + Log::error($e->getMessage()); + return response()->json(['error' => 'An error occurred while fetching site polygons'], 500); + } + } + + public function getBboxOfCompleteSite($site): JsonResponse + { + try { + $sitePolygons = SitePolygon::where('site_id', $site)->get(); + if ($sitePolygons->isEmpty()) { + return response()->json(['error' => 'No polygons found for the site'], 404); + } + + $polygonsIds = $sitePolygons->pluck('poly_id'); + $bboxCoordinates = GeometryHelper::getPolygonsBbox($polygonsIds); + + return response()->json(['bbox' => $bboxCoordinates]); + } catch (\Exception $e) { + Log::error($e->getMessage()); + return response()->json(['error' => 'An error occurred while fetching the bounding box coordinates'], 500); + } + } +} diff --git a/openapi-src/V2/definitions/SitePolygon.yml b/openapi-src/V2/definitions/SitePolygon.yml new file mode 100644 index 000000000..51f5cd1e0 --- /dev/null +++ b/openapi-src/V2/definitions/SitePolygon.yml @@ -0,0 +1,55 @@ +title: SitePolygon +type: object +properties: + id: + type: integer + uuid: + type: string + project_id: + type: string + proj_name: + type: string + org_name: + type: string + poly_id: + type: string + poly_name: + type: string + site_id: + type: string + site_name: + type: string + plantstart: + type: string + format: date + plantend: + type: string + format: date + practice: + type: string + target_sys: + type: string + distr: + type: string + num_trees: + type: integer + calc_area: + type: number + format: float + created_by: + type: string + last_modified_by: + type: string + deleted_at: + type: string + format: date-time + created_at: + type: string + format: date-time + updated_at: + type: string + format: date-time + status: + type: string + country: + type: string \ No newline at end of file diff --git a/openapi-src/V2/definitions/SitePolygonsBboxResponse.yml b/openapi-src/V2/definitions/SitePolygonsBboxResponse.yml new file mode 100644 index 000000000..246a10085 --- /dev/null +++ b/openapi-src/V2/definitions/SitePolygonsBboxResponse.yml @@ -0,0 +1,5 @@ +title: SitePolygonsBboxResponse +type: object +properties: + bbox: + type: array \ No newline at end of file diff --git a/openapi-src/V2/definitions/SitePolygonsDataResponse.yml b/openapi-src/V2/definitions/SitePolygonsDataResponse.yml new file mode 100644 index 000000000..ddcedc790 --- /dev/null +++ b/openapi-src/V2/definitions/SitePolygonsDataResponse.yml @@ -0,0 +1,4 @@ +title: SitePolygonsDataResponse +type: array +items: + $ref: './_index.yml#/SitePolygon' \ No newline at end of file diff --git a/openapi-src/V2/definitions/_index.yml b/openapi-src/V2/definitions/_index.yml index fcff7d24b..12c435c3a 100644 --- a/openapi-src/V2/definitions/_index.yml +++ b/openapi-src/V2/definitions/_index.yml @@ -276,3 +276,9 @@ GeoJSON: $ref: './GeoJSON.yml' SiteGeometryPost: $ref: './SiteGeometryPost.yml' +SitePolygon: + $ref: './SitePolygon.yml' +SitePolygonsDataResponse: + $ref: './SitePolygonsDataResponse.yml' +SitePolygonsBboxResponse: + $ref: './SitePolygonsBboxResponse.yml' diff --git a/openapi-src/V2/paths/Sites/get-v2-sites-polygon-bbox.yml b/openapi-src/V2/paths/Sites/get-v2-sites-polygon-bbox.yml new file mode 100644 index 000000000..88470087e --- /dev/null +++ b/openapi-src/V2/paths/Sites/get-v2-sites-polygon-bbox.yml @@ -0,0 +1,18 @@ +summary: Get bbox for a specific site +parameters: + - in: path + name: site + required: true + type: string + description: The ID of the site +responses: + '200': + description: Successful response + content: + application/json: + schema: + $ref: '../../definitions/_index.yml#/SitePolygonsBboxResponse' + '400': + description: Bad request + '500': + description: Internal server error \ No newline at end of file diff --git a/openapi-src/V2/paths/Sites/get-v2-sites-polygons-data.yml b/openapi-src/V2/paths/Sites/get-v2-sites-polygons-data.yml new file mode 100644 index 000000000..9529905b4 --- /dev/null +++ b/openapi-src/V2/paths/Sites/get-v2-sites-polygons-data.yml @@ -0,0 +1,18 @@ +summary: Get polygons for a specific site +parameters: + - in: path + name: site + required: true + type: string + description: The ID of the site +responses: + '200': + description: Successful response + content: + application/json: + schema: + $ref: '../../definitions/_index.yml#/SitePolygonsDataResponse' + '400': + description: Bad request + '500': + description: Internal server error \ No newline at end of file diff --git a/openapi-src/V2/paths/_index.yml b/openapi-src/V2/paths/_index.yml index e1e615422..24525dd98 100644 --- a/openapi-src/V2/paths/_index.yml +++ b/openapi-src/V2/paths/_index.yml @@ -2523,3 +2523,9 @@ /v2/geometry/{UUID}: put: $ref: './Geometry/put-v2-geometry-uuid.yml' +/v2/sites/{site}/polygon: + get: + $ref: './Sites/get-v2-sites-polygons-data.yml' +/v2/sites/{site}/bbox: + get: + $ref: './Sites/get-v2-sites-polygon-bbox.yml' diff --git a/resources/docs/swagger-v2.yml b/resources/docs/swagger-v2.yml index aa91d215f..572346c91 100644 --- a/resources/docs/swagger-v2.yml +++ b/resources/docs/swagger-v2.yml @@ -44062,6 +44062,127 @@ definitions: message: type: string description: Human readable string in English to describe the error. + SitePolygon: + title: SitePolygon + type: object + properties: + id: + type: integer + uuid: + type: string + project_id: + type: string + proj_name: + type: string + org_name: + type: string + poly_id: + type: string + poly_name: + type: string + site_id: + type: string + site_name: + type: string + plantstart: + type: string + format: date + plantend: + type: string + format: date + practice: + type: string + target_sys: + type: string + distr: + type: string + num_trees: + type: integer + calc_area: + type: number + format: float + created_by: + type: string + last_modified_by: + type: string + deleted_at: + type: string + format: date-time + created_at: + type: string + format: date-time + updated_at: + type: string + format: date-time + status: + type: string + country: + type: string + SitePolygonsDataResponse: + title: SitePolygonsDataResponse + type: array + items: + title: SitePolygon + type: object + properties: + id: + type: integer + uuid: + type: string + project_id: + type: string + proj_name: + type: string + org_name: + type: string + poly_id: + type: string + poly_name: + type: string + site_id: + type: string + site_name: + type: string + plantstart: + type: string + format: date + plantend: + type: string + format: date + practice: + type: string + target_sys: + type: string + distr: + type: string + num_trees: + type: integer + calc_area: + type: number + format: float + created_by: + type: string + last_modified_by: + type: string + deleted_at: + type: string + format: date-time + created_at: + type: string + format: date-time + updated_at: + type: string + format: date-time + status: + type: string + country: + type: string + SitePolygonsBboxResponse: + title: SitePolygonsBboxResponse + type: object + properties: + bbox: + type: array paths: '/v2/tree-species/{entity}/{UUID}': get: @@ -93944,3 +94065,104 @@ paths: description: This account does not have permission to update the polygon. '404': description: Geometry was not found. + '/v2/sites/{site}/polygon': + get: + summary: Get polygons for a specific site + parameters: + - in: path + name: site + required: true + type: string + description: The ID of the site + responses: + '200': + description: Successful response + content: + application/json: + schema: + title: SitePolygonsDataResponse + type: array + items: + title: SitePolygon + type: object + properties: + id: + type: integer + uuid: + type: string + project_id: + type: string + proj_name: + type: string + org_name: + type: string + poly_id: + type: string + poly_name: + type: string + site_id: + type: string + site_name: + type: string + plantstart: + type: string + format: date + plantend: + type: string + format: date + practice: + type: string + target_sys: + type: string + distr: + type: string + num_trees: + type: integer + calc_area: + type: number + format: float + created_by: + type: string + last_modified_by: + type: string + deleted_at: + type: string + format: date-time + created_at: + type: string + format: date-time + updated_at: + type: string + format: date-time + status: + type: string + country: + type: string + '400': + description: Bad request + '500': + description: Internal server error + '/v2/sites/{site}/bbox': + get: + summary: Get bbox for a specific site + parameters: + - in: path + name: site + required: true + type: string + description: The ID of the site + responses: + '200': + description: Successful response + content: + application/json: + schema: + title: SitePolygonsBboxResponse + type: object + properties: + bbox: + type: array + '400': + description: Bad request + '500': + description: Internal server error diff --git a/routes/api_v2.php b/routes/api_v2.php index 4261cc69d..cb25a724f 100644 --- a/routes/api_v2.php +++ b/routes/api_v2.php @@ -156,6 +156,7 @@ use App\Http\Controllers\V2\Sites\Monitoring\AdminSoftDeleteSiteMonitoringController; use App\Http\Controllers\V2\Sites\Monitoring\AdminUpdateSiteMonitoringController; use App\Http\Controllers\V2\Sites\Monitoring\ViewSiteMonitoringController; +use App\Http\Controllers\V2\Sites\SitePolygonDataController; use App\Http\Controllers\V2\Sites\SoftDeleteSiteController; use App\Http\Controllers\V2\Sites\ViewASitesMonitoringsController; use App\Http\Controllers\V2\Stages\DeleteStageController; @@ -553,6 +554,8 @@ Route::delete('/', SoftDeleteSiteController::class); Route::get('/export', ExportAllSiteDataAsProjectDeveloperController::class); Route::post('/geometry', [GeometryController::class, 'storeSiteGeometry']); + Route::get('/polygon', [SitePolygonDataController::class, 'getSitePolygonData']); + Route::get('/bbox', [SitePolygonDataController::class, 'getBboxOfCompleteSite']); }); Route::prefix('geometry')->group(function () { From 11a8dcbc1894872867995d0d6cead33e577eb280 Mon Sep 17 00:00:00 2001 From: cesarLima1 Date: Thu, 23 May 2024 15:46:50 -0400 Subject: [PATCH 02/17] [TM-846] fix lint --- app/Helpers/GeometryHelper.php | 2 +- app/Http/Controllers/V2/Sites/SitePolygonDataController.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Helpers/GeometryHelper.php b/app/Helpers/GeometryHelper.php index 46df71528..56f376b93 100644 --- a/app/Helpers/GeometryHelper.php +++ b/app/Helpers/GeometryHelper.php @@ -33,4 +33,4 @@ public static function getPolygonsBbox($polygonsIds) return $bboxCoordinates; } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/V2/Sites/SitePolygonDataController.php b/app/Http/Controllers/V2/Sites/SitePolygonDataController.php index 6e16f659a..215925299 100644 --- a/app/Http/Controllers/V2/Sites/SitePolygonDataController.php +++ b/app/Http/Controllers/V2/Sites/SitePolygonDataController.php @@ -5,8 +5,8 @@ use App\Helpers\GeometryHelper; use App\Http\Controllers\Controller; use App\Models\V2\Sites\SitePolygon; -use Illuminate\Support\Facades\Log; use Illuminate\Http\JsonResponse; +use Illuminate\Support\Facades\Log; class SitePolygonDataController extends Controller { @@ -14,9 +14,11 @@ public function getSitePolygonData($site): JsonResponse { try { $sitePolygons = SitePolygon::where('site_id', $site)->get(); + return response()->json($sitePolygons); } catch (\Exception $e) { Log::error($e->getMessage()); + return response()->json(['error' => 'An error occurred while fetching site polygons'], 500); } } @@ -35,6 +37,7 @@ public function getBboxOfCompleteSite($site): JsonResponse return response()->json(['bbox' => $bboxCoordinates]); } catch (\Exception $e) { Log::error($e->getMessage()); + return response()->json(['error' => 'An error occurred while fetching the bounding box coordinates'], 500); } } From d65f520d0ca9a245696434d117ab0d1dfd90c361 Mon Sep 17 00:00:00 2001 From: cesarLima1 Date: Fri, 24 May 2024 16:20:16 -0400 Subject: [PATCH 03/17] [TM-846] add definition - create Site Polygon controller --- .../definitions/SitePolygonCreateResponse.yml | 12 ++ .../V2/definitions/SitePolygonResponse.yml | 27 +++++ openapi-src/V2/definitions/_index.yml | 4 + .../Terrafund/post-v2-site-polygon-data.yml | 28 +++++ openapi-src/V2/paths/_index.yml | 3 + resources/docs/swagger-v2.yml | 108 ++++++++++++++++++ 6 files changed, 182 insertions(+) create mode 100644 openapi-src/V2/definitions/SitePolygonCreateResponse.yml create mode 100644 openapi-src/V2/definitions/SitePolygonResponse.yml create mode 100644 openapi-src/V2/paths/Terrafund/post-v2-site-polygon-data.yml diff --git a/openapi-src/V2/definitions/SitePolygonCreateResponse.yml b/openapi-src/V2/definitions/SitePolygonCreateResponse.yml new file mode 100644 index 000000000..3c5a29921 --- /dev/null +++ b/openapi-src/V2/definitions/SitePolygonCreateResponse.yml @@ -0,0 +1,12 @@ +type: object +properties: + message: + type: string + example: Site polygon created successfully + uuid: + type: string + description: UUID of the created site polygon + area: + type: number + format: double + description: Calculated area in hectares \ No newline at end of file diff --git a/openapi-src/V2/definitions/SitePolygonResponse.yml b/openapi-src/V2/definitions/SitePolygonResponse.yml new file mode 100644 index 000000000..f2bafdd02 --- /dev/null +++ b/openapi-src/V2/definitions/SitePolygonResponse.yml @@ -0,0 +1,27 @@ +type: object +properties: + id: + type: integer + uuid: + type: string + poly_name: + type: string + plantstart: + type: string + format: date + plantend: + type: string + format: date + practice: + type: string + target_sys: + type: string + distr: + type: string + num_trees: + type: integer + calc_area: + type: number + format: float + status: + type: string \ No newline at end of file diff --git a/openapi-src/V2/definitions/_index.yml b/openapi-src/V2/definitions/_index.yml index 12c435c3a..10f0eba48 100644 --- a/openapi-src/V2/definitions/_index.yml +++ b/openapi-src/V2/definitions/_index.yml @@ -282,3 +282,7 @@ SitePolygonsDataResponse: $ref: './SitePolygonsDataResponse.yml' SitePolygonsBboxResponse: $ref: './SitePolygonsBboxResponse.yml' +SitePolygonResponse: + $ref: './SitePolygonResponse.yml' +SitePolygonCreateResponse: + $ref: './SitePolygonCreateResponse.yml' diff --git a/openapi-src/V2/paths/Terrafund/post-v2-site-polygon-data.yml b/openapi-src/V2/paths/Terrafund/post-v2-site-polygon-data.yml new file mode 100644 index 000000000..7291fb087 --- /dev/null +++ b/openapi-src/V2/paths/Terrafund/post-v2-site-polygon-data.yml @@ -0,0 +1,28 @@ +summary: Create site polygon +parameters: + - in: path + name: uuid + required: true + type: string + description: The UUID of the polygon related + - in: path + name: siteUuid + required: true + type: string + description: The UUID of the site + - in: body + name: body + required: true + schema: + $ref: '../../definitions/_index.yml#/SitePolygonResponse' +responses: + '201': + description: Successful response + content: + application/json: + schema: + $ref: '../../definitions/_index.yml#/SitePolygonCreateResponse' + '400': + description: Bad request + '500': + description: Internal server error \ No newline at end of file diff --git a/openapi-src/V2/paths/_index.yml b/openapi-src/V2/paths/_index.yml index 24525dd98..08dfd69cc 100644 --- a/openapi-src/V2/paths/_index.yml +++ b/openapi-src/V2/paths/_index.yml @@ -2529,3 +2529,6 @@ /v2/sites/{site}/bbox: get: $ref: './Sites/get-v2-sites-polygon-bbox.yml' +/site-polygon/{uuid}/{siteUuid}: + post: + $ref: './Terrafund/post-v2-site-polygon-data.yml' diff --git a/resources/docs/swagger-v2.yml b/resources/docs/swagger-v2.yml index 572346c91..54898c24b 100644 --- a/resources/docs/swagger-v2.yml +++ b/resources/docs/swagger-v2.yml @@ -44183,6 +44183,47 @@ definitions: properties: bbox: type: array + SitePolygonResponse: + type: object + properties: + id: + type: integer + uuid: + type: string + poly_name: + type: string + plantstart: + type: string + format: date + plantend: + type: string + format: date + practice: + type: string + target_sys: + type: string + distr: + type: string + num_trees: + type: integer + calc_area: + type: number + format: float + status: + type: string + SitePolygonCreateResponse: + type: object + properties: + message: + type: string + example: Site polygon created successfully + uuid: + type: string + description: UUID of the created site polygon + area: + type: number + format: double + description: Calculated area in hectares paths: '/v2/tree-species/{entity}/{UUID}': get: @@ -94166,3 +94207,70 @@ paths: description: Bad request '500': description: Internal server error + '/site-polygon/{uuid}/{siteUuid}': + post: + summary: Create site polygon + parameters: + - in: path + name: uuid + required: true + type: string + description: The UUID of the polygon related + - in: path + name: siteUuid + required: true + type: string + description: The UUID of the site + - in: body + name: body + required: true + schema: + type: object + properties: + id: + type: integer + uuid: + type: string + poly_name: + type: string + plantstart: + type: string + format: date + plantend: + type: string + format: date + practice: + type: string + target_sys: + type: string + distr: + type: string + num_trees: + type: integer + calc_area: + type: number + format: float + status: + type: string + responses: + '201': + description: Successful response + content: + application/json: + schema: + type: object + properties: + message: + type: string + example: Site polygon created successfully + uuid: + type: string + description: UUID of the created site polygon + area: + type: number + format: double + description: Calculated area in hectares + '400': + description: Bad request + '500': + description: Internal server error From 704675f4cb995d89fd70180a938c78a98804f597 Mon Sep 17 00:00:00 2001 From: cesarLima1 Date: Mon, 27 May 2024 14:01:02 -0400 Subject: [PATCH 04/17] [TM-846] get polygon bounding box --- .../TerrafundEditGeometryController.php | 14 ++++++++++ .../paths/Terrafund/get-v2-polygon-bbox.yml | 18 +++++++++++++ openapi-src/V2/paths/_index.yml | 5 +++- resources/docs/swagger-v2.yml | 26 ++++++++++++++++++- routes/api_v2.php | 2 ++ 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 openapi-src/V2/paths/Terrafund/get-v2-polygon-bbox.yml diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php index ff7fc8849..61701a062 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php @@ -2,12 +2,14 @@ namespace App\Http\Controllers\V2\Terrafund; +use App\Helpers\GeometryHelper; use App\Http\Controllers\Controller; use App\Models\V2\PolygonGeometry; use App\Models\V2\Sites\SitePolygon; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; class TerrafundEditGeometryController extends Controller { @@ -134,4 +136,16 @@ public function createSitePolygon(string $uuid, string $siteUuid, Request $reque return response()->json(['error' => 'An error occurred: ' . $e->getMessage()], 500); } } + public function getPolygonBbox(string $uuid) + { + try { + $bboxCoordinates = GeometryHelper::getPolygonsBbox([$uuid]); + + return response()->json(['bbox' => $bboxCoordinates]); + } catch (\Exception $e) { + Log::error($e->getMessage()); + + return response()->json(['error' => 'An error occurred while fetching the bounding box coordinates'], 404); + } + } } diff --git a/openapi-src/V2/paths/Terrafund/get-v2-polygon-bbox.yml b/openapi-src/V2/paths/Terrafund/get-v2-polygon-bbox.yml new file mode 100644 index 000000000..3e63b06b0 --- /dev/null +++ b/openapi-src/V2/paths/Terrafund/get-v2-polygon-bbox.yml @@ -0,0 +1,18 @@ +summary: Get bbox for a polygon +parameters: + - in: path + name: uuid + required: true + type: string + description: The UUID of the polygon +responses: + '200': + description: Successful response + content: + application/json: + schema: + $ref: '../../definitions/_index.yml#/SitePolygonsBboxResponse' + '400': + description: Bad request + '500': + description: Internal server error \ No newline at end of file diff --git a/openapi-src/V2/paths/_index.yml b/openapi-src/V2/paths/_index.yml index 08dfd69cc..0990d04b7 100644 --- a/openapi-src/V2/paths/_index.yml +++ b/openapi-src/V2/paths/_index.yml @@ -2529,6 +2529,9 @@ /v2/sites/{site}/bbox: get: $ref: './Sites/get-v2-sites-polygon-bbox.yml' -/site-polygon/{uuid}/{siteUuid}: +/v2/terrafund/site-polygon/{uuid}/{siteUuid}: post: $ref: './Terrafund/post-v2-site-polygon-data.yml' +/v2/terrafund/polygon/bbox/{uuid}: + get: + $ref: './Terrafund/get-v2-polygon-bbox.yml' diff --git a/resources/docs/swagger-v2.yml b/resources/docs/swagger-v2.yml index 54898c24b..33e949ee5 100644 --- a/resources/docs/swagger-v2.yml +++ b/resources/docs/swagger-v2.yml @@ -94207,7 +94207,7 @@ paths: description: Bad request '500': description: Internal server error - '/site-polygon/{uuid}/{siteUuid}': + '/v2/terrafund/site-polygon/{uuid}/{siteUuid}': post: summary: Create site polygon parameters: @@ -94274,3 +94274,27 @@ paths: description: Bad request '500': description: Internal server error + '/v2/terrafund/polygon/bbox/{uuid}': + get: + summary: Get bbox for a polygon + parameters: + - in: path + name: uuid + required: true + type: string + description: The UUID of the polygon + responses: + '200': + description: Successful response + content: + application/json: + schema: + title: SitePolygonsBboxResponse + type: object + properties: + bbox: + type: array + '400': + description: Bad request + '500': + description: Internal server error diff --git a/routes/api_v2.php b/routes/api_v2.php index c407ca94f..44f873bf7 100644 --- a/routes/api_v2.php +++ b/routes/api_v2.php @@ -632,6 +632,8 @@ Route::get('/polygon/geojson/{uuid}', [TerrafundEditGeometryController::class, 'getPolygonGeojson']); Route::put('/polygon/{uuid}', [TerrafundEditGeometryController::class, 'updateGeometry']); + Route::get('/polygon/bbox/{uuid}', [TerrafundEditGeometryController::class, 'getPolygonBbox']); + Route::put('/site-polygon/{uuid}', [TerrafundEditGeometryController::class, 'updateSitePolygon']); Route::post('/site-polygon/{uuid}/{siteUuid}', [TerrafundEditGeometryController::class, 'createSitePolygon']); }); From a651a27f3c854213a0d687f59e33882918a68130 Mon Sep 17 00:00:00 2001 From: cesarLima1 Date: Mon, 27 May 2024 15:32:57 -0400 Subject: [PATCH 05/17] [TM-853] add polygon and site validation controllers --- .../TerrafundCreateGeometryController.php | 99 ++++++++++- .../definitions/V2TerrafundCriteriaData.yml | 21 +++ .../definitions/V2TerrafundCriteriaSite.yml | 13 ++ openapi-src/V2/definitions/_index.yml | 4 + ...-v2-terrafund-validation-criteria-data.yml | 16 ++ ...-v2-terrafund-validation-criteria-site.yml | 16 ++ .../get-v2-terrafund-validation-polygon.yml | 16 ++ ...t-v2-terrafund-validation-sitepolygons.yml | 20 +++ openapi-src/V2/paths/_index.yml | 12 ++ resources/docs/swagger-v2.yml | 164 ++++++++++++++++++ routes/api_v2.php | 3 + 11 files changed, 382 insertions(+), 2 deletions(-) create mode 100644 openapi-src/V2/definitions/V2TerrafundCriteriaData.yml create mode 100644 openapi-src/V2/definitions/V2TerrafundCriteriaSite.yml create mode 100644 openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-criteria-data.yml create mode 100644 openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-criteria-site.yml create mode 100644 openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-polygon.yml create mode 100644 openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-sitepolygons.yml diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php index f7893f39a..a92c6a987 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php @@ -327,7 +327,7 @@ public function getCriteriaData(Request $request) $criteriaList = []; foreach ($criteriaData as $criteria) { $criteriaId = $criteria->criteria_id; - $valid = CriteriaSite::where(['polygon_id' => $uuid, 'criteria_id' => $criteriaId])->select('valid')->first()?->valid; + $valid = CriteriaSite::where(['polygon_id' => $uuid, 'criteria_id' => $criteriaId])->orderBy('created_at', 'desc')->select('valid')->first()?->valid; $criteriaList[] = [ 'criteria_id' => $criteriaId, 'latest_created_at' => $criteria->latest_created_at, @@ -437,4 +437,99 @@ private function handlePolygonValidation($polygonUuid, $response, $criteriaId): return response()->json($response); } -} + + public function runValidationPolygon(string $uuid) + { + $request = new Request(['uuid' => $uuid]); + + $this->validateOverlapping($request); + $this->checkSelfIntersection($request); + $this->validatePolygonSize($request); + $this->checkWithinCountry($request); + $this->checkBoundarySegments($request); + $this->getGeometryType($request); + $this->validateEstimatedArea($request); + $this->validateDataInDB($request); + } + + public function getValidationPolygon(Request $request) + { + + $uuid = $request->input('uuid'); + $this->runValidationPolygon($uuid); + $criteriaData = $this->getCriteriaData($request); + + return $criteriaData; + } + + public function getSiteValidationPolygon(Request $request) + { + try { + $uuid = $request->input('uuid'); + + $sitePolygonsUuids = $this->getSitePolygonsUuids($uuid); + + foreach ($sitePolygonsUuids as $polygonUuid) { + $this->runValidationPolygon($polygonUuid); + } + + return response()->json(['message' => 'Validation completed for all site polygons']); + } catch (\Exception $e) { + Log::error('Error during site validation polygon: ' . $e->getMessage()); + return response()->json(['error' => 'An error occurred during site validation'], 500); + } + } + + public function getCurrentSiteValidation(Request $request) + { + try { + $uuid = $request->input('uuid'); + + $sitePolygonsUuids = $this->getSitePolygonsUuids($uuid); + $checkedPolygons = []; + + foreach ($sitePolygonsUuids as $polygonUuid) { + $isValid = true; + $isChecked = true; + + $criteriaData = $this->fetchCriteriaData($polygonUuid); + + if (isset($criteriaData['error'])) { + Log::error('Error fetching criteria data', ['polygon_uuid' => $polygonUuid, 'error' => $criteriaData['error']]); + $isValid = false; + $isChecked = false; + } else { + foreach ($criteriaData['criteria_list'] as $criteria) { + if ($criteria['valid'] == 0) { + $isValid = false; + break; + } + } + } + + $checkedPolygons[] = [ + 'uuid' => $polygonUuid, + 'valid' => $isValid, + 'checked' => $isChecked, + ]; + } + + return $checkedPolygons; + } catch (\Exception $e) { + Log::error('Error during current site validation: ' . $e->getMessage()); + return response()->json(['error' => 'An error occurred during current site validation'], 500); + } + } + + private function getSitePolygonsUuids($uuid) + { + return SitePolygon::where('site_id', $uuid)->get()->pluck('poly_id'); + } + + private function fetchCriteriaData($polygonUuid) + { + $polygonRequest = new Request(['uuid' => $polygonUuid]); + $criteriaDataResponse = $this->getCriteriaData($polygonRequest); + return json_decode($criteriaDataResponse->getContent(), true); + } +} \ No newline at end of file diff --git a/openapi-src/V2/definitions/V2TerrafundCriteriaData.yml b/openapi-src/V2/definitions/V2TerrafundCriteriaData.yml new file mode 100644 index 000000000..4d073736b --- /dev/null +++ b/openapi-src/V2/definitions/V2TerrafundCriteriaData.yml @@ -0,0 +1,21 @@ +type: object +properties: + polygon_id: + type: string + description: The ID of the polygon + criteria_list: + type: array + description: List of validation criteria + items: + type: object + properties: + criteria_id: + type: integer + description: The ID of the criteria + latest_created_at: + type: string + format: date-time + description: The latest created at timestamp of the criteria + valid: + type: integer + description: Indicates if the criteria is valid or not (1 for valid, 0 for invalid) \ No newline at end of file diff --git a/openapi-src/V2/definitions/V2TerrafundCriteriaSite.yml b/openapi-src/V2/definitions/V2TerrafundCriteriaSite.yml new file mode 100644 index 000000000..667dc4b02 --- /dev/null +++ b/openapi-src/V2/definitions/V2TerrafundCriteriaSite.yml @@ -0,0 +1,13 @@ +type: array +items: + type: object + properties: + uuid: + type: string + description: The UUID of the polygon. + valid: + type: boolean + description: Indicates if the polygon is valid or not. + checked: + type: boolean + description: Indicates if the polygon has been checked before or not. \ No newline at end of file diff --git a/openapi-src/V2/definitions/_index.yml b/openapi-src/V2/definitions/_index.yml index 10f0eba48..596488c98 100644 --- a/openapi-src/V2/definitions/_index.yml +++ b/openapi-src/V2/definitions/_index.yml @@ -276,6 +276,10 @@ GeoJSON: $ref: './GeoJSON.yml' SiteGeometryPost: $ref: './SiteGeometryPost.yml' +V2TerrafundCriteriaData: + $ref: './V2TerrafundCriteriaData.yml' +V2TerrafundCriteriaSite: + $ref: './V2TerrafundCriteriaSite.yml' SitePolygon: $ref: './SitePolygon.yml' SitePolygonsDataResponse: diff --git a/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-criteria-data.yml b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-criteria-data.yml new file mode 100644 index 000000000..5c9f537ef --- /dev/null +++ b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-criteria-data.yml @@ -0,0 +1,16 @@ +summary: Get criteria data validation results for a polygon +parameters: + - in: query + name: uuid + required: true + description: The UUID of the polygon + type: string + schema: + type: string +responses: + '200': + description: Successful response + content: + application/json: + schema: + $ref: '../../definitions/_index.yml#/V2TerrafundCriteriaData' \ No newline at end of file diff --git a/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-criteria-site.yml b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-criteria-site.yml new file mode 100644 index 000000000..03d5c4644 --- /dev/null +++ b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-criteria-site.yml @@ -0,0 +1,16 @@ +summary: Get criteria data validation results for all polygons in a site +parameters: + - in: query + name: uuid + required: true + description: The UUID of the polygon + type: string + schema: + type: string +responses: + '200': + description: Successful response + content: + application/json: + schema: + $ref: '../../definitions/_index.yml#/V2TerrafundCriteriaSite' \ No newline at end of file diff --git a/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-polygon.yml b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-polygon.yml new file mode 100644 index 000000000..e7e7a433e --- /dev/null +++ b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-polygon.yml @@ -0,0 +1,16 @@ +summary: Get validation results for a polygon +parameters: + - in: query + name: uuid + required: true + description: The UUID of the polygon + type: string + schema: + type: string +responses: + '200': + description: Successful response + content: + application/json: + schema: + $ref: '../../definitions/_index.yml#/V2TerrafundCriteriaData' \ No newline at end of file diff --git a/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-sitepolygons.yml b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-sitepolygons.yml new file mode 100644 index 000000000..79d89df49 --- /dev/null +++ b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-sitepolygons.yml @@ -0,0 +1,20 @@ +summary: Run validation for all polygons in a site +parameters: + - in: query + name: uuid + required: true + description: The UUID of the polygon + type: string + schema: + type: string +responses: + "200": + description: Successful response + content: + application/json: + schema: + type: object + properties: + message: + type: string + description: A message indicating the completion of validation for all site polygons. \ No newline at end of file diff --git a/openapi-src/V2/paths/_index.yml b/openapi-src/V2/paths/_index.yml index 0990d04b7..1add5ad68 100644 --- a/openapi-src/V2/paths/_index.yml +++ b/openapi-src/V2/paths/_index.yml @@ -2514,6 +2514,18 @@ /v2/{ENTITY}/{UUID}/export: get: $ref: './Exports/get-v2-entity-export-uuid.yml' +'/v2/terrafund/validation/polygon': + get: + $ref: './Terrafund/get-v2-terrafund-validation-polygon.yml' +'/v2/terrafund/validation/criteria-data': + get: + $ref: './Terrafund/get-v2-terrafund-validation-criteria-data.yml' +'/v2/terrafund/validation/sitePolygons': + get: + $ref: './Terrafund/get-v2-terrafund-validation-sitepolygons.yml' +'/v2/terrafund/validation/site': + get: + $ref: './Terrafund/get-v2-terrafund-validation-criteria-site.yml' /v2/geometry/validate: post: $ref: './Geometry/post-v2-geometry-validate.yml' diff --git a/resources/docs/swagger-v2.yml b/resources/docs/swagger-v2.yml index 33e949ee5..e7094b502 100644 --- a/resources/docs/swagger-v2.yml +++ b/resources/docs/swagger-v2.yml @@ -44062,6 +44062,42 @@ definitions: message: type: string description: Human readable string in English to describe the error. + V2TerrafundCriteriaData: + type: object + properties: + polygon_id: + type: string + description: The ID of the polygon + criteria_list: + type: array + description: List of validation criteria + items: + type: object + properties: + criteria_id: + type: integer + description: The ID of the criteria + latest_created_at: + type: string + format: date-time + description: The latest created at timestamp of the criteria + valid: + type: integer + description: 'Indicates if the criteria is valid or not (1 for valid, 0 for invalid)' + V2TerrafundCriteriaSite: + type: array + items: + type: object + properties: + uuid: + type: string + description: The UUID of the polygon. + valid: + type: boolean + description: Indicates if the polygon is valid or not. + checked: + type: boolean + description: Indicates if the polygon has been checked before or not. SitePolygon: title: SitePolygon type: object @@ -93880,6 +93916,134 @@ paths: description: OK schema: type: file + /v2/terrafund/validation/polygon: + get: + summary: Get validation results for a polygon + parameters: + - in: query + name: uuid + required: true + description: The UUID of the polygon + type: string + schema: + type: string + responses: + '200': + description: Successful response + content: + application/json: + schema: + type: object + properties: + polygon_id: + type: string + description: The ID of the polygon + criteria_list: + type: array + description: List of validation criteria + items: + type: object + properties: + criteria_id: + type: integer + description: The ID of the criteria + latest_created_at: + type: string + format: date-time + description: The latest created at timestamp of the criteria + valid: + type: integer + description: 'Indicates if the criteria is valid or not (1 for valid, 0 for invalid)' + /v2/terrafund/validation/criteria-data: + get: + summary: Get criteria data validation results for a polygon + parameters: + - in: query + name: uuid + required: true + description: The UUID of the polygon + type: string + schema: + type: string + responses: + '200': + description: Successful response + content: + application/json: + schema: + type: object + properties: + polygon_id: + type: string + description: The ID of the polygon + criteria_list: + type: array + description: List of validation criteria + items: + type: object + properties: + criteria_id: + type: integer + description: The ID of the criteria + latest_created_at: + type: string + format: date-time + description: The latest created at timestamp of the criteria + valid: + type: integer + description: 'Indicates if the criteria is valid or not (1 for valid, 0 for invalid)' + /v2/terrafund/validation/sitePolygons: + get: + summary: Run validation for all polygons in a site + parameters: + - in: query + name: uuid + required: true + description: The UUID of the polygon + type: string + schema: + type: string + responses: + '200': + description: Successful response + content: + application/json: + schema: + type: object + properties: + message: + type: string + description: A message indicating the completion of validation for all site polygons. + /v2/terrafund/validation/site: + get: + summary: Get criteria data validation results for all polygons in a site + parameters: + - in: query + name: uuid + required: true + description: The UUID of the polygon + type: string + schema: + type: string + responses: + '200': + description: Successful response + content: + application/json: + schema: + type: array + items: + type: object + properties: + uuid: + type: string + description: The UUID of the polygon. + valid: + type: boolean + description: Indicates if the polygon is valid or not. + checked: + type: boolean + description: Indicates if the polygon has been checked before or not. /v2/geometry/validate: post: summary: Test a set of geometries for validity diff --git a/routes/api_v2.php b/routes/api_v2.php index 44f873bf7..e4e52cf45 100644 --- a/routes/api_v2.php +++ b/routes/api_v2.php @@ -627,6 +627,9 @@ Route::get('/validation/overlapping', [TerrafundCreateGeometryController::class, 'validateOverlapping']); Route::get('/validation/estimated-area', [TerrafundCreateGeometryController::class, 'validateEstimatedArea']); Route::get('/validation/table-data', [TerrafundCreateGeometryController::class, 'validateDataInDB']); + Route::get('/validation/polygon', [TerrafundCreateGeometryController::class, 'getValidationPolygon']); + Route::get('/validation/sitePolygons', [TerrafundCreateGeometryController::class, 'getSiteValidationPolygon']); + Route::get('/validation/site', [TerrafundCreateGeometryController::class, 'getCurrentSiteValidation']); Route::get('/polygon/{uuid}', [TerrafundEditGeometryController::class, 'getSitePolygonData']); Route::get('/polygon/geojson/{uuid}', [TerrafundEditGeometryController::class, 'getPolygonGeojson']); From 14785f62b45f39a17bea6c7df237b88958620705 Mon Sep 17 00:00:00 2001 From: JORGE Date: Mon, 27 May 2024 15:44:29 -0400 Subject: [PATCH 06/17] [TM-853] Add download functionality for single and complete geojsons --- .../TerrafundCreateGeometryController.php | 118 ++++++++++++++---- .../V2/definitions/GeoJSONResponse.yml | 35 ++++++ openapi-src/V2/definitions/_index.yml | 2 + .../get-v2-geojson-complete-download.yml | 20 +++ openapi-src/V2/paths/_index.yml | 3 + package-lock.json | 3 +- package.json | 4 +- resources/docs/swagger-v2.yml | 92 ++++++++++++++ routes/api_v2.php | 4 +- 9 files changed, 251 insertions(+), 30 deletions(-) create mode 100644 openapi-src/V2/definitions/GeoJSONResponse.yml create mode 100644 openapi-src/V2/paths/Terrafund/get-v2-geojson-complete-download.yml diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php index a92c6a987..f17aa5279 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php @@ -381,37 +381,105 @@ public function validateEstimatedArea(Request $request) ); } - public function getPolygonsAsGeoJSON() + public function getPolygonAsGeoJSONDownload(Request $request) { - $limit = 2; - $polygons = PolygonGeometry::selectRaw('ST_AsGeoJSON(geom) AS geojson') - ->orderBy('created_at', 'desc') - ->whereNotNull('geom') - ->limit($limit) - ->get(); - $features = []; - - foreach ($polygons as $polygon) { - $coordinates = json_decode($polygon->geojson)->coordinates; + try { + $uuid = $request->query('uuid'); + + $polygonGeometry = PolygonGeometry::where('uuid', $uuid) + ->select(DB::raw('ST_AsGeoJSON(geom) AS geojsonGeom')) + ->first(); + + Log::info('Polygon Geometry', ['polygonGeometry' => $polygonGeometry]); + if (! $polygonGeometry) { + return response()->json(['message' => 'No polygon geometry found for the given UUID.'], 404); + } + + $sitePolygon = SitePolygon::where('poly_id', $uuid)->first(); + if (! $sitePolygon) { + return response()->json(['message' => 'No site polygon found for the given UUID.'], 404); + } + + $properties = []; + $fieldsToValidate = [ + 'poly_name', + 'plantstart', + 'plantend', + 'practice', + 'target_sys', + 'distr', + 'num_trees', + 'uuid', + 'site_id', + ]; + foreach ($fieldsToValidate as $field) { + $properties[$field] = $sitePolygon->$field; + } + + $propertiesJson = json_encode($properties); + $feature = [ - 'type' => 'Feature', - 'geometry' => [ - 'type' => 'Polygon', - 'coordinates' => $coordinates, - ], - 'properties' => [], + 'type' => 'Feature', + 'geometry' => json_decode($polygonGeometry->geojsonGeom), + 'properties' => json_decode($propertiesJson), ]; - $features[] = $feature; - } - $geojson = [ - 'type' => 'FeatureCollection', - 'features' => $features, - ]; - // Return the GeoJSON data - return response()->json($geojson); + $featureCollection = [ + 'type' => 'FeatureCollection', + 'features' => [$feature], + ]; + + return response()->json($featureCollection); + } catch (\Exception $e) { + return response()->json(['message' => 'Failed to generate GeoJSON.', 'error' => $e->getMessage()], 500); + } } + public function getAllPolygonsAsGeoJSONDownload(Request $request) + { + try { + $siteUuid = $request->query('uuid'); + $polygonsUuids = SitePolygon::where('site_id', $siteUuid)->pluck('poly_id'); + $features = []; + foreach ($polygonsUuids as $polygonUuid) { + $feature = []; + $polygonGeometry = PolygonGeometry::where('uuid', $polygonUuid) + ->select(DB::raw('ST_AsGeoJSON(geom) AS geojsonGeom')) + ->first(); + if (! $polygonGeometry) { + return response()->json(['message' => 'No polygon geometry found for the given UUID.'], 404); + } + + $sitePolygon = SitePolygon::where('poly_id', $polygonUuid)->first(); + if (! $sitePolygon) { + return response()->json(['message' => 'No site polygon found for the given UUID.'], 404); + } + + $properties = []; + $fieldsToValidate = ['poly_name', 'plantstart', 'plantend', 'practice', 'target_sys', 'distr', 'num_trees', 'site_id']; + foreach ($fieldsToValidate as $field) { + $properties[$field] = $sitePolygon->$field; + } + + $propertiesJson = json_encode($properties); + $feature = [ + 'type' => 'Feature', + 'geometry' => json_decode($polygonGeometry->geojsonGeom), + 'properties' => json_decode($propertiesJson), + ]; + $features[] = $feature; + } + $featureCollection = [ + 'type' => 'FeatureCollection', + 'features' => $features, + ]; + + return response()->json($featureCollection); + } catch (\Exception $e) { + return response()->json(['message' => 'Failed to generate GeoJSON.', 'error' => $e->getMessage()], 500); + } + } + public function getAllCountryNames() { $countries = WorldCountryGeneralized::select('country') diff --git a/openapi-src/V2/definitions/GeoJSONResponse.yml b/openapi-src/V2/definitions/GeoJSONResponse.yml new file mode 100644 index 000000000..ab67d4340 --- /dev/null +++ b/openapi-src/V2/definitions/GeoJSONResponse.yml @@ -0,0 +1,35 @@ +type: object +properties: + type: + type: string + features: + type: array + items: + type: object + properties: + type: + type: string + geometry: + type: object + properties: + type: + type: string + coordinates: + type: array + "properties": + type: object + properties: + poly_name: + type: string + plantstart: + type: string + plantend: + type: string + practice: + type: string + target_sys: + type: string + distr: + type: string + num_trees: + type: integer \ No newline at end of file diff --git a/openapi-src/V2/definitions/_index.yml b/openapi-src/V2/definitions/_index.yml index 596488c98..66dba7cc0 100644 --- a/openapi-src/V2/definitions/_index.yml +++ b/openapi-src/V2/definitions/_index.yml @@ -290,3 +290,5 @@ SitePolygonResponse: $ref: './SitePolygonResponse.yml' SitePolygonCreateResponse: $ref: './SitePolygonCreateResponse.yml' +GeoJSONResponse: + $ref: './GeoJSONResponse.yml' \ No newline at end of file diff --git a/openapi-src/V2/paths/Terrafund/get-v2-geojson-complete-download.yml b/openapi-src/V2/paths/Terrafund/get-v2-geojson-complete-download.yml new file mode 100644 index 000000000..c5f6cdced --- /dev/null +++ b/openapi-src/V2/paths/Terrafund/get-v2-geojson-complete-download.yml @@ -0,0 +1,20 @@ +summary: Get Polygon as GeoJSON +description: | + Retrieve polygon geometry and properties as GeoJSON. +parameters: + - in: query + name: uuid + type: string + required: true + description: UUID of the polygon geometry. +responses: + '200': + description: Successful response + content: + application/json: + schema: + $ref: '../../definitions/_index.yml#/GeoJSONResponse' + '400': + description: Bad request + '500': + description: Internal server error \ No newline at end of file diff --git a/openapi-src/V2/paths/_index.yml b/openapi-src/V2/paths/_index.yml index 1add5ad68..630c7dbee 100644 --- a/openapi-src/V2/paths/_index.yml +++ b/openapi-src/V2/paths/_index.yml @@ -2547,3 +2547,6 @@ /v2/terrafund/polygon/bbox/{uuid}: get: $ref: './Terrafund/get-v2-polygon-bbox.yml' +/v2/terrafund/geojson/complete: + get: + $ref: './Terrafund/get-v2-geojson-complete-download.yml' \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 3f348d81b..492c76df4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,10 +1,9 @@ { - "name": "wri-restoration-marketplace-api", + "name": "wri-terramatch-api", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "wri-restoration-marketplace-api", "dependencies": { "swagger-ui-dist": "^3.23.3" }, diff --git a/package.json b/package.json index 6a32704fa..cbfbdd6e8 100644 --- a/package.json +++ b/package.json @@ -18,14 +18,14 @@ "laravel-mix": "^6.0.12", "lodash": "^4.17.5", "popper.js": "^1.12", + "postcss": "^8.2.8", "resolve-url-loader": "^2.3.1", "sass": "^1.15.2", "sass-loader": "^7.1.0", "swagger-cli": "^4.0.4", "swagger-ui-dist": "^3.23.3", "vue": "^2.5.17", - "vue-template-compiler": "^2.6.10", - "postcss": "^8.2.8" + "vue-template-compiler": "^2.6.10" }, "dependencies": { "swagger-ui-dist": "^3.23.3" diff --git a/resources/docs/swagger-v2.yml b/resources/docs/swagger-v2.yml index e7094b502..0441a800d 100644 --- a/resources/docs/swagger-v2.yml +++ b/resources/docs/swagger-v2.yml @@ -44260,6 +44260,42 @@ definitions: type: number format: double description: Calculated area in hectares + GeoJSONResponse: + type: object + properties: + type: + type: string + features: + type: array + items: + type: object + properties: + type: + type: string + geometry: + type: object + properties: + type: + type: string + coordinates: + type: array + properties: + type: object + properties: + poly_name: + type: string + plantstart: + type: string + plantend: + type: string + practice: + type: string + target_sys: + type: string + distr: + type: string + num_trees: + type: integer paths: '/v2/tree-species/{entity}/{UUID}': get: @@ -94462,3 +94498,59 @@ paths: description: Bad request '500': description: Internal server error + /v2/terrafund/geojson/complete: + get: + summary: Get Polygon as GeoJSON + description: | + Retrieve polygon geometry and properties as GeoJSON. + parameters: + - in: query + name: uuid + type: string + required: true + description: UUID of the polygon geometry. + responses: + '200': + description: Successful response + content: + application/json: + schema: + type: object + properties: + type: + type: string + features: + type: array + items: + type: object + properties: + type: + type: string + geometry: + type: object + properties: + type: + type: string + coordinates: + type: array + properties: + type: object + properties: + poly_name: + type: string + plantstart: + type: string + plantend: + type: string + practice: + type: string + target_sys: + type: string + distr: + type: string + num_trees: + type: integer + '400': + description: Bad request + '500': + description: Internal server error diff --git a/routes/api_v2.php b/routes/api_v2.php index e4e52cf45..f69fe624f 100644 --- a/routes/api_v2.php +++ b/routes/api_v2.php @@ -615,8 +615,10 @@ Route::post('/upload-shapefile', [TerrafundCreateGeometryController::class, 'uploadShapefile']); Route::post('/upload-kml', [TerrafundCreateGeometryController::class, 'uploadKMLFile']); Route::post('/polygon/{uuid}', [TerrafundCreateGeometryController::class, 'processGeometry']); + Route::get('/geojson/complete', [TerrafundCreateGeometryController::class, 'getPolygonAsGeoJSONDownload']); + Route::get('/geojson/site', [TerrafundCreateGeometryController::class, 'getAllPolygonsAsGeoJSONDownload']); + - Route::get('/geojson/complete', [TerrafundCreateGeometryController::class, 'getPolygonsAsGeoJSON']); Route::get('/validation/self-intersection', [TerrafundCreateGeometryController::class, 'checkSelfIntersection']); Route::get('/validation/size-limit', [TerrafundCreateGeometryController::class, 'validatePolygonSize']); Route::get('/validation/spike', [TerrafundCreateGeometryController::class, 'checkBoundarySegments']); From c411667f372a3da2682fa8ba9572e4e6cb07baa8 Mon Sep 17 00:00:00 2001 From: cesarLima1 Date: Mon, 27 May 2024 16:02:21 -0400 Subject: [PATCH 07/17] [TM-846] fix lint --- .../Controllers/V2/Terrafund/TerrafundEditGeometryController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php index 61701a062..f695e7b79 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php @@ -136,6 +136,7 @@ public function createSitePolygon(string $uuid, string $siteUuid, Request $reque return response()->json(['error' => 'An error occurred: ' . $e->getMessage()], 500); } } + public function getPolygonBbox(string $uuid) { try { From 7596b7e9aed0740381e699c2070e91b7084d426d Mon Sep 17 00:00:00 2001 From: cesarLima1 Date: Mon, 27 May 2024 16:07:05 -0400 Subject: [PATCH 08/17] [TM-853] fix lint --- .../TerrafundCreateGeometryController.php | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php index a92c6a987..bbb41782f 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php @@ -476,22 +476,23 @@ public function getSiteValidationPolygon(Request $request) return response()->json(['message' => 'Validation completed for all site polygons']); } catch (\Exception $e) { Log::error('Error during site validation polygon: ' . $e->getMessage()); + return response()->json(['error' => 'An error occurred during site validation'], 500); } } - + public function getCurrentSiteValidation(Request $request) { try { $uuid = $request->input('uuid'); - + $sitePolygonsUuids = $this->getSitePolygonsUuids($uuid); $checkedPolygons = []; - + foreach ($sitePolygonsUuids as $polygonUuid) { $isValid = true; $isChecked = true; - + $criteriaData = $this->fetchCriteriaData($polygonUuid); if (isset($criteriaData['error'])) { @@ -502,34 +503,37 @@ public function getCurrentSiteValidation(Request $request) foreach ($criteriaData['criteria_list'] as $criteria) { if ($criteria['valid'] == 0) { $isValid = false; + break; } } } - + $checkedPolygons[] = [ 'uuid' => $polygonUuid, 'valid' => $isValid, 'checked' => $isChecked, ]; } - + return $checkedPolygons; } catch (\Exception $e) { Log::error('Error during current site validation: ' . $e->getMessage()); + return response()->json(['error' => 'An error occurred during current site validation'], 500); } } - + private function getSitePolygonsUuids($uuid) { return SitePolygon::where('site_id', $uuid)->get()->pluck('poly_id'); } - + private function fetchCriteriaData($polygonUuid) { $polygonRequest = new Request(['uuid' => $polygonUuid]); $criteriaDataResponse = $this->getCriteriaData($polygonRequest); + return json_decode($criteriaDataResponse->getContent(), true); - } -} \ No newline at end of file + } +} From 307fd6270579414d6edd955a72ad11e0285edda1 Mon Sep 17 00:00:00 2001 From: JORGE Date: Mon, 27 May 2024 16:19:08 -0400 Subject: [PATCH 09/17] [TM-853] endpoint to delete polygon and site polygon --- app/Helpers/GeometryHelper.php | 81 +++++++++++++++++++ .../TerrafundEditGeometryController.php | 60 ++++++++++++++ .../Terrafund/delete-v2-polygon-uuid.yml | 10 +++ openapi-src/V2/paths/_index.yml | 5 +- resources/docs/swagger-v2.yml | 12 +++ routes/api_v2.php | 3 +- 6 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 openapi-src/V2/paths/Terrafund/delete-v2-polygon-uuid.yml diff --git a/app/Helpers/GeometryHelper.php b/app/Helpers/GeometryHelper.php index 56f376b93..a5c2e58d7 100644 --- a/app/Helpers/GeometryHelper.php +++ b/app/Helpers/GeometryHelper.php @@ -3,6 +3,8 @@ namespace App\Helpers; use App\Models\V2\PolygonGeometry; +use App\Models\V2\Projects\Project; +use Illuminate\Support\Facades\Log; class GeometryHelper { @@ -33,4 +35,83 @@ public static function getPolygonsBbox($polygonsIds) return $bboxCoordinates; } + public function updateProjectCentroid(string $projectUuid) + { + try { + $centroid = $this->centroidOfProject($projectUuid); + + if ($centroid === null) { + Log::warning("Invalid centroid for projectUuid: $projectUuid"); + } + + $centroidArray = json_decode($centroid, true); + + $latitude = $centroidArray['coordinates'][1]; + $longitude = $centroidArray['coordinates'][0]; + + + Project::where('uuid', $projectUuid) + ->update([ + 'lat' => $latitude, + 'long' => $longitude, + ]); + + + Log::info("Centroid updated for projectUuid: $projectUuid"); + + return 'Centroids updated successfully!'; + } catch (\Exception $e) { + Log::error("Error updating centroid for projectUuid: $projectUuid"); + + return response()->json([ + 'message' => 'Error updating centroid', + 'error' => $e->getMessage(), + ], 500); + } + + } + public function centroidOfProject($projectUuid) + { + $project = Project::where('uuid', $projectUuid)->first(); + + if (!$project) { + return null; + } + + $sitePolygons = $project->sitePolygons; + + if ($sitePolygons->isEmpty()) { + return null; // Return null if no polygons are found for the given projectUuid + } + + $polyIds = $sitePolygons->pluck('poly_id')->toArray(); + + $centroids = PolygonGeometry::selectRaw('ST_AsGeoJSON(ST_Centroid(geom)) AS centroid') + ->whereIn('uuid', $polyIds) + ->get(); + + if ($centroids->isEmpty()) { + return null; // Return null if no centroids are found + } + + $centroidCount = $centroids->count(); + $totalLatitude = 0; + $totalLongitude = 0; + + foreach ($centroids as $centroid) { + $centroidData = json_decode($centroid->centroid, true); + $totalLatitude += $centroidData['coordinates'][1]; + $totalLongitude += $centroidData['coordinates'][0]; + } + + $averageLatitude = $totalLatitude / $centroidCount; + $averageLongitude = $totalLongitude / $centroidCount; + + $centroidOfCentroids = json_encode([ + 'type' => 'Point', + 'coordinates' => [$averageLongitude, $averageLatitude], + ]); + + return $centroidOfCentroids; + } } diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php index f695e7b79..35bd85495 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php @@ -6,6 +6,8 @@ use App\Http\Controllers\Controller; use App\Models\V2\PolygonGeometry; use App\Models\V2\Sites\SitePolygon; +use App\Models\V2\Sites\Site; +use App\Models\V2\Projects\Project; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; @@ -27,6 +29,64 @@ public function getSitePolygonData(string $uuid) return response()->json(['message' => $e->getMessage()], 500); } } + + public function updateProjectCentroid($polygonGeometry) + { + try { + $sitePolygon = SitePolygon::where('poly_id', $polygonGeometry->uuid)->first(); + + if ($sitePolygon) { + $relatedSite = Site::where('uuid', $sitePolygon->site_id)->first(); + $project = Project::where('id', $relatedSite->project_id)->first(); + + if ($project) { + $geometryHelper = new GeometryHelper(); + $centroid = $geometryHelper->centroidOfProject($project->uuid); + + if ($centroid === null) { + Log::warning("Invalid centroid for project UUID: $project->uuid"); + } + } else { + Log::warning("Project with UUID $relatedSite->project_id not found."); + } + } else { + Log::warning("Site polygon with UUID $polygonGeometry->uuid not found."); + } + } catch (\Exception $e) { + Log::error('Error updating project centroid: ' . $e->getMessage()); + } + } + + public function deletePolygonAndSitePolygon(string $uuid) + { + try { + $polygonGeometry = PolygonGeometry::where('uuid', $uuid)->first(); + if (! $polygonGeometry) { + return response()->json(['message' => 'No polygon geometry found for the given UUID.'], 404); + } + $sitePolygon = SitePolygon::where('poly_id', $uuid)->first(); + $relatedSite = Site::where('uuid', $sitePolygon->site_id)->first(); + $projectUuid = Project::where('id', $relatedSite->project_id)->pluck('uuid')->first(); + if (! $projectUuid) { + return response()->json(['message' => 'No project found for the given UUID.'], 404); + } + if ($sitePolygon) { + Log::info("Deleting associated site polygon for UUID: $uuid"); + $sitePolygon->delete(); + } + $geometryHelper = new GeometryHelper(); + $geometryHelper->updateProjectCentroid($projectUuid); + $polygonGeometry->delete(); + Log::info("Polygon geometry and associated site polygon deleted successfully for UUID: $uuid"); + + return response()->json(['message' => 'Polygon geometry and associated site polygon deleted successfully.', 'uuid' => $uuid]); + } catch (\Exception $e) { + Log::error('An error occurred: ' . $e->getMessage()); + + // Return error response if an exception occurs + return response()->json(['error' => 'An error occurred: ' . $e->getMessage()], 500); + } + } public function updateGeometry(string $uuid, Request $request) { diff --git a/openapi-src/V2/paths/Terrafund/delete-v2-polygon-uuid.yml b/openapi-src/V2/paths/Terrafund/delete-v2-polygon-uuid.yml new file mode 100644 index 000000000..982445259 --- /dev/null +++ b/openapi-src/V2/paths/Terrafund/delete-v2-polygon-uuid.yml @@ -0,0 +1,10 @@ +summary: Delete polygon records +parameters: + - in: path + name: uuid + required: true + type: string + description: The UUID of the polygon geometry to delete +responses: + '204': + description: No Content \ No newline at end of file diff --git a/openapi-src/V2/paths/_index.yml b/openapi-src/V2/paths/_index.yml index 630c7dbee..315716c87 100644 --- a/openapi-src/V2/paths/_index.yml +++ b/openapi-src/V2/paths/_index.yml @@ -2549,4 +2549,7 @@ $ref: './Terrafund/get-v2-polygon-bbox.yml' /v2/terrafund/geojson/complete: get: - $ref: './Terrafund/get-v2-geojson-complete-download.yml' \ No newline at end of file + $ref: './Terrafund/get-v2-geojson-complete-download.yml' +/v2/terrafund/polygon/{uuid}: + delete: + $ref: './Terrafund/delete-v2-polygon-uuid.yml' \ No newline at end of file diff --git a/resources/docs/swagger-v2.yml b/resources/docs/swagger-v2.yml index 0441a800d..88fdf9a5f 100644 --- a/resources/docs/swagger-v2.yml +++ b/resources/docs/swagger-v2.yml @@ -94554,3 +94554,15 @@ paths: description: Bad request '500': description: Internal server error + '/v2/terrafund/polygon/{uuid}': + delete: + summary: Delete polygon records + parameters: + - in: path + name: uuid + required: true + type: string + description: The UUID of the polygon geometry to delete + responses: + '204': + description: No Content diff --git a/routes/api_v2.php b/routes/api_v2.php index f69fe624f..0e5efb149 100644 --- a/routes/api_v2.php +++ b/routes/api_v2.php @@ -636,7 +636,8 @@ Route::get('/polygon/{uuid}', [TerrafundEditGeometryController::class, 'getSitePolygonData']); Route::get('/polygon/geojson/{uuid}', [TerrafundEditGeometryController::class, 'getPolygonGeojson']); Route::put('/polygon/{uuid}', [TerrafundEditGeometryController::class, 'updateGeometry']); - + Route::delete('/polygon/{uuid}', [TerrafundEditGeometryController::class, 'deletePolygonAndSitePolygon']); + Route::get('/polygon/bbox/{uuid}', [TerrafundEditGeometryController::class, 'getPolygonBbox']); Route::put('/site-polygon/{uuid}', [TerrafundEditGeometryController::class, 'updateSitePolygon']); From 11d3d921b1743f5114ceedaa0fa2e9924257826b Mon Sep 17 00:00:00 2001 From: JORGE Date: Mon, 27 May 2024 16:20:17 -0400 Subject: [PATCH 10/17] [TM-853] fix lint --- app/Helpers/GeometryHelper.php | 4 +++- .../V2/Terrafund/TerrafundCreateGeometryController.php | 3 ++- .../V2/Terrafund/TerrafundEditGeometryController.php | 6 +++--- routes/api_v2.php | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/Helpers/GeometryHelper.php b/app/Helpers/GeometryHelper.php index a5c2e58d7..66e0fc28f 100644 --- a/app/Helpers/GeometryHelper.php +++ b/app/Helpers/GeometryHelper.php @@ -35,6 +35,7 @@ public static function getPolygonsBbox($polygonsIds) return $bboxCoordinates; } + public function updateProjectCentroid(string $projectUuid) { try { @@ -70,11 +71,12 @@ public function updateProjectCentroid(string $projectUuid) } } + public function centroidOfProject($projectUuid) { $project = Project::where('uuid', $projectUuid)->first(); - if (!$project) { + if (! $project) { return null; } diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php index b05125973..bcdf46221 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php @@ -434,6 +434,7 @@ public function getPolygonAsGeoJSONDownload(Request $request) return response()->json(['message' => 'Failed to generate GeoJSON.', 'error' => $e->getMessage()], 500); } } + public function getAllPolygonsAsGeoJSONDownload(Request $request) { try { @@ -479,7 +480,7 @@ public function getAllPolygonsAsGeoJSONDownload(Request $request) return response()->json(['message' => 'Failed to generate GeoJSON.', 'error' => $e->getMessage()], 500); } } - + public function getAllCountryNames() { $countries = WorldCountryGeneralized::select('country') diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php index 35bd85495..72eca3b06 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php @@ -5,9 +5,9 @@ use App\Helpers\GeometryHelper; use App\Http\Controllers\Controller; use App\Models\V2\PolygonGeometry; -use App\Models\V2\Sites\SitePolygon; -use App\Models\V2\Sites\Site; use App\Models\V2\Projects\Project; +use App\Models\V2\Sites\Site; +use App\Models\V2\Sites\SitePolygon; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; @@ -29,7 +29,7 @@ public function getSitePolygonData(string $uuid) return response()->json(['message' => $e->getMessage()], 500); } } - + public function updateProjectCentroid($polygonGeometry) { try { diff --git a/routes/api_v2.php b/routes/api_v2.php index 0e5efb149..75d840e26 100644 --- a/routes/api_v2.php +++ b/routes/api_v2.php @@ -617,7 +617,7 @@ Route::post('/polygon/{uuid}', [TerrafundCreateGeometryController::class, 'processGeometry']); Route::get('/geojson/complete', [TerrafundCreateGeometryController::class, 'getPolygonAsGeoJSONDownload']); Route::get('/geojson/site', [TerrafundCreateGeometryController::class, 'getAllPolygonsAsGeoJSONDownload']); - + Route::get('/validation/self-intersection', [TerrafundCreateGeometryController::class, 'checkSelfIntersection']); Route::get('/validation/size-limit', [TerrafundCreateGeometryController::class, 'validatePolygonSize']); @@ -637,7 +637,7 @@ Route::get('/polygon/geojson/{uuid}', [TerrafundEditGeometryController::class, 'getPolygonGeojson']); Route::put('/polygon/{uuid}', [TerrafundEditGeometryController::class, 'updateGeometry']); Route::delete('/polygon/{uuid}', [TerrafundEditGeometryController::class, 'deletePolygonAndSitePolygon']); - + Route::get('/polygon/bbox/{uuid}', [TerrafundEditGeometryController::class, 'getPolygonBbox']); Route::put('/site-polygon/{uuid}', [TerrafundEditGeometryController::class, 'updateSitePolygon']); From b5695f7978d5aa69ab4db7f491dfe1fd561d1782 Mon Sep 17 00:00:00 2001 From: cesarLima1 Date: Mon, 27 May 2024 16:41:38 -0400 Subject: [PATCH 11/17] [TM-848] add site id when uploading polygon and recalculate calc_area --- .../TerrafundCreateGeometryController.php | 13 +++-- .../TerrafundEditGeometryController.php | 51 +++++++++++++++---- 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php index bcdf46221..20cc8b3a8 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php @@ -60,14 +60,14 @@ public function storeGeometry(Request $request) /** * @throws ValidationException */ - public function insertGeojsonToDB(string $geojsonFilename) + public function insertGeojsonToDB(string $geojsonFilename, ?string $site_id = null) { $geojsonData = Storage::get("public/geojson_files/{$geojsonFilename}"); $geojson = json_decode($geojsonData, true); SitePolygonValidator::validate('FEATURE_BOUNDS', $geojson, false); - return App::make(PolygonService::class)->createGeojsonModels($geojson); + return App::make(PolygonService::class)->createGeojsonModels($geojson, [], $site_id); } public function validateDataInDB(Request $request) @@ -130,6 +130,7 @@ public function getGeometryProperties(string $geojsonFilename) public function uploadKMLFile(Request $request) { if ($request->hasFile('file')) { + $site_id = $request->input('uuid'); $kmlfile = $request->file('file'); $directory = storage_path('app/public/kml_files'); if (! file_exists($directory)) { @@ -147,7 +148,7 @@ public function uploadKMLFile(Request $request) return response()->json(['error' => 'Failed to convert KML to GeoJSON', 'message' => $process->getErrorOutput()], 500); } - $uuid = $this->insertGeojsonToDB($geojsonFilename); + $uuid = $this->insertGeojsonToDB($geojsonFilename, $site_id); if (isset($uuid['error'])) { return response()->json(['error' => 'Geometry not inserted into DB', 'message' => $uuid['error']], 500); } @@ -179,6 +180,7 @@ public function uploadShapefile(Request $request) { Log::debug('Upload Shape file data', ['request' => $request->all()]); if ($request->hasFile('file')) { + $site_id = $request->input('uuid'); $file = $request->file('file'); if ($file->getClientOriginalExtension() !== 'zip') { return response()->json(['error' => 'Only ZIP files are allowed'], 400); @@ -204,7 +206,7 @@ public function uploadShapefile(Request $request) return response()->json(['error' => 'Failed to convert Shapefile to GeoJSON', 'message' => $process->getErrorOutput()], 500); } - $uuid = $this->insertGeojsonToDB($geojsonFilename); + $uuid = $this->insertGeojsonToDB($geojsonFilename, $site_id); if (isset($uuid['error'])) { return response()->json(['error' => 'Geometry not inserted into DB', 'message' => $uuid['error']], 500); } @@ -341,6 +343,7 @@ public function getCriteriaData(Request $request) public function uploadGeoJSONFile(Request $request) { if ($request->hasFile('file')) { + $site_id = $request->input('uuid'); $file = $request->file('file'); $directory = storage_path('app/public/geojson_files'); if (! file_exists($directory)) { @@ -348,7 +351,7 @@ public function uploadGeoJSONFile(Request $request) } $filename = uniqid('geojson_file_') . '.' . $file->getClientOriginalExtension(); $file->move($directory, $filename); - $uuid = $this->insertGeojsonToDB($filename); + $uuid = $this->insertGeojsonToDB($filename, $site_id); if (is_array($uuid) && isset($uuid['error'])) { return response()->json(['error' => 'Failed to insert GeoJSON data into the database', 'message' => $uuid['error']], 500); } diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php index 72eca3b06..f1fa5cd4e 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php @@ -30,6 +30,31 @@ public function getSitePolygonData(string $uuid) } } + public function updateEstAreainSitePolygon($polygonGeometry, $geometry) + { + try { + $sitePolygon = SitePolygon::where('poly_id', $polygonGeometry->uuid)->first(); + + if ($sitePolygon) { + $geojson = json_encode($geometry); + $areaSqDegrees = DB::selectOne("SELECT ST_Area(ST_GeomFromGeoJSON('$geojson')) AS area")->area; + $latitude = DB::selectOne("SELECT ST_Y(ST_Centroid(ST_GeomFromGeoJSON('$geojson'))) AS latitude")->latitude; + $unitLatitude = 111320; + $areaSqMeters = $areaSqDegrees * pow($unitLatitude * cos(deg2rad($latitude)), 2); + $areaHectares = $areaSqMeters / 10000; + + $sitePolygon->calc_area = $areaHectares; + $sitePolygon->save(); + + Log::info("Updated area for site polygon with UUID: $sitePolygon->uuid"); + } else { + Log::warning("Updating Area: Site polygon with UUID $polygonGeometry->uuid not found."); + } + } catch (\Exception $e) { + Log::error('Error updating area in site polygon: ' . $e->getMessage()); + } + } + public function updateProjectCentroid($polygonGeometry) { try { @@ -90,16 +115,24 @@ public function deletePolygonAndSitePolygon(string $uuid) public function updateGeometry(string $uuid, Request $request) { - $polygonGeometry = PolygonGeometry::where('uuid', $uuid)->first(); - if (! $polygonGeometry) { - return response()->json(['message' => 'No polygon geometry found for the given UUID.'], 404); - } - $geometry = json_decode($request->input('geometry')); - $geom = DB::raw("ST_GeomFromGeoJSON('" . json_encode($geometry) . "')"); - $polygonGeometry->geom = $geom; - $polygonGeometry->save(); + try { + Log::info("Updating geometry for polygon with UUID: $uuid"); - return response()->json(['message' => 'Geometry updated successfully.', 'geometry' => $geometry, 'uuid' => $uuid]); + $polygonGeometry = PolygonGeometry::where('uuid', $uuid)->first(); + if (! $polygonGeometry) { + return response()->json(['message' => 'No polygon geometry found for the given UUID.'], 404); + } + $geometry = json_decode($request->input('geometry')); + $geom = DB::raw("ST_GeomFromGeoJSON('" . json_encode($geometry) . "')"); + $polygonGeometry->geom = $geom; + $polygonGeometry->save(); + $this->updateEstAreainSitePolygon($polygonGeometry, $geometry); + $this->updateProjectCentroid($polygonGeometry); + + return response()->json(['message' => 'Geometry updated successfully.', 'geometry' => $geometry, 'uuid' => $uuid]); + } catch (\Exception $e) { + return response()->json(['error' => 'An error occurred: ' . $e->getMessage()], 500); + } } public function getPolygonGeojson(string $uuid) From 4bfc457c415a18934bd2b22912dfbec2a92571f0 Mon Sep 17 00:00:00 2001 From: JORGE Date: Tue, 4 Jun 2024 12:10:22 -0400 Subject: [PATCH 12/17] [TM-853] add indentation --- .../V2/Terrafund/TerrafundCreateGeometryController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php index b05125973..169a928a3 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php @@ -387,8 +387,8 @@ public function getPolygonAsGeoJSONDownload(Request $request) $uuid = $request->query('uuid'); $polygonGeometry = PolygonGeometry::where('uuid', $uuid) - ->select(DB::raw('ST_AsGeoJSON(geom) AS geojsonGeom')) - ->first(); + ->select(DB::raw('ST_AsGeoJSON(geom) AS geojsonGeom')) + ->first(); Log::info('Polygon Geometry', ['polygonGeometry' => $polygonGeometry]); if (! $polygonGeometry) { @@ -443,8 +443,8 @@ public function getAllPolygonsAsGeoJSONDownload(Request $request) foreach ($polygonsUuids as $polygonUuid) { $feature = []; $polygonGeometry = PolygonGeometry::where('uuid', $polygonUuid) - ->select(DB::raw('ST_AsGeoJSON(geom) AS geojsonGeom')) - ->first(); + ->select(DB::raw('ST_AsGeoJSON(geom) AS geojsonGeom')) + ->first(); if (! $polygonGeometry) { return response()->json(['message' => 'No polygon geometry found for the given UUID.'], 404); } From 6761d2ff2ba3f744c5d6f3f9f89e62f794e96908 Mon Sep 17 00:00:00 2001 From: JORGE Date: Tue, 4 Jun 2024 12:27:05 -0400 Subject: [PATCH 13/17] [TM-853] remove redundance and nesting --- app/Helpers/GeometryHelper.php | 8 +++--- .../TerrafundEditGeometryController.php | 27 +++++++++---------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/app/Helpers/GeometryHelper.php b/app/Helpers/GeometryHelper.php index 66e0fc28f..13b3b1bc2 100644 --- a/app/Helpers/GeometryHelper.php +++ b/app/Helpers/GeometryHelper.php @@ -80,14 +80,12 @@ public function centroidOfProject($projectUuid) return null; } - $sitePolygons = $project->sitePolygons; + $polyIds = $project->sitePolygons()->pluck('poly_id')->toArray(); - if ($sitePolygons->isEmpty()) { - return null; // Return null if no polygons are found for the given projectUuid + if (empty($polyIds)) { + return null; } - $polyIds = $sitePolygons->pluck('poly_id')->toArray(); - $centroids = PolygonGeometry::selectRaw('ST_AsGeoJSON(ST_Centroid(geom)) AS centroid') ->whereIn('uuid', $polyIds) ->get(); diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php index 72eca3b06..f8ea89b89 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php @@ -34,23 +34,22 @@ public function updateProjectCentroid($polygonGeometry) { try { $sitePolygon = SitePolygon::where('poly_id', $polygonGeometry->uuid)->first(); + if (!$sitePolygon) { + Log::warning("Site polygon with UUID $polygonGeometry->uuid not found."); + return null; + } + $relatedSite = Site::where('uuid', $sitePolygon->site_id)->first(); + $project = Project::where('id', $relatedSite->project_id)->first(); - if ($sitePolygon) { - $relatedSite = Site::where('uuid', $sitePolygon->site_id)->first(); - $project = Project::where('id', $relatedSite->project_id)->first(); - - if ($project) { - $geometryHelper = new GeometryHelper(); - $centroid = $geometryHelper->centroidOfProject($project->uuid); - - if ($centroid === null) { - Log::warning("Invalid centroid for project UUID: $project->uuid"); - } - } else { - Log::warning("Project with UUID $relatedSite->project_id not found."); + if ($project) { + $geometryHelper = new GeometryHelper(); + $centroid = $geometryHelper->centroidOfProject($project->uuid); + + if ($centroid === null) { + Log::warning("Invalid centroid for project UUID: $project->uuid"); } } else { - Log::warning("Site polygon with UUID $polygonGeometry->uuid not found."); + Log::warning("Project with UUID $relatedSite->project_id not found."); } } catch (\Exception $e) { Log::error('Error updating project centroid: ' . $e->getMessage()); From 81beb5741924cbb14820b3e9ba4222858726f746 Mon Sep 17 00:00:00 2001 From: cesarLima1 Date: Tue, 4 Jun 2024 12:28:28 -0400 Subject: [PATCH 14/17] [TM-848] fix: remove site_id from createGeojsonModels function --- .../V2/Terrafund/TerrafundCreateGeometryController.php | 2 +- app/Services/PolygonService.php | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php index 20cc8b3a8..c04592f7d 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php @@ -67,7 +67,7 @@ public function insertGeojsonToDB(string $geojsonFilename, ?string $site_id = nu SitePolygonValidator::validate('FEATURE_BOUNDS', $geojson, false); - return App::make(PolygonService::class)->createGeojsonModels($geojson, [], $site_id); + return App::make(PolygonService::class)->createGeojsonModels($geojson, ['site_id' => $site_id]); } public function validateDataInDB(Request $request) diff --git a/app/Services/PolygonService.php b/app/Services/PolygonService.php index 329416709..2d4e9610c 100644 --- a/app/Services/PolygonService.php +++ b/app/Services/PolygonService.php @@ -24,13 +24,10 @@ class PolygonService public const SCHEMA_CRITERIA_ID = 13; public const DATA_CRITERIA_ID = 14; - public function createGeojsonModels($geojson, $sitePolygonProperties = [], ?string $site_id = null): array + public function createGeojsonModels($geojson, $sitePolygonProperties = []): array { $uuids = []; foreach ($geojson['features'] as $feature) { - if ($site_id !== null) { - $feature['properties']['site_id'] = $site_id; - } if ($feature['geometry']['type'] === 'Polygon') { $data = $this->insertSinglePolygon($feature['geometry']); $uuids[] = $data['uuid']; From 69bbf03f4636c5e8a7e8401fb9fdb64f8a618655 Mon Sep 17 00:00:00 2001 From: JORGE Date: Tue, 4 Jun 2024 14:43:16 -0400 Subject: [PATCH 15/17] [TM-853] remove redundan query --- .../V2/Terrafund/TerrafundEditGeometryController.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php index f8ea89b89..dede162af 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php @@ -38,8 +38,7 @@ public function updateProjectCentroid($polygonGeometry) Log::warning("Site polygon with UUID $polygonGeometry->uuid not found."); return null; } - $relatedSite = Site::where('uuid', $sitePolygon->site_id)->first(); - $project = Project::where('id', $relatedSite->project_id)->first(); + $project = $sitePolygon->project; if ($project) { $geometryHelper = new GeometryHelper(); @@ -49,7 +48,7 @@ public function updateProjectCentroid($polygonGeometry) Log::warning("Invalid centroid for project UUID: $project->uuid"); } } else { - Log::warning("Project with UUID $relatedSite->project_id not found."); + Log::warning("Project UUID not found."); } } catch (\Exception $e) { Log::error('Error updating project centroid: ' . $e->getMessage()); @@ -64,9 +63,8 @@ public function deletePolygonAndSitePolygon(string $uuid) return response()->json(['message' => 'No polygon geometry found for the given UUID.'], 404); } $sitePolygon = SitePolygon::where('poly_id', $uuid)->first(); - $relatedSite = Site::where('uuid', $sitePolygon->site_id)->first(); - $projectUuid = Project::where('id', $relatedSite->project_id)->pluck('uuid')->first(); - if (! $projectUuid) { + $project = $sitePolygon->project; + if (! $project) { return response()->json(['message' => 'No project found for the given UUID.'], 404); } if ($sitePolygon) { @@ -74,7 +72,7 @@ public function deletePolygonAndSitePolygon(string $uuid) $sitePolygon->delete(); } $geometryHelper = new GeometryHelper(); - $geometryHelper->updateProjectCentroid($projectUuid); + $geometryHelper->updateProjectCentroid($project->uuid); $polygonGeometry->delete(); Log::info("Polygon geometry and associated site polygon deleted successfully for UUID: $uuid"); From d01369f7ea5579a5ffb5726a9614502fb8dacc25 Mon Sep 17 00:00:00 2001 From: cesarLima1 Date: Thu, 6 Jun 2024 12:08:15 -0400 Subject: [PATCH 16/17] [TM-846] make lint fix --- app/Helpers/GeometryHelper.php | 2 +- .../V2/Terrafund/TerrafundEditGeometryController.php | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/Helpers/GeometryHelper.php b/app/Helpers/GeometryHelper.php index 13b3b1bc2..337249d85 100644 --- a/app/Helpers/GeometryHelper.php +++ b/app/Helpers/GeometryHelper.php @@ -83,7 +83,7 @@ public function centroidOfProject($projectUuid) $polyIds = $project->sitePolygons()->pluck('poly_id')->toArray(); if (empty($polyIds)) { - return null; + return null; } $centroids = PolygonGeometry::selectRaw('ST_AsGeoJSON(ST_Centroid(geom)) AS centroid') diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php index 0de39f676..fdeea0402 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php @@ -5,8 +5,6 @@ use App\Helpers\GeometryHelper; use App\Http\Controllers\Controller; use App\Models\V2\PolygonGeometry; -use App\Models\V2\Projects\Project; -use App\Models\V2\Sites\Site; use App\Models\V2\Sites\SitePolygon; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -59,9 +57,10 @@ public function updateProjectCentroid($polygonGeometry) { try { $sitePolygon = SitePolygon::where('poly_id', $polygonGeometry->uuid)->first(); - if (!$sitePolygon) { - Log::warning("Site polygon with UUID $polygonGeometry->uuid not found."); - return null; + if (! $sitePolygon) { + Log::warning("Site polygon with UUID $polygonGeometry->uuid not found."); + + return null; } $project = $sitePolygon->project; @@ -73,7 +72,7 @@ public function updateProjectCentroid($polygonGeometry) Log::warning("Invalid centroid for project UUID: $project->uuid"); } } else { - Log::warning("Project UUID not found."); + Log::warning('Project UUID not found.'); } } catch (\Exception $e) { Log::error('Error updating project centroid: ' . $e->getMessage()); From b36535288eab5d5427c4924c527f61bd12ec3572 Mon Sep 17 00:00:00 2001 From: cesarLima1 Date: Thu, 6 Jun 2024 12:59:22 -0400 Subject: [PATCH 17/17] [TM-846] fix issues with definitions in openapi src folder --- .../definitions/SitePolygonsBboxResponse.yml | 4 +- .../paths/Sites/get-v2-sites-polygon-bbox.yml | 6 +- .../Sites/get-v2-sites-polygons-data.yml | 6 +- .../get-v2-geojson-complete-download.yml | 9 +- .../paths/Terrafund/get-v2-polygon-bbox.yml | 6 +- ...-v2-terrafund-validation-criteria-data.yml | 8 +- ...-v2-terrafund-validation-criteria-site.yml | 8 +- .../get-v2-terrafund-validation-polygon.yml | 8 +- ...t-v2-terrafund-validation-sitepolygons.yml | 16 +- .../Terrafund/post-v2-site-polygon-data.yml | 6 +- resources/docs/swagger-v2.yml | 395 +++++++++--------- 11 files changed, 213 insertions(+), 259 deletions(-) diff --git a/openapi-src/V2/definitions/SitePolygonsBboxResponse.yml b/openapi-src/V2/definitions/SitePolygonsBboxResponse.yml index 246a10085..0a454bac5 100644 --- a/openapi-src/V2/definitions/SitePolygonsBboxResponse.yml +++ b/openapi-src/V2/definitions/SitePolygonsBboxResponse.yml @@ -2,4 +2,6 @@ title: SitePolygonsBboxResponse type: object properties: bbox: - type: array \ No newline at end of file + type: array + items: + type: number \ No newline at end of file diff --git a/openapi-src/V2/paths/Sites/get-v2-sites-polygon-bbox.yml b/openapi-src/V2/paths/Sites/get-v2-sites-polygon-bbox.yml index 88470087e..f54bad8fb 100644 --- a/openapi-src/V2/paths/Sites/get-v2-sites-polygon-bbox.yml +++ b/openapi-src/V2/paths/Sites/get-v2-sites-polygon-bbox.yml @@ -8,10 +8,8 @@ parameters: responses: '200': description: Successful response - content: - application/json: - schema: - $ref: '../../definitions/_index.yml#/SitePolygonsBboxResponse' + schema: + $ref: '../../definitions/_index.yml#/SitePolygonsBboxResponse' '400': description: Bad request '500': diff --git a/openapi-src/V2/paths/Sites/get-v2-sites-polygons-data.yml b/openapi-src/V2/paths/Sites/get-v2-sites-polygons-data.yml index 9529905b4..485073593 100644 --- a/openapi-src/V2/paths/Sites/get-v2-sites-polygons-data.yml +++ b/openapi-src/V2/paths/Sites/get-v2-sites-polygons-data.yml @@ -8,10 +8,8 @@ parameters: responses: '200': description: Successful response - content: - application/json: - schema: - $ref: '../../definitions/_index.yml#/SitePolygonsDataResponse' + schema: + $ref: '../../definitions/_index.yml#/SitePolygonsDataResponse' '400': description: Bad request '500': diff --git a/openapi-src/V2/paths/Terrafund/get-v2-geojson-complete-download.yml b/openapi-src/V2/paths/Terrafund/get-v2-geojson-complete-download.yml index c5f6cdced..5073d4122 100644 --- a/openapi-src/V2/paths/Terrafund/get-v2-geojson-complete-download.yml +++ b/openapi-src/V2/paths/Terrafund/get-v2-geojson-complete-download.yml @@ -1,6 +1,5 @@ summary: Get Polygon as GeoJSON -description: | - Retrieve polygon geometry and properties as GeoJSON. +description: Retrieve polygon geometry and properties as GeoJSON. parameters: - in: query name: uuid @@ -10,10 +9,8 @@ parameters: responses: '200': description: Successful response - content: - application/json: - schema: - $ref: '../../definitions/_index.yml#/GeoJSONResponse' + schema: + $ref: '../../definitions/_index.yml#/GeoJSONResponse' '400': description: Bad request '500': diff --git a/openapi-src/V2/paths/Terrafund/get-v2-polygon-bbox.yml b/openapi-src/V2/paths/Terrafund/get-v2-polygon-bbox.yml index 3e63b06b0..19d0dee0c 100644 --- a/openapi-src/V2/paths/Terrafund/get-v2-polygon-bbox.yml +++ b/openapi-src/V2/paths/Terrafund/get-v2-polygon-bbox.yml @@ -8,10 +8,8 @@ parameters: responses: '200': description: Successful response - content: - application/json: - schema: - $ref: '../../definitions/_index.yml#/SitePolygonsBboxResponse' + schema: + $ref: '../../definitions/_index.yml#/SitePolygonsBboxResponse' '400': description: Bad request '500': diff --git a/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-criteria-data.yml b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-criteria-data.yml index 5c9f537ef..6ecd1611e 100644 --- a/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-criteria-data.yml +++ b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-criteria-data.yml @@ -5,12 +5,8 @@ parameters: required: true description: The UUID of the polygon type: string - schema: - type: string responses: '200': description: Successful response - content: - application/json: - schema: - $ref: '../../definitions/_index.yml#/V2TerrafundCriteriaData' \ No newline at end of file + schema: + $ref: '../../definitions/_index.yml#/V2TerrafundCriteriaData' \ No newline at end of file diff --git a/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-criteria-site.yml b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-criteria-site.yml index 03d5c4644..acbb3b816 100644 --- a/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-criteria-site.yml +++ b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-criteria-site.yml @@ -5,12 +5,8 @@ parameters: required: true description: The UUID of the polygon type: string - schema: - type: string responses: '200': description: Successful response - content: - application/json: - schema: - $ref: '../../definitions/_index.yml#/V2TerrafundCriteriaSite' \ No newline at end of file + schema: + $ref: '../../definitions/_index.yml#/V2TerrafundCriteriaSite' \ No newline at end of file diff --git a/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-polygon.yml b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-polygon.yml index e7e7a433e..1f565764b 100644 --- a/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-polygon.yml +++ b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-polygon.yml @@ -5,12 +5,8 @@ parameters: required: true description: The UUID of the polygon type: string - schema: - type: string responses: '200': description: Successful response - content: - application/json: - schema: - $ref: '../../definitions/_index.yml#/V2TerrafundCriteriaData' \ No newline at end of file + schema: + $ref: '../../definitions/_index.yml#/V2TerrafundCriteriaData' \ No newline at end of file diff --git a/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-sitepolygons.yml b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-sitepolygons.yml index 79d89df49..6596857f6 100644 --- a/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-sitepolygons.yml +++ b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-validation-sitepolygons.yml @@ -5,16 +5,12 @@ parameters: required: true description: The UUID of the polygon type: string - schema: - type: string responses: "200": description: Successful response - content: - application/json: - schema: - type: object - properties: - message: - type: string - description: A message indicating the completion of validation for all site polygons. \ No newline at end of file + schema: + type: object + properties: + message: + type: string + description: A message indicating the completion of validation for all site polygons. \ No newline at end of file diff --git a/openapi-src/V2/paths/Terrafund/post-v2-site-polygon-data.yml b/openapi-src/V2/paths/Terrafund/post-v2-site-polygon-data.yml index 7291fb087..d472868e6 100644 --- a/openapi-src/V2/paths/Terrafund/post-v2-site-polygon-data.yml +++ b/openapi-src/V2/paths/Terrafund/post-v2-site-polygon-data.yml @@ -18,10 +18,8 @@ parameters: responses: '201': description: Successful response - content: - application/json: - schema: - $ref: '../../definitions/_index.yml#/SitePolygonCreateResponse' + schema: + $ref: '../../definitions/_index.yml#/SitePolygonCreateResponse' '400': description: Bad request '500': diff --git a/resources/docs/swagger-v2.yml b/resources/docs/swagger-v2.yml index 91e1a5301..20eebcf24 100644 --- a/resources/docs/swagger-v2.yml +++ b/resources/docs/swagger-v2.yml @@ -44215,6 +44215,8 @@ definitions: properties: bbox: type: array + items: + type: number SitePolygonResponse: type: object properties: @@ -93954,35 +93956,31 @@ paths: required: true description: The UUID of the polygon type: string - schema: - type: string responses: '200': description: Successful response - content: - application/json: - schema: - type: object - properties: - polygon_id: - type: string - description: The ID of the polygon - criteria_list: - type: array - description: List of validation criteria - items: - type: object - properties: - criteria_id: - type: integer - description: The ID of the criteria - latest_created_at: - type: string - format: date-time - description: The latest created at timestamp of the criteria - valid: - type: integer - description: 'Indicates if the criteria is valid or not (1 for valid, 0 for invalid)' + schema: + type: object + properties: + polygon_id: + type: string + description: The ID of the polygon + criteria_list: + type: array + description: List of validation criteria + items: + type: object + properties: + criteria_id: + type: integer + description: The ID of the criteria + latest_created_at: + type: string + format: date-time + description: The latest created at timestamp of the criteria + valid: + type: integer + description: 'Indicates if the criteria is valid or not (1 for valid, 0 for invalid)' /v2/terrafund/validation/criteria-data: get: summary: Get criteria data validation results for a polygon @@ -93992,35 +93990,31 @@ paths: required: true description: The UUID of the polygon type: string - schema: - type: string responses: '200': description: Successful response - content: - application/json: - schema: - type: object - properties: - polygon_id: - type: string - description: The ID of the polygon - criteria_list: - type: array - description: List of validation criteria - items: - type: object - properties: - criteria_id: - type: integer - description: The ID of the criteria - latest_created_at: - type: string - format: date-time - description: The latest created at timestamp of the criteria - valid: - type: integer - description: 'Indicates if the criteria is valid or not (1 for valid, 0 for invalid)' + schema: + type: object + properties: + polygon_id: + type: string + description: The ID of the polygon + criteria_list: + type: array + description: List of validation criteria + items: + type: object + properties: + criteria_id: + type: integer + description: The ID of the criteria + latest_created_at: + type: string + format: date-time + description: The latest created at timestamp of the criteria + valid: + type: integer + description: 'Indicates if the criteria is valid or not (1 for valid, 0 for invalid)' /v2/terrafund/validation/sitePolygons: get: summary: Run validation for all polygons in a site @@ -94030,19 +94024,15 @@ paths: required: true description: The UUID of the polygon type: string - schema: - type: string responses: '200': description: Successful response - content: - application/json: - schema: - type: object - properties: - message: - type: string - description: A message indicating the completion of validation for all site polygons. + schema: + type: object + properties: + message: + type: string + description: A message indicating the completion of validation for all site polygons. /v2/terrafund/validation/site: get: summary: Get criteria data validation results for all polygons in a site @@ -94052,27 +94042,23 @@ paths: required: true description: The UUID of the polygon type: string - schema: - type: string responses: '200': description: Successful response - content: - application/json: - schema: - type: array - items: - type: object - properties: - uuid: - type: string - description: The UUID of the polygon. - valid: - type: boolean - description: Indicates if the polygon is valid or not. - checked: - type: boolean - description: Indicates if the polygon has been checked before or not. + schema: + type: array + items: + type: object + properties: + uuid: + type: string + description: The UUID of the polygon. + valid: + type: boolean + description: Indicates if the polygon is valid or not. + checked: + type: boolean + description: Indicates if the polygon has been checked before or not. /v2/geometry/validate: post: summary: Test a set of geometries for validity @@ -94406,67 +94392,65 @@ paths: responses: '200': description: Successful response - content: - application/json: - schema: - title: SitePolygonsDataResponse - type: array - items: - title: SitePolygon - type: object - properties: - id: - type: integer - uuid: - type: string - project_id: - type: string - proj_name: - type: string - org_name: - type: string - poly_id: - type: string - poly_name: - type: string - site_id: - type: string - site_name: - type: string - plantstart: - type: string - format: date - plantend: - type: string - format: date - practice: - type: string - target_sys: - type: string - distr: - type: string - num_trees: - type: integer - calc_area: - type: number - format: float - created_by: - type: string - last_modified_by: - type: string - deleted_at: - type: string - format: date-time - created_at: - type: string - format: date-time - updated_at: - type: string - format: date-time - status: - type: string - country: - type: string + schema: + title: SitePolygonsDataResponse + type: array + items: + title: SitePolygon + type: object + properties: + id: + type: integer + uuid: + type: string + project_id: + type: string + proj_name: + type: string + org_name: + type: string + poly_id: + type: string + poly_name: + type: string + site_id: + type: string + site_name: + type: string + plantstart: + type: string + format: date + plantend: + type: string + format: date + practice: + type: string + target_sys: + type: string + distr: + type: string + num_trees: + type: integer + calc_area: + type: number + format: float + created_by: + type: string + last_modified_by: + type: string + deleted_at: + type: string + format: date-time + created_at: + type: string + format: date-time + updated_at: + type: string + format: date-time + status: + type: string + country: + type: string '400': description: Bad request '500': @@ -94483,14 +94467,14 @@ paths: responses: '200': description: Successful response - content: - application/json: - schema: - title: SitePolygonsBboxResponse - type: object - properties: - bbox: - type: array + schema: + title: SitePolygonsBboxResponse + type: object + properties: + bbox: + type: array + items: + type: number '400': description: Bad request '500': @@ -94543,21 +94527,19 @@ paths: responses: '201': description: Successful response - content: - application/json: - schema: - type: object - properties: - message: - type: string - example: Site polygon created successfully - uuid: - type: string - description: UUID of the created site polygon - area: - type: number - format: double - description: Calculated area in hectares + schema: + type: object + properties: + message: + type: string + example: Site polygon created successfully + uuid: + type: string + description: UUID of the created site polygon + area: + type: number + format: double + description: Calculated area in hectares '400': description: Bad request '500': @@ -94574,14 +94556,14 @@ paths: responses: '200': description: Successful response - content: - application/json: - schema: - title: SitePolygonsBboxResponse - type: object - properties: - bbox: - type: array + schema: + title: SitePolygonsBboxResponse + type: object + properties: + bbox: + type: array + items: + type: number '400': description: Bad request '500': @@ -94589,8 +94571,7 @@ paths: /v2/terrafund/geojson/complete: get: summary: Get Polygon as GeoJSON - description: | - Retrieve polygon geometry and properties as GeoJSON. + description: Retrieve polygon geometry and properties as GeoJSON. parameters: - in: query name: uuid @@ -94600,44 +94581,42 @@ paths: responses: '200': description: Successful response - content: - application/json: - schema: - type: object - properties: - type: - type: string - features: - type: array - items: + schema: + type: object + properties: + type: + type: string + features: + type: array + items: + type: object + properties: + type: + type: string + geometry: type: object properties: type: type: string - geometry: - type: object - properties: - type: - type: string - coordinates: - type: array - properties: - type: object - properties: - poly_name: - type: string - plantstart: - type: string - plantend: - type: string - practice: - type: string - target_sys: - type: string - distr: - type: string - num_trees: - type: integer + coordinates: + type: array + properties: + type: object + properties: + poly_name: + type: string + plantstart: + type: string + plantend: + type: string + practice: + type: string + target_sys: + type: string + distr: + type: string + num_trees: + type: integer '400': description: Bad request '500':