Skip to content

Commit

Permalink
Update openapi for project protected areas list
Browse files Browse the repository at this point in the history
  • Loading branch information
yulia-bel committed Sep 20, 2023
1 parent 7679988 commit 2b8936a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
34 changes: 34 additions & 0 deletions api/apps/api/src/decorators/json-api-parameters.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -130,3 +157,10 @@ export const JSONAPISingleEntityQueryParams = (fetchConfiguration?: {
fieldsQueryParam,
omitFieldsQueryParam,
);

export const JSONAPIProtectedAreasListQueryParams = () =>
applyDecorators(
protectedAreasFilterQueryParam,
protectedAreasSortQueryParam,
protectedAreasSearchQueryParam,
);
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ApiForbiddenResponse,
ApiOkResponse,
ApiOperation,
ApiQuery,
ApiTags,
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
Expand All @@ -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)
Expand All @@ -54,7 +58,7 @@ export class ProjectProtectedAreasController {
isArray: true,
})
@ApiUnauthorizedResponse()
@JSONAPIQueryParams()
@JSONAPIProtectedAreasListQueryParams()
@ApiForbiddenResponse()
@Get(':projectId/protected-areas')
async findAllProtectedAreasForProject(
Expand Down

0 comments on commit 2b8936a

Please sign in to comment.