-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TM-1461] waiting load for data polygons (#582)
* add basic endpoints * move endpoints outside admin * fix duplicate * [TM-1461] add entity for site and project endpoint * [TM-1461] fix distinct responses * [TM-1461] lint --------- Co-authored-by: Jose Carlos Laura Ramirez <[email protected]>
- Loading branch information
1 parent
49ca423
commit dbf01a1
Showing
12 changed files
with
595 additions
and
2 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
app/Http/Controllers/V2/Sites/AdminSitesPolygonController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\V2\Sites; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\V2\Projects\Project; | ||
use App\Models\V2\Sites\SitePolygon; | ||
use App\Services\PolygonService; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\App; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class AdminSitesPolygonController extends Controller | ||
{ | ||
public function __invoke(Request $request): JsonResponse | ||
{ | ||
try { | ||
$uuid = $request->input('uuid'); | ||
$type = $request->input('type'); | ||
$offset = $request->input('offset', 0); | ||
$limit = $request->input('limit', 10); | ||
$request = request(); | ||
|
||
|
||
if ($type === 'projects') { | ||
$project = Project::where('uuid', $uuid)->firstOrFail(); | ||
$finalEntityQuery = App::make(PolygonService::class)->getSitePolygonsWithFiltersAndSorts($project->sitePolygons(), $request); | ||
} elseif ($type === 'sites') { | ||
$sitePolygonsQuery = SitePolygon::active()->where('site_id', $uuid); | ||
$finalEntityQuery = App::make(PolygonService::class)->getSitePolygonsWithFiltersAndSorts($sitePolygonsQuery, $request); | ||
} | ||
$sitePolygons = $finalEntityQuery | ||
->offset($offset) | ||
->limit($limit) | ||
->get(); | ||
|
||
return response()->json($sitePolygons); | ||
} catch (\Exception $e) { | ||
Log::error($e->getMessage()); | ||
|
||
return response()->json(['error' => 'An error occurred while fetching site polygons'], 500); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
app/Http/Controllers/V2/Sites/AdminSitesPolygonCountController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\V2\Sites; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\V2\Projects\Project; | ||
use App\Models\V2\Sites\SitePolygon; | ||
use App\Services\PolygonService; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\App; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class AdminSitesPolygonCountController extends Controller | ||
{ | ||
public function __invoke(Request $request): JsonResponse | ||
{ | ||
try { | ||
$uuid = $request->input('uuid'); | ||
$type = $request->input('type'); | ||
$request = request(); | ||
if ($type === 'projects') { | ||
$project = Project::where('uuid', $uuid)->firstOrFail(); | ||
$countSitePolygons = App::make(PolygonService::class)->getSitePolygonsWithFiltersAndSorts($project->sitePolygons(), $request); | ||
} elseif ($type === 'sites') { | ||
$sitePolygonsQuery = SitePolygon::active()->where('site_id', $uuid); | ||
$countSitePolygons = App::make(PolygonService::class)->getSitePolygonsWithFiltersAndSorts($sitePolygonsQuery, $request); | ||
} | ||
|
||
$totalCount = $countSitePolygons->count(); | ||
|
||
return response()->json([ | ||
'count' => $totalCount, | ||
]); | ||
} catch (\Exception $e) { | ||
Log::error($e->getMessage()); | ||
|
||
return response()->json(['error' => 'An error occurred while fetching site polygons'], 500); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
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[poly_name]=asc or sort[status]=desc` | ||
type: string | ||
responses: | ||
'200': | ||
description: Successful response | ||
schema: | ||
type: object | ||
properties: | ||
count: | ||
type: number | ||
'500': | ||
description: Internal server error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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[poly_name]=asc or sort[status]=desc` | ||
type: string | ||
responses: | ||
'200': | ||
description: Successful response | ||
schema: | ||
$ref: '../../definitions/_index.yml#/EntityPolygonResponse' | ||
'400': | ||
description: Bad request, UUID parameter is missing | ||
'500': | ||
description: Internal server error | ||
schema: | ||
type: object | ||
properties: | ||
error: | ||
type: string | ||
description: Error message |
17 changes: 17 additions & 0 deletions
17
openapi-src/V2/paths/Sites/get-v2-admin-sites-uuid-polygons-count.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
summary: Get count polygons for a specific site | ||
parameters: | ||
- in: path | ||
name: UUID | ||
required: true | ||
type: string | ||
description: The UUID of the site | ||
responses: | ||
'200': | ||
description: Successful response | ||
schema: | ||
type: object | ||
properties: | ||
count: | ||
type: number | ||
'500': | ||
description: Internal server error |
26 changes: 26 additions & 0 deletions
26
openapi-src/V2/paths/Sites/get-v2-admin-sites-uuid-polygons.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
summary: Get polygons for a specific site | ||
parameters: | ||
- in: path | ||
name: UUID | ||
required: true | ||
type: string | ||
description: The UUID of the site | ||
- in: query | ||
name: limit | ||
required: true | ||
description: The maximum number of polygons to return | ||
type: number | ||
- in: query | ||
name: offset | ||
required: true | ||
description: The number of polygons to skip | ||
type: string | ||
responses: | ||
'200': | ||
description: Successful response | ||
schema: | ||
type: array | ||
items: | ||
$ref: '../../definitions/_index.yml#/SitePolygon' | ||
'500': | ||
description: Internal server error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.