Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TM-] criteria data by multiple uuids #637

Merged
merged 6 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ public function clipOverlappingPolygonsBySite(string $uuid)
ini_set('memory_limit', '-1');
$user = Auth::user();
$site = Site::isUuid($uuid)->first();
$polygonUuids = GeometryHelper::getSitePolygonsUuids($uuid)->toArray();
$delayedJob = DelayedJobProgress::create([
'processed_content' => 0,
'created_by' => $user->id,
'metadata' => [
'entity_id' => $site->id,
'entity_type' => get_class($site),
'entity_name' => $site->name,
],
'is_acknowledged' => false,
'name' => 'Polygon Fix',
]);
'processed_content' => 0,
'created_by' => $user->id,
'metadata' => [
'entity_id' => $site->id,
'entity_type' => get_class($site),
'entity_name' => $site->name,
],
'is_acknowledged' => false,
'name' => 'Polygon Fix',
]);
$polygonUuids = GeometryHelper::getSitePolygonsUuids($uuid)->toArray();
$job = new FixPolygonOverlapJob($delayedJob->id, $polygonUuids, $user->id);
dispatch($job);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,42 @@ public function getCriteriaData(Request $request)
return response()->json(['polygon_id' => $uuid, 'criteria_list' => $criteriaList]);
}

public function getCriteriaDataForMultiple(Request $request)
{
$uuids = $request->input('uuids');

if (empty($uuids) || ! is_array($uuids)) {
return response()->json(['error' => 'Invalid or missing UUIDs array'], 400);
}

$response = [];

foreach ($uuids as $uuid) {
$geometry = PolygonGeometry::isUuid($uuid)->first();

if ($geometry === null) {
$response[$uuid] = ['error' => 'Polygon not found for the given UUID'];

continue;
}

$criteriaList = GeometryHelper::getCriteriaDataForPolygonGeometry($geometry);

if (empty($criteriaList)) {
$response[$uuid] = ['error' => 'Criteria data not found for the given polygon ID'];

continue;
}

$response[$uuid] = [
'polygon_id' => $uuid,
'criteria_list' => $criteriaList,
];
}

return response()->json($response);
}

public function getCriteriaDataForMultiplePolygons(array $uuids)
{
$result = [];
Expand Down
37 changes: 37 additions & 0 deletions openapi-src/V2/definitions/V2TerrafundCriteriaDataMultiple.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
type: object
additionalProperties:
oneOf:
- 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)
extra_info:
type: object
description: Extra information about the polygon validation
required:
- polygon_id
- criteria_list
- type: object
properties:
error:
type: string
description: Error message if the polygon or criteria data is not found
required:
- error
6 changes: 4 additions & 2 deletions openapi-src/V2/definitions/_index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ EntityFormCreate:
EntityFormUpdate:
$ref: './EntityFormUpdate.yml'
EntityFormRead:
$ref: './EntityFormRead.yml'
$ref: './EntityFormRead.yml'
UserRead:
$ref: './UserRead.yml'
UserReadAll:
Expand Down Expand Up @@ -276,6 +276,8 @@ AuditStatusResponse:
$ref: './AuditStatusResponse.yml'
V2TerrafundCriteriaData:
$ref: './V2TerrafundCriteriaData.yml'
V2TerrafundCriteriaDataMultiple:
$ref: './V2TerrafundCriteriaDataMultiple.yml'
V2TerrafundCriteriaSite:
$ref: './V2TerrafundCriteriaSite.yml'
DashboardProjectAvailableResponse:
Expand Down Expand Up @@ -312,7 +314,7 @@ DashboardTreesUnderRestorationActual:
$ref: './DashboardTreesUnderRestorationActual.yml'
DashboardGetProjectsResponse:
$ref: './DashboardGetProjectsResponse.yml'
DashboardGetProjectsData:
DashboardGetProjectsData:
$ref: './DashboardGetProjectsData.yml'
DashboardGetPolygonStatusResponse:
$ref: './DashboardGetPolygonStatusResponse.yml'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ responses:
'200':
description: Successful response
schema:
$ref: '../../definitions/_index.yml#/V2TerrafundCriteriaData'
$ref: '../../definitions/_index.yml#/V2TerrafundCriteriaData'
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
summary: Get criteria data validation results for multiple polygons
parameters:
- in: body
name: body
required: true
description: A JSON object containing the list of UUIDs of the polygons
schema:
type: object
properties:
uuids:
type: array
description: A list of UUIDs of the polygons
items:
type: string
responses:
'200':
description: Successful response
schema:
$ref: '../../definitions/_index.yml#/V2TerrafundCriteriaDataMultiple'
'400':
description: Invalid or missing UUIDs array
schema:
type: object
properties:
error:
type: string
example: 'Invalid or missing UUIDs array'
'404':
description: No criteria data found for the given UUIDs
schema:
type: object
properties:
error:
type: string
example: 'Criteria data not found for the given polygon IDs'
4 changes: 3 additions & 1 deletion openapi-src/V2/paths/_index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2161,7 +2161,7 @@
schema:
$ref: '../definitions/_index.yml#/FormSubmissionUpdate'
delete:
summary: "Deletes a specific form submission"
summary: 'Deletes a specific form submission'
operationId: delete-v2-form-submission-UUID
tags:
- Forms
Expand Down Expand Up @@ -2585,6 +2585,8 @@
'/v2/terrafund/validation/criteria-data':
get:
$ref: './Terrafund/get-v2-terrafund-validation-criteria-data.yml'
post:
$ref: './Terrafund/post-v2-terrafund-validation-criteria-data.yml'
'/v2/terrafund/validation/sitePolygons':
post:
$ref: './Terrafund/get-v2-terrafund-validation-sitepolygons.yml'
Expand Down
110 changes: 110 additions & 0 deletions resources/docs/swagger-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42801,6 +42801,44 @@ definitions:
extra_info:
type: object
description: Extra information about the polygon validation
V2TerrafundCriteriaDataMultiple:
type: object
additionalProperties:
oneOf:
- 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)'
extra_info:
type: object
description: Extra information about the polygon validation
required:
- polygon_id
- criteria_list
- type: object
properties:
error:
type: string
description: Error message if the polygon or criteria data is not found
required:
- error
V2TerrafundCriteriaSite:
type: array
items:
Expand Down Expand Up @@ -95422,6 +95460,78 @@ paths:
extra_info:
type: object
description: Extra information about the polygon validation
post:
summary: Get criteria data validation results for multiple polygons
parameters:
- in: body
name: body
required: true
description: A JSON object containing the list of UUIDs of the polygons
schema:
type: object
properties:
uuids:
type: array
description: A list of UUIDs of the polygons
items:
type: string
responses:
'200':
description: Successful response
schema:
type: object
additionalProperties:
oneOf:
- 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)'
extra_info:
type: object
description: Extra information about the polygon validation
required:
- polygon_id
- criteria_list
- type: object
properties:
error:
type: string
description: Error message if the polygon or criteria data is not found
required:
- error
'400':
description: Invalid or missing UUIDs array
schema:
type: object
properties:
error:
type: string
example: Invalid or missing UUIDs array
'404':
description: No criteria data found for the given UUIDs
schema:
type: object
properties:
error:
type: string
example: Criteria data not found for the given polygon IDs
/v2/terrafund/validation/sitePolygons:
post:
summary: Run validation for all polygons in a site
Expand Down
1 change: 1 addition & 0 deletions routes/api_v2.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@
Route::get('/validation/geometry-type', [TerrafundCreateGeometryController::class, 'getGeometryType']);
Route::get('/country-names', [TerrafundCreateGeometryController::class, 'getAllCountryNames']);
Route::get('/validation/criteria-data', [TerrafundCreateGeometryController::class, 'getCriteriaData']);
Route::post('/validation/criteria-data', [TerrafundCreateGeometryController::class, 'getCriteriaDataForMultiple']);
Route::get('/validation/overlapping', [TerrafundCreateGeometryController::class, 'validateOverlapping']);
Route::get('/validation/estimated-area', [TerrafundCreateGeometryController::class, 'validateEstimatedArea']);
Route::get('/validation/estimated-area-project', [TerrafundCreateGeometryController::class, 'validateEstimatedAreaProject']);
Expand Down
Loading