Skip to content

Commit

Permalink
v2 nls wrapper endpoint; use minimal observation association loading
Browse files Browse the repository at this point in the history
  • Loading branch information
pleary committed Jun 25, 2024
1 parent f6b4880 commit 810c13e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/controllers/v1/computervision_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ const ComputervisionController = class ComputervisionController {
} );
const results = _.values( resultsObject );
const localeOpts = util.localeOpts( req );
await Observation.preloadInto( req, results, localeOpts );
await Observation.preloadInto( req, results, { ...localeOpts, minimal: true } );
_.each( results, r => {
delete r.observation_id;
} );
Expand Down
41 changes: 41 additions & 0 deletions openapi/paths/v2/computervision/language_search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const _ = require( "lodash" );
const languageSearchSchema = require( "../../../schema/request/language_search" );
const transform = require( "../../../joi_to_openapi_parameter" );
const computervisionController = require( "../../../../lib/controllers/v1/computervision_controller" );

module.exports = sendWrapper => {
async function GET( req, res ) {
const results = await computervisionController.languageSearch( req );
sendWrapper( req, res, null, results );
}

GET.apiDoc = {
tags: ["Computer Vision"],
summary: "Fetch language demo search results for a search term",
security: [{
appOrUserJwtRequired: []
}],
"x-unpublished": true,
parameters: _.map(
languageSearchSchema.$_terms.keys, child => (
transform( child.schema.label( child.key ) )
)
),
responses: {
200: {
description: "An array of language demo search results",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/ResultsLanguageSearch"
}
}
}
}
}
};

return {
GET
};
};
10 changes: 10 additions & 0 deletions openapi/schema/request/language_search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const Joi = require( "joi" );

module.exports = Joi.object( ).keys( {
q: Joi.string( ),
taxon_id: Joi.array( ).items( Joi.number( ).integer( ) ),
locale: Joi.string( ),
page: Joi.number( ).integer( ),
per_page: Joi.number( ).integer( ),
fields: Joi.any( )
} ).unknown( false ).meta( { unpublished: true } );
15 changes: 15 additions & 0 deletions openapi/schema/response/results_language_search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const Joi = require( "joi" );
const observation = require( "./observation" );

module.exports = Joi.object( ).keys( {
total_results: Joi.number( ).integer( ).required( ),
page: Joi.number( ).integer( ).required( ),
per_page: Joi.number( ).integer( ).required( ),
results: Joi.array( ).items(
Joi.object( {
photo_id: Joi.number( ).integer( ).required( ),
score: Joi.number( ).required( ),
observation
} )
).required( )
} ).unknown( false ).meta( { unpublished: true } );

0 comments on commit 810c13e

Please sign in to comment.