diff --git a/api/apps/api/src/decorators/json-api-parameters.decorator.ts b/api/apps/api/src/decorators/json-api-parameters.decorator.ts index dc4cd71a08..62ccaf6399 100644 --- a/api/apps/api/src/decorators/json-api-parameters.decorator.ts +++ b/api/apps/api/src/decorators/json-api-parameters.decorator.ts @@ -76,6 +76,33 @@ const disablePaginationQueryParam = ApiQuery({ required: false, }); +const protectedAreasFilterQueryParam = ApiQuery({ + name: 'filter', + example: 'filter[name]=II&filter[name]=customAreaName', + description: `An array of filters for name property`, + type: String, + isArray: true, + required: false, +}); + +const protectedAreasSortQueryParam = ApiQuery({ + name: 'sort', + example: 'sort=name', + description: + 'Sorting protected area by name, can prefixed with a minus (for descending order). ' + + 'Accepted values: name or -name', + type: String, + required: false, +}); + +const protectedAreasSearchQueryParam = ApiQuery({ + name: 'q', + example: 'q=keyWord', + description: 'Search will be performed on name property of protected area.', + type: String, + required: false, +}); + /** * Method decorator: convenience wrapper for OpenAPI annotations common to most * JSON:API plural GET endpoints. @@ -130,3 +157,10 @@ export const JSONAPISingleEntityQueryParams = (fetchConfiguration?: { fieldsQueryParam, omitFieldsQueryParam, ); + +export const JSONAPIProtectedAreasListQueryParams = () => + applyDecorators( + protectedAreasFilterQueryParam, + protectedAreasSortQueryParam, + protectedAreasSearchQueryParam, + ); diff --git a/api/apps/api/src/modules/projects/project-protected-areas.controller.ts b/api/apps/api/src/modules/projects/project-protected-areas.controller.ts index 21637dc0d2..fed441afc4 100644 --- a/api/apps/api/src/modules/projects/project-protected-areas.controller.ts +++ b/api/apps/api/src/modules/projects/project-protected-areas.controller.ts @@ -14,6 +14,7 @@ import { ApiForbiddenResponse, ApiOkResponse, ApiOperation, + ApiQuery, ApiTags, ApiUnauthorizedResponse, } from '@nestjs/swagger'; @@ -33,7 +34,10 @@ import { FetchSpecification, ProcessFetchSpecification, } from 'nestjs-base-service'; -import { JSONAPIQueryParams } from '@marxan-api/decorators/json-api-parameters.decorator'; +import { + JSONAPIProtectedAreasListQueryParams, + JSONAPIQueryParams, +} from '@marxan-api/decorators/json-api-parameters.decorator'; import { ProtectedAreaResult } from '@marxan-api/modules/protected-areas/protected-area.geo.entity'; @UseGuards(JwtAuthGuard) @@ -54,7 +58,7 @@ export class ProjectProtectedAreasController { isArray: true, }) @ApiUnauthorizedResponse() - @JSONAPIQueryParams() + @JSONAPIProtectedAreasListQueryParams() @ApiForbiddenResponse() @Get(':projectId/protected-areas') async findAllProtectedAreasForProject(