Skip to content

Commit 8666975

Browse files
Add ability to query backend with multiple IDs (#741)
* fetch features by ids * handle exceptions * Standardize naming --------- Co-authored-by: Garrett Stevens <stevens.garrett.j@gmail.com>
1 parent 1b95bfe commit 8666975

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

packages/apollo-collaboration-server/src/entity/gff3Object.dto.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ export interface FeatureRangeSearchDto {
2828
start: number
2929
end: number
3030
}
31+
32+
export interface FeatureIdsSearchDto {
33+
featureIds: string[]
34+
topLevel?: boolean
35+
}

packages/apollo-collaboration-server/src/features/features.controller.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import {
2+
Body,
23
Controller,
34
Get,
45
Logger,
56
Param,
67
ParseBoolPipe,
8+
Post,
79
Query,
810
} from '@nestjs/common'
911

10-
import { FeatureRangeSearchDto } from '../entity/gff3Object.dto'
12+
import {
13+
FeatureIdsSearchDto,
14+
FeatureRangeSearchDto,
15+
} from '../entity/gff3Object.dto'
1116
import { Role } from '../utils/role/role.enum'
1217
import { Validations } from '../utils/validation/validatation.decorator'
1318

@@ -37,14 +42,23 @@ export class FeaturesController {
3742
* or if search data was not found or in case of error throw exception
3843
*/
3944
@Get('getFeatures')
40-
getFeatures(@Query() request: FeatureRangeSearchDto) {
45+
getFeaturesByRange(@Query() request: FeatureRangeSearchDto) {
4146
this.logger.debug(
42-
`getFeaturesByCriteria -method: refSeq: ${request.refSeq}, start: ${request.start}, end: ${request.end}`,
47+
`getFeatures endpoint: refSeq: ${request.refSeq}, start: ${request.start}, end: ${request.end}`,
4348
)
4449

4550
return this.featuresService.findByRange(request)
4651
}
4752

53+
@Post('getByIds')
54+
findByFeatureIds(@Body() request: FeatureIdsSearchDto) {
55+
this.logger.debug(`: featureIds: ${JSON.stringify(request.featureIds)}`)
56+
return this.featuresService.findByFeatureIds(
57+
request.featureIds,
58+
request.topLevel,
59+
)
60+
}
61+
4862
@Get('count')
4963
async getFeatureCount(@Query() featureCountRequest: FeatureCountRequest) {
5064
this.logger.debug(

packages/apollo-collaboration-server/src/features/features.service.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,33 @@ export class FeaturesService {
117117
return
118118
}
119119

120+
async findByFeatureIds(featureIds: string[], topLevel?: boolean) {
121+
const foundFeatures: Feature[] = []
122+
// all featureIds that have already been fetched
123+
const fetchedFeatureIds = new Set<string>()
124+
125+
for (const featureId of featureIds) {
126+
if (fetchedFeatureIds.has(featureId)) {
127+
this.logger.debug(`FeatureId ${featureId} already fetched, skipping...`)
128+
continue
129+
}
130+
131+
try {
132+
const feature = await this.findById(featureId, topLevel)
133+
foundFeatures.push(feature)
134+
for (const id of feature.allIds) {
135+
fetchedFeatureIds.add(id)
136+
}
137+
} catch (error) {
138+
this.logger.error(
139+
`Error occurred while fetching feature ${featureId}`,
140+
error instanceof Error ? error.stack : String(error),
141+
)
142+
}
143+
}
144+
return foundFeatures
145+
}
146+
120147
/**
121148
* Get feature by featureId. When retrieving features by id, the features and any of its children are returned, but not any of its parent or sibling features.
122149
* @param featureId - featureId

0 commit comments

Comments
 (0)