swisstopo / swissgeol-assets-suite

1 stars 0 forks source link

Feature 99: Refactor Suche - Backend #104

Closed daniel-va closed 1 month ago

daniel-va commented 2 months ago

Solves #102 as part of #99.

Adds the new API endpoint POST /api/assets/search which can be used as a replacement for POST /api/search-asset and GET /api/asset. The endpoint can be tested via the asset-search.http file.

The endpoint's request format is described via AssetSearchQuery, its response in AssetSearchResult. To parse the response, use:

import { plainToInstance } from 'class-transformer';
import { AssetSearchResultDTO } from '@asset-sg/shared';

const serializedResult = /* ...fetch data... */;
const result = plainToInstance(AssetSearchResultDTO, serializedResult);

Due to fp-ts not being compatible with class-transformer, the returned assets will need to be parsed individually:

import { AssetEditDetail} from '@asset-sg/shared';

result.data = result.data.map(AssetEditDetail.decode)

To complement the search, the endpoint POST /api/assets/search/stats has been added, which allows retrieval of aggregations related to a specific search. It can be used with the same query as the search endpoint itself, and returns values of type AssetSearchStats.

Other Changes