diff --git a/app/Helpers/GeometryHelper.php b/app/Helpers/GeometryHelper.php index 55c25234c..96c918bcc 100644 --- a/app/Helpers/GeometryHelper.php +++ b/app/Helpers/GeometryHelper.php @@ -91,6 +91,9 @@ public function updateProjectCentroid(string $projectUuid) public static function getPolygonsBbox($polygonsIds) { + if (count($polygonsIds) === 0) { + return null; + } $envelopes = PolygonGeometry::whereIn('uuid', $polygonsIds) ->selectRaw('ST_ASGEOJSON(ST_Envelope(geom)) as envelope') ->get(); diff --git a/app/Helpers/TerrafundDashboardQueryHelper.php b/app/Helpers/TerrafundDashboardQueryHelper.php index f6a4b8745..008641be8 100644 --- a/app/Helpers/TerrafundDashboardQueryHelper.php +++ b/app/Helpers/TerrafundDashboardQueryHelper.php @@ -4,6 +4,7 @@ use App\Models\V2\Projects\Project; use App\Models\V2\Sites\SitePolygon; +use Illuminate\Support\Facades\Log; class TerrafundDashboardQueryHelper { @@ -24,37 +25,83 @@ public static function buildQueryFromRequest($request) return $query; } - public static function getPolygonIdsOfProject($request) + public static function retrievePolygonUuidsForProject($projectUuId) { - $projectIds = TerrafundDashboardQueryHelper::buildQueryFromRequest($request) - ->pluck('uuid'); - $polygonsIds = SitePolygon::whereHas('site.project', function ($query) use ($projectIds) { - $query->whereIn('uuid', $projectIds); - })->pluck('poly_id'); + $project = Project::where('uuid', $projectUuId)->first(); + $sitePolygons = $project->sitePolygons; + + $polygonsIds = $sitePolygons->pluck('poly_id'); return $polygonsIds; } - public static function getPolygonsByStatusOfProject($request) + public static function getPolygonIdsOfProject($request) { - $projectIds = TerrafundDashboardQueryHelper::buildQueryFromRequest($request) - ->pluck('uuid'); + $projectUuId = TerrafundDashboardQueryHelper::buildQueryFromRequest($request) + ->pluck('uuid')->first(); + + return self::retrievePolygonUuidsForProject($projectUuId); + } + + public static function getPolygonUuidsOfProject($request) + { + $projectUuId = $request->input('uuid'); + + return self::retrievePolygonUuidsForProject($projectUuId); + } + + public static function getPolygonsByStatus() + { + try { + $statuses = ['needs-more-information', 'submitted', 'approved']; + $polygons = []; + foreach ($statuses as $status) { + $polygonsOfProject = SitePolygon::where('status', $status) + ->whereNotNull('site_id') + ->where('site_id', '!=', 'NULL') + ->pluck('poly_id'); + + $polygons[$status] = $polygonsOfProject; + } - $statuses = ['Needs More Info', 'Submitted', 'Approved']; + return $polygons; + } catch (\Exception $e) { + Log::error('Error fetching polygons by status of project: ' . $e->getMessage()); + return []; + } + } + + public static function retrievePolygonUuidsByStatusForProject($projectUuid) + { + $project = Project::where('uuid', $projectUuid)->first(); + $sitePolygons = $project->sitePolygons; + $statuses = ['needs-more-information', 'submitted', 'approved']; $polygons = []; foreach ($statuses as $status) { - // Get polygons of the project filtered by status - $polygonsOfProject = SitePolygon::whereHas('site.project', function ($query) use ($projectIds) { - $query->whereIn('uuid', $projectIds); - }) - ->where('status', $status) - ->pluck('poly_id'); + $polygonsOfProject = $sitePolygons + ->where('status', $status) + ->pluck('poly_id'); $polygons[$status] = $polygonsOfProject; } return $polygons; } + + public static function getPolygonsByStatusOfProject($request) + { + $projectUuid = TerrafundDashboardQueryHelper::buildQueryFromRequest($request) + ->pluck('uuid')->first(); + + return self::retrievePolygonUuidsByStatusForProject($projectUuid); + } + + public static function getPolygonsUuidsByStatusForProject($request) + { + $projectUuid = $request->input('uuid'); + + return self::retrievePolygonUuidsByStatusForProject($projectUuid); + } } diff --git a/app/Http/Controllers/V2/Dashboard/GetPolygonsController.php b/app/Http/Controllers/V2/Dashboard/GetPolygonsController.php index cf210820b..7c2e9db37 100644 --- a/app/Http/Controllers/V2/Dashboard/GetPolygonsController.php +++ b/app/Http/Controllers/V2/Dashboard/GetPolygonsController.php @@ -31,6 +31,15 @@ public function getPolygonsByStatusOfProject(Request $request): GetPolygonsResou ]); } + public function getPolygonsUuidsByStatusForProject(Request $request): GetPolygonsResource + { + $polygonsIds = TerrafundDashboardQueryHelper::getPolygonsUuidsByStatusForProject($request); + + return new GetPolygonsResource([ + 'data' => $polygonsIds, + ]); + } + public function getBboxOfCompleteProject(Request $request) { try { @@ -44,4 +53,18 @@ public function getBboxOfCompleteProject(Request $request) return response()->json(['error' => 'An error occurred while fetching the bounding box coordinates'], 404); } } + + public function getProjectBbox(Request $request) + { + try { + $polygonsIds = TerrafundDashboardQueryHelper::getPolygonUuidsOfProject($request); + $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'], 404); + } + } }; diff --git a/app/Http/Controllers/V2/Dashboard/ViewProjectController.php b/app/Http/Controllers/V2/Dashboard/ViewProjectController.php new file mode 100644 index 000000000..2e4c6261b --- /dev/null +++ b/app/Http/Controllers/V2/Dashboard/ViewProjectController.php @@ -0,0 +1,137 @@ +role; + if ($role === 'government') { + $isAllowed = Project::where('uuid', $uuid) + ->where('country', $user->country) + ->first(); + $response = (object)[ + 'allowed' => $isAllowed ? true : false, + ]; + } elseif ($role === 'funder') { + $isAllowed = Project::where('uuid', $uuid) + ->where('framework_key', $user->program) + ->first(); + $response = (object)[ + 'allowed' => $isAllowed ? true : false, + ]; + } elseif ($role === 'project_developer') { + $projectId = Project::where('uuid', $uuid) + ->value('id'); + $isInvite = ProjectInvite::where('email_address', $user->email_address) + ->where('project_id', $projectId) + ->first(); + $response = (object)[ + 'allowed' => $isInvite ? true : false, + ]; + } elseif ($role === 'admin' || $role === 'terrafund_admin') { + $response = (object)[ + 'allowed' => true, + ]; + } else { + $response = (object)[ + 'allowed' => false, + ]; + } + + return response()->json($response); + } + + public function getAllProjectsAllowedToUser() + { + try { + $user = Auth::user(); + $role = $user->role; + Log::info($role); + if ($role === 'admin' || $role === 'terrafund_admin' || $role === 'terrafund-admin') { + $response = TerrafundDashboardQueryHelper::getPolygonsByStatus(); + + return response()->json([ + 'polygonsUuids' => $response, + ]); + } else { + if ($role === 'government') { + try { + $projectUuids = Project::where('framework_key', 'terrafund')->where('country', $user->country)->pluck('uuid'); + } catch (\Exception $e) { + $errorMessage = $e->getMessage(); + Log::error('Error fetching projects for government: ' . $errorMessage); + + return response()->json(['error' => 'An error occurred while fetching government projects', 'message' => $errorMessage], 500); + } + } elseif ($role === 'funder') { + try { + $projectUuids = Project::where('framework_key', $user->program)->pluck('uuid'); + } catch (\Exception $e) { + $errorMessage = $e->getMessage(); + Log::error('Error fetching projects for funder: ' . $errorMessage); + + return response()->json(['error' => 'An error occurred while fetching funder projects', 'message' => $errorMessage], 500); + } + } elseif ($role === 'project_developer') { + try { + $projectIds = ProjectInvite::where('email_address', $user->email_address)->pluck('project_id'); + $projectUuids = Project::whereIn('id', $projectIds)->where('framework_key', 'terrafund')->pluck('uuid'); + } catch (\Exception $e) { + $errorMessage = $e->getMessage(); + Log::error('Error fetching projects for project developer: ' . $errorMessage); + + return response()->json(['error' => 'An error occurred while fetching project developer projects', 'message' => $errorMessage], 500); + } + } elseif ($role === 'admin' || $role === 'terrafund_admin' || $role === 'terrafund-admin') { + + } else { + $projectUuids = null; + } + + Log::info('Returning this value: ' . json_encode($projectUuids)); + $polygonsData = [ + 'needs-more-information' => [], + 'submitted' => [], + 'approved' => [], + ]; + + foreach ($projectUuids as $uuid) { + Log::info('Fetching polygons for project UUID ' . $uuid); + $request = new Request(['uuid' => $uuid]); + + try { + $polygonsResource = TerrafundDashboardQueryHelper::getPolygonsByStatusOfProject($request); + foreach ($polygonsResource as $status => $polygons) { + $polygons = $polygons instanceof \Illuminate\Support\Collection ? $polygons->toArray() : $polygons; + $polygonsData[$status] = array_merge($polygonsData[$status], $polygons); + } + } catch (\Exception $e) { + Log::error('Error fetching polygons for project UUID ' . $uuid . ': ' . $e->getMessage()); + } + } + + return response()->json([ + 'projectsUuids' => $projectUuids->toArray(), + 'polygonsUuids' => $polygonsData, + ]); + } + + } catch (\Exception $e) { + $errorMessage = $e->getMessage(); + Log::error('An error occurred: ' . $errorMessage); + + return response()->json(['error' => 'An error occurred while fetching the data', 'message' => $errorMessage], 500); + } + } +}; diff --git a/app/Http/Controllers/V2/Entities/EntityTypeController.php b/app/Http/Controllers/V2/Entities/EntityTypeController.php new file mode 100644 index 000000000..ad4748f2b --- /dev/null +++ b/app/Http/Controllers/V2/Entities/EntityTypeController.php @@ -0,0 +1,119 @@ +input('uuid'); + $type = $request->input('type'); + + if ($type === 'projects') { + return $this->handleProjectEntity($uuid, $request); + } elseif ($type === 'sites') { + return $this->handleSiteEntity($uuid, $request); + } + + return response()->json([ + 'type' => 'unknown', + 'uuid' => $uuid, + ]); + } catch (Exception $e) { + Log::error($e); + + return response()->json([ + 'error' => 'An error occurred while processing your request.', + ], 500); + } + } + + private function handleProjectEntity($uuid, Request $request) + { + try { + $project = Project::where('uuid', $uuid)->firstOrFail(); + $sitePolygons = $this->getSitePolygonsWithFiltersAndSorts($project->sitePolygons(), $request); + $polygonsUuids = $sitePolygons->pluck('poly_id'); + $bboxCoordinates = GeometryHelper::getPolygonsBbox($polygonsUuids); + + return response()->json([ + 'type' => 'project', + 'uuid' => $uuid, + 'polygonsData' => $sitePolygons, + 'bbox' => $bboxCoordinates, + ]); + } catch (ModelNotFoundException $e) { + Log::error($e); + + return response()->json([ + 'error' => 'The requested project was not found.', + ], 404); + } catch (Exception $e) { + Log::error($e); + + return response()->json([ + 'error' => 'An error occurred while retrieving the project.', + ], 500); + } + } + + private function handleSiteEntity($uuid, Request $request) + { + try { + $site = Site::where('uuid', $uuid)->firstOrFail(); + $sitePolygons = $this->getSitePolygonsWithFiltersAndSorts($site->sitePolygons(), $request); + $polygonsUuids = $sitePolygons->pluck('poly_id'); + $bboxCoordinates = GeometryHelper::getPolygonsBbox($polygonsUuids); + + return response()->json([ + 'type' => 'site', + 'uuid' => $uuid, + 'polygonsData' => $sitePolygons, + 'bbox' => $bboxCoordinates, + ]); + } catch (ModelNotFoundException $e) { + Log::error($e); + + return response()->json([ + 'error' => 'The requested site was not found.', + ], 404); + } catch (Exception $e) { + Log::error($e); + + return response()->json([ + 'error' => 'An error occurred while retrieving the site.', + ], 500); + } + } + + private function getSitePolygonsWithFiltersAndSorts($sitePolygonsQuery, Request $request) + { + if ($request->has('status') && $request->input('status')) { + $statusValues = explode(',', $request->input('status')); + $sitePolygonsQuery->whereIn('site_polygon.status', $statusValues); + } + + $sortFields = $request->input('sort', []); + foreach ($sortFields as $field => $direction) { + if ($field === 'status') { + $sitePolygonsQuery->orderByRaw('FIELD(site_polygon.status, "draft", "submitted", "needs-more-information", "approved") ' . $direction); + } elseif ($field === 'poly_name') { + $sitePolygonsQuery->orderByRaw('site_polygon.poly_name IS NULL, site_polygon.poly_name ' . $direction); + } else { + $sitePolygonsQuery->orderBy($field, $direction); + } + } + + return $sitePolygonsQuery->get(); + } +} diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php index fdeea0402..fb11c14ee 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php @@ -5,6 +5,8 @@ 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; @@ -57,22 +59,37 @@ 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; - } - $project = $sitePolygon->project; + 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 ($project) { - $geometryHelper = new GeometryHelper(); - $centroid = $geometryHelper->centroidOfProject($project->uuid); + if ($centroid === null) { + Log::warning("Invalid centroid for project UUID: $project->uuid"); + } + $centroidData = json_decode($centroid, true); - if ($centroid === null) { - Log::warning("Invalid centroid for project UUID: $project->uuid"); + if (isset($centroidData['coordinates']) && is_array($centroidData['coordinates'])) { + $longitude = $centroidData['coordinates'][0]; + $latitude = $centroidData['coordinates'][1]; + $project->lat = $latitude; + $project->long = $longitude; + $project->save(); + + Log::info("Updated project centroid for project UUID: $project->uuid with lat: $latitude, lng: $longitude"); + } else { + Log::warning("Centroid data for project UUID: $project->uuid is malformed."); + } + Log::info("Updated project centroid for project UUID: $project->uuid with lat: {$centroid['lat']}, lng: {$centroid['lng']}"); + } else { + Log::warning("Project with UUID $relatedSite->project_id not found."); } } else { - Log::warning('Project UUID not found.'); + Log::warning("Site polygon with UUID $polygonGeometry->uuid not found."); } } catch (\Exception $e) { Log::error('Error updating project centroid: ' . $e->getMessage()); diff --git a/app/Models/V2/Sites/SitePolygon.php b/app/Models/V2/Sites/SitePolygon.php index b434c3281..d9bf5e11a 100644 --- a/app/Models/V2/Sites/SitePolygon.php +++ b/app/Models/V2/Sites/SitePolygon.php @@ -63,9 +63,9 @@ public function project(): BelongsToThrough ); } - public function site() + public function site(): BelongsTo { - return $this->belongsTo(Site::class, 'site_id', 'id'); + return $this->belongsTo(Site::class, 'site_id', 'uuid'); } public function createdBy(): HasOne diff --git a/openapi-src/V2/definitions/EntityTypeResponse.yml b/openapi-src/V2/definitions/EntityTypeResponse.yml new file mode 100644 index 000000000..47e85a28b --- /dev/null +++ b/openapi-src/V2/definitions/EntityTypeResponse.yml @@ -0,0 +1,18 @@ +type: object +properties: + type: + type: string + description: Type of the entity ('project', 'site', 'unknown') + uuid: + type: string + format: uuid + description: UUID of the entity + polygonsData: + type: array + items: + $ref: './_index.yml#/SitePolygon' + bbox: + type: array + items: + type: number + description: Bounding box of the entity \ No newline at end of file diff --git a/openapi-src/V2/definitions/GeojsonData.yml b/openapi-src/V2/definitions/GeojsonData.yml new file mode 100644 index 000000000..9570f3ae3 --- /dev/null +++ b/openapi-src/V2/definitions/GeojsonData.yml @@ -0,0 +1,5 @@ +type: object +properties: + geojson: + type: object + description: The GeoJSON representation of the polygon geometry. \ No newline at end of file diff --git a/openapi-src/V2/definitions/GeometryString.yml b/openapi-src/V2/definitions/GeometryString.yml new file mode 100644 index 000000000..b2e78a2d1 --- /dev/null +++ b/openapi-src/V2/definitions/GeometryString.yml @@ -0,0 +1,4 @@ +type: object +properties: + geometry: + type: string \ No newline at end of file diff --git a/openapi-src/V2/definitions/ProjectPipelinePost.yml b/openapi-src/V2/definitions/ProjectPipelinePost.yml new file mode 100644 index 000000000..a0a029652 --- /dev/null +++ b/openapi-src/V2/definitions/ProjectPipelinePost.yml @@ -0,0 +1,23 @@ +type: object +properties: + date: + type: string + format: date + id: + type: integer + SubmittedBy: + type: string + Program: + type: string + Cohort: + type: string + PublishFor: + type: string + URL: + type: string + CreatedDate: + type: string + format: date + ModifiedDate: + type: string + format: date \ No newline at end of file diff --git a/openapi-src/V2/definitions/_index.yml b/openapi-src/V2/definitions/_index.yml index 8bb6ff277..619262284 100644 --- a/openapi-src/V2/definitions/_index.yml +++ b/openapi-src/V2/definitions/_index.yml @@ -282,6 +282,8 @@ V2TerrafundCriteriaSite: $ref: './V2TerrafundCriteriaSite.yml' SitePolygon: $ref: './SitePolygon.yml' +GeometryString: + $ref: './GeometryString.yml' SitePolygonsDataResponse: $ref: './SitePolygonsDataResponse.yml' SitePolygonsBboxResponse: @@ -313,4 +315,8 @@ DashboardBBOXProject: DashboardBBOXCountry: $ref: './DashboardBBOXCountry.yml' DashboardPolygonData: - $ref: './DashboardPolygonData.yml' \ No newline at end of file + $ref: './DashboardPolygonData.yml' +GeojsonData: + $ref: './GeojsonData.yml' +EntityTypeResponse: + $ref: './EntityTypeResponse.yml' \ No newline at end of file diff --git a/openapi-src/V2/paths/Entity/get-v2-type-entity.yml b/openapi-src/V2/paths/Entity/get-v2-type-entity.yml new file mode 100644 index 000000000..9ddaee2ff --- /dev/null +++ b/openapi-src/V2/paths/Entity/get-v2-type-entity.yml @@ -0,0 +1,39 @@ +summary: Get Entity Type +description: | + Determine the type of entity based on UUID. +parameters: + - in: query + name: uuid + required: true + description: UUID of the entity + type: string + - in: query + name: type + required: true + description: type of the entity + type: string + - in: query + name: status + required: false + description: Comma-separated list of status values to filter by + type: string + - in: query + name: sort + required: false + description: Sort criteria in the format `sort[field]=direction`, e.g. `sort[poly_name]=asc or sort[status]=desc` + type: string +responses: + '200': + description: Successful response + schema: + $ref: '../../definitions/_index.yml#/EntityTypeResponse' + '400': + description: Bad request, UUID parameter is missing + '500': + description: Internal server error + schema: + type: object + properties: + error: + type: string + description: Error message \ No newline at end of file diff --git a/openapi-src/V2/paths/Terrafund/delete-v2-terrafund-polygon-uuid.yml b/openapi-src/V2/paths/Terrafund/delete-v2-terrafund-polygon-uuid.yml new file mode 100644 index 000000000..982445259 --- /dev/null +++ b/openapi-src/V2/paths/Terrafund/delete-v2-terrafund-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/Terrafund/get-api-v2-terrafund-polygon-uuid.yml b/openapi-src/V2/paths/Terrafund/get-api-v2-terrafund-polygon-uuid.yml new file mode 100644 index 000000000..6e8169201 --- /dev/null +++ b/openapi-src/V2/paths/Terrafund/get-api-v2-terrafund-polygon-uuid.yml @@ -0,0 +1,87 @@ + +summary: Get Site Polygon Data +description: Retrieve site polygon data for the given UUID. +parameters: + - in: path + name: uuid + type: string + required: true + description: The UUID of the site polygon. +responses: + '200': + description: Successful response + schema: + type: object + properties: + site_polygon: + type: object + properties: + calc_area: + type: number + created_at: + type: string + format: date-time + created_by: + type: string + nullable: true + deleted_at: + type: string + format: date-time + nullable: true + distr: + type: string + nullable: true + id: + type: integer + last_modified_by: + type: string + nullable: true + num_trees: + type: integer + nullable: true + plantend: + type: string + format: date + nullable: true + plantstart: + type: string + format: date + point_id: + type: string + nullable: true + poly_id: + type: string + poly_name: + type: string + practice: + type: string + nullable: true + site_id: + type: string + nullable: true + status: + type: string + target_sys: + type: string + nullable: true + updated_at: + type: string + format: date-time + uuid: + type: string + '404': + description: No site polygons found for the given UUID + schema: + type: object + properties: + message: + type: string + example: No site polygons found for the given UUID. + '500': + description: Internal server error + schema: + type: object + properties: + message: + type: string + example: An error message describing the issue. \ No newline at end of file diff --git a/openapi-src/V2/paths/Terrafund/get-v2-terrafund-polygon-geojson-uuid.yml b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-polygon-geojson-uuid.yml new file mode 100644 index 000000000..e2aa24b53 --- /dev/null +++ b/openapi-src/V2/paths/Terrafund/get-v2-terrafund-polygon-geojson-uuid.yml @@ -0,0 +1,22 @@ +summary: Retrieve polygon GeoJSON by UUID +description: | + Retrieves the GeoJSON representation of a polygon geometry based on the provided UUID. +parameters: + - in: path + name: uuid + type: string + required: true + description: The UUID of the polygon geometry to retrieve. +responses: + '200': + description: OK + schema: + $ref: '../../definitions/_index.yml#/GeojsonData' + '404': + description: Not Found + schema: + type: object + properties: + message: + type: string + description: Error message indicating that no polygon geometry was found for the provided UUID. \ No newline at end of file diff --git a/openapi-src/V2/paths/Terrafund/put-v2-terrafund-polygon-uuid.yml b/openapi-src/V2/paths/Terrafund/put-v2-terrafund-polygon-uuid.yml new file mode 100644 index 000000000..93a85b717 --- /dev/null +++ b/openapi-src/V2/paths/Terrafund/put-v2-terrafund-polygon-uuid.yml @@ -0,0 +1,43 @@ +summary: Update geometry for a polygon +parameters: + - in: path + name: uuid + required: true + type: string + description: The UUID of the polygon geometry to update + - in: body + name: geometry + required: true + schema: + $ref: '../../definitions/_index.yml#/GeometryString' + description: The new geometry data +responses: + '200': + description: Geometry updated successfully + schema: + type: object + properties: + message: + type: string + example: Geometry updated successfully. + geometry: + type: object + description: The updated geometry data + uuid: + type: string + '404': + description: No polygon geometry found for the given UUID + schema: + type: object + properties: + message: + type: string + example: No polygon geometry found for the given UUID. + '500': + description: An error occurred + schema: + type: object + properties: + error: + type: string + example: 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 3900cd570..e2d3de649 100644 --- a/openapi-src/V2/paths/_index.yml +++ b/openapi-src/V2/paths/_index.yml @@ -2553,8 +2553,12 @@ get: $ref: './Terrafund/get-v2-geojson-complete-download.yml' /v2/terrafund/polygon/{uuid}: + get: + $ref: './Terrafund/get-api-v2-terrafund-polygon-uuid.yml' + put: + $ref: './Terrafund/put-v2-terrafund-polygon-uuid.yml' delete: - $ref: './Terrafund/delete-v2-polygon-uuid.yml' + $ref: './Terrafund/delete-v2-terrafund-polygon-uuid.yml' /v2/dashboard/jobs-created: get: $ref: './Dashboard/get-v2-dashboard-jobs-created.yml' @@ -2576,6 +2580,9 @@ /v2/dashboard/get-bbox-project: get: $ref: './Dashboard/get-v2-dashboard-get-bbox-project.yml' +/v2/dashboard/bbox/project: + get: + $ref: './Dashboard/get-v2-dashboard-get-bbox-project.yml' /v2/dashboard/country/{country}: get: $ref: './Dashboard/get-v2-dashboard-country.yml' @@ -2584,4 +2591,10 @@ $ref: './Dashboard/get-v2-dashboard-polygon-data-uuid.yml' /v2/dashboard/project-data/{uuid}: get: - $ref: './Dashboard/get-v2-dashboard-project-data-uuid.yml' \ No newline at end of file + $ref: './Dashboard/get-v2-dashboard-project-data-uuid.yml' +/v2/terrafund/polygon/geojson/{uuid}: + get: + $ref: './Terrafund/get-v2-terrafund-polygon-geojson-uuid.yml' +/v2/type-entity: + get: + $ref: './Entity/get-v2-type-entity.yml' \ No newline at end of file diff --git a/resources/docs/swagger-v2.yml b/resources/docs/swagger-v2.yml index aeff0dffc..9aa564506 100644 --- a/resources/docs/swagger-v2.yml +++ b/resources/docs/swagger-v2.yml @@ -44150,6 +44150,11 @@ definitions: type: string country: type: string + GeometryString: + type: object + properties: + geometry: + type: string SitePolygonsDataResponse: title: SitePolygonsDataResponse type: array @@ -44556,6 +44561,85 @@ definitions: key: type: string description: Key of the data field + GeojsonData: + type: object + properties: + geojson: + type: object + description: The GeoJSON representation of the polygon geometry. + EntityTypeResponse: + type: object + properties: + type: + type: string + description: 'Type of the entity (''project'', ''site'', ''unknown'')' + uuid: + type: string + format: uuid + description: UUID of the entity + polygonsData: + 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 + bbox: + type: array + items: + type: number + description: Bounding box of the entity paths: '/v2/tree-species/{entity}/{UUID}': get: @@ -94884,6 +94968,140 @@ paths: '500': description: Internal server error '/v2/terrafund/polygon/{uuid}': + get: + summary: Get Site Polygon Data + description: Retrieve site polygon data for the given UUID. + parameters: + - in: path + name: uuid + type: string + required: true + description: The UUID of the site polygon. + responses: + '200': + description: Successful response + schema: + type: object + properties: + site_polygon: + type: object + properties: + calc_area: + type: number + created_at: + type: string + format: date-time + created_by: + type: string + nullable: true + deleted_at: + type: string + format: date-time + nullable: true + distr: + type: string + nullable: true + id: + type: integer + last_modified_by: + type: string + nullable: true + num_trees: + type: integer + nullable: true + plantend: + type: string + format: date + nullable: true + plantstart: + type: string + format: date + point_id: + type: string + nullable: true + poly_id: + type: string + poly_name: + type: string + practice: + type: string + nullable: true + site_id: + type: string + nullable: true + status: + type: string + target_sys: + type: string + nullable: true + updated_at: + type: string + format: date-time + uuid: + type: string + '404': + description: No site polygons found for the given UUID + schema: + type: object + properties: + message: + type: string + example: No site polygons found for the given UUID. + '500': + description: Internal server error + schema: + type: object + properties: + message: + type: string + example: An error message describing the issue. + put: + summary: Update geometry for a polygon + parameters: + - in: path + name: uuid + required: true + type: string + description: The UUID of the polygon geometry to update + - in: body + name: geometry + required: true + schema: + type: object + properties: + geometry: + type: string + description: The new geometry data + responses: + '200': + description: Geometry updated successfully + schema: + type: object + properties: + message: + type: string + example: Geometry updated successfully. + geometry: + type: object + description: The updated geometry data + uuid: + type: string + '404': + description: No polygon geometry found for the given UUID + schema: + type: object + properties: + message: + type: string + example: No polygon geometry found for the given UUID. + '500': + description: An error occurred + schema: + type: object + properties: + error: + type: string + example: Internal Server Error delete: summary: Delete polygon records parameters: @@ -95192,6 +95410,29 @@ paths: type: number '404': description: Project not found + /v2/dashboard/bbox/project: + get: + summary: Get Bbox of all polygons of project + tags: + - Projects + parameters: + - in: query + name: uuid + type: string + description: UUID of the project + required: true + responses: + '200': + description: Successful response + schema: + type: object + properties: + bbox: + type: array + items: + type: number + '404': + description: Project not found '/v2/dashboard/country/{country}': get: summary: Get the bounding box of a country @@ -95281,3 +95522,143 @@ paths: description: Key of the data field '500': description: Error in queries + '/v2/terrafund/polygon/geojson/{uuid}': + get: + summary: Retrieve polygon GeoJSON by UUID + description: | + Retrieves the GeoJSON representation of a polygon geometry based on the provided UUID. + parameters: + - in: path + name: uuid + type: string + required: true + description: The UUID of the polygon geometry to retrieve. + responses: + '200': + description: OK + schema: + type: object + properties: + geojson: + type: object + description: The GeoJSON representation of the polygon geometry. + '404': + description: Not Found + schema: + type: object + properties: + message: + type: string + description: Error message indicating that no polygon geometry was found for the provided UUID. + /v2/type-entity: + get: + summary: Get Entity Type + description: | + Determine the type of entity based on UUID. + parameters: + - in: query + name: uuid + required: true + description: UUID of the entity + type: string + - in: query + name: type + required: true + description: type of the entity + type: string + - in: query + name: status + required: false + description: Comma-separated list of status values to filter by + type: string + - in: query + name: sort + required: false + description: 'Sort criteria in the format `sort[field]=direction`, e.g. `sort[poly_name]=asc or sort[status]=desc`' + type: string + responses: + '200': + description: Successful response + schema: + type: object + properties: + type: + type: string + description: 'Type of the entity (''project'', ''site'', ''unknown'')' + uuid: + type: string + format: uuid + description: UUID of the entity + polygonsData: + 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 + bbox: + type: array + items: + type: number + description: Bounding box of the entity + '400': + description: 'Bad request, UUID parameter is missing' + '500': + description: Internal server error + schema: + type: object + properties: + error: + type: string + description: Error message diff --git a/routes/api_v2.php b/routes/api_v2.php index 0be75ac9e..c4caa12ff 100644 --- a/routes/api_v2.php +++ b/routes/api_v2.php @@ -27,6 +27,7 @@ use App\Http\Controllers\V2\Disturbances\UpdateDisturbanceController; use App\Http\Controllers\V2\Entities\AdminSoftDeleteEntityController; use App\Http\Controllers\V2\Entities\AdminStatusEntityController; +use App\Http\Controllers\V2\Entities\EntityTypeController; use App\Http\Controllers\V2\Entities\SubmitEntityWithFormController; use App\Http\Controllers\V2\Entities\UpdateEntityWithFormController; use App\Http\Controllers\V2\Entities\ViewEntityController; @@ -677,7 +678,10 @@ function () { Route::get('/get-polygons', [GetPolygonsController::class, 'getPolygonsOfProject']); Route::get('/get-polygons/statuses', [GetPolygonsController::class, 'getPolygonsByStatusOfProject']); Route::get('/get-bbox-project', [GetPolygonsController::class, 'getBboxOfCompleteProject']); + Route::get('/bbox/project', [GetPolygonsController::class, 'getProjectBbox']); Route::get('/country/{country}', [CountryDataController::class, 'getCountryBbox']); Route::get('/polygon-data/{uuid}', [CountryDataController::class, 'getPolygonData']); Route::get('/project-data/{uuid}', [CountryDataController::class, 'getProjectData']); }); + +Route::get('/type-entity', EntityTypeController::class);