diff --git a/lib/controllers/v1/projects_controller.js b/lib/controllers/v1/projects_controller.js index 088c3abb..a58379d7 100644 --- a/lib/controllers/v1/projects_controller.js +++ b/lib/controllers/v1/projects_controller.js @@ -221,7 +221,7 @@ const ProjectsController = class ProjectsController { static async show( req ) { InaturalistAPI.setPerPage( req, { max: 100 } ); - const ids = _.filter( req.params.id.split( "," ), _.identity ); + const ids = _.filter( req.params.id.toString( ).split( "," ), _.identity ); if ( ids.length > req.query.per_page ) { throw util.httpError( 422, "Too many IDs" ); } @@ -290,7 +290,7 @@ const ProjectsController = class ProjectsController { null, "prup.owner_id = pu.id AND prup.owner_type = 'ProjectUser' AND prup.name = 'updates'" ) - .where( "p.id IN (?)", ids ) + .where( "p.id IN ?", ids ) .where( "pu.user_id = ?", req.userSession.user_id ); const { rows } = await pgClient.query( query.toString( ) ); _.each( rows, row => { @@ -344,13 +344,13 @@ const ProjectsController = class ProjectsController { static async posts( req ) { const { page, perPage } = InaturalistAPI.paginationData( req, { default: 10, max: 30 } ); - const ids = _.filter( req.params.id.split( "," ), _.identity ); + const ids = _.filter( req.params.id.toString( ).split( "," ), _.identity ); let numericIDs = _.filter( ids, id => Number( id ) ); if ( _.isEmpty( numericIDs ) ) { numericIDs = [-1]; } const query = squel.select( ).field( "posts.*, count(*) OVER() AS total_count" ) .from( "posts" ) .join( "projects", null, "posts.parent_id = projects.id AND parent_type='Project'" ) - .where( "projects.id IN (?) OR projects.slug IN (?)", numericIDs, ids ) + .where( "projects.id IN ? OR projects.slug IN ?", numericIDs, ids ) .where( "posts.published_at IS NOT NULL" ) .order( "posts.published_at", false ) .limit( perPage ) diff --git a/lib/controllers/v2/projects_controller.js b/lib/controllers/v2/projects_controller.js deleted file mode 100644 index 00c06787..00000000 --- a/lib/controllers/v2/projects_controller.js +++ /dev/null @@ -1,18 +0,0 @@ -const ctrlv1 = require( "../v1/projects_controller" ); - -const show = async req => { - if ( req.params.id && typeof ( req.params.id ) !== "string" ) { - req.params.id = req.params.id.join( "," ); - } - return ctrlv1.show( req ); -}; - -module.exports = { - join: ctrlv1.join, - leave: ctrlv1.leave, - members: ctrlv1.members, - membership: ctrlv1.membership, - posts: ctrlv1.posts, - search: ctrlv1.search, - show -}; diff --git a/lib/views/swagger_v1.yml.ejs b/lib/views/swagger_v1.yml.ejs index 982a68b6..6066c703 100644 --- a/lib/views/swagger_v1.yml.ejs +++ b/lib/views/swagger_v1.yml.ejs @@ -1562,10 +1562,10 @@ paths: get: summary: Membership of current user description: | - Given a project ID, return the details of the authenticated user's - membership in that project + Given an ID, or an array of IDs in comma-delimited format, return the details of the + authenticated user's membership in these projects parameters: - - $ref: "#/parameters/path_id" + - $ref: "#/parameters/path_multi_id" tags: - Projects security: diff --git a/openapi/paths/v2/projects.js b/openapi/paths/v2/projects.js index 2beeb144..0f2166ed 100644 --- a/openapi/paths/v2/projects.js +++ b/openapi/paths/v2/projects.js @@ -1,7 +1,7 @@ const _ = require( "lodash" ); const projectsSearchSchema = require( "../../schema/request/projects_search" ); const transform = require( "../../joi_to_openapi_parameter" ); -const ProjectsController = require( "../../../lib/controllers/v2/projects_controller" ); +const ProjectsController = require( "../../../lib/controllers/v1/projects_controller" ); module.exports = sendWrapper => { async function GET( req, res ) { diff --git a/openapi/paths/v2/projects/{id}.js b/openapi/paths/v2/projects/{id}.js index 2f41c38d..35e9929b 100644 --- a/openapi/paths/v2/projects/{id}.js +++ b/openapi/paths/v2/projects/{id}.js @@ -1,6 +1,6 @@ const Joi = require( "joi" ); const transform = require( "../../../joi_to_openapi_parameter" ); -const projectsController = require( "../../../../lib/controllers/v2/projects_controller" ); +const projectsController = require( "../../../../lib/controllers/v1/projects_controller" ); module.exports = sendWrapper => { async function GET( req, res ) { diff --git a/openapi/paths/v2/projects/{id}/members.js b/openapi/paths/v2/projects/{id}/members.js index 11979d26..8703be3d 100644 --- a/openapi/paths/v2/projects/{id}/members.js +++ b/openapi/paths/v2/projects/{id}/members.js @@ -1,8 +1,8 @@ const _ = require( "lodash" ); const Joi = require( "joi" ); const transform = require( "../../../../joi_to_openapi_parameter" ); -const ProjectsController = require( "../../../../../lib/controllers/v2/projects_controller" ); -const observationsSearchSchema = require( "../../../../schema/request/projects_members" ); +const ProjectsController = require( "../../../../../lib/controllers/v1/projects_controller" ); +const projectsMembersSchema = require( "../../../../schema/request/projects_members" ); module.exports = sendWrapper => { async function GET( req, res ) { @@ -10,9 +10,18 @@ module.exports = sendWrapper => { sendWrapper( req, res, null, results ); } - const parameters = _.map( - observationsSearchSchema.$_terms.keys, - child => transform( child.schema.label( child.key ) ) + const parameters = [ + transform( + Joi.number( ).integer( ) + .label( "id" ) + .meta( { in: "path" } ) + .required( ) + .description( "A single ID" ) + ) + ].concat( + _.map( projectsMembersSchema.$_terms.keys, child => ( + transform( child.schema.label( child.key ) ) + ) ) ); parameters.push( transform( Joi.string( ).label( "X-HTTP-Method-Override" ).meta( { in: "header" } ) ) diff --git a/openapi/paths/v2/projects/{id}/membership.js b/openapi/paths/v2/projects/{id}/membership.js index a0dcfede..5f3e2284 100644 --- a/openapi/paths/v2/projects/{id}/membership.js +++ b/openapi/paths/v2/projects/{id}/membership.js @@ -1,6 +1,6 @@ const Joi = require( "joi" ); const transform = require( "../../../../joi_to_openapi_parameter" ); -const projectsController = require( "../../../../../lib/controllers/v2/projects_controller" ); +const projectsController = require( "../../../../../lib/controllers/v1/projects_controller" ); module.exports = sendWrapper => { async function GET( req, res ) { @@ -16,11 +16,12 @@ module.exports = sendWrapper => { }], parameters: [ transform( - Joi.number( ).integer( ) + Joi.array( ) + .items( Joi.number( ).integer( ) ) .label( "id" ) .meta( { in: "path" } ) .required( ) - .description( "A single project ID" ) + .description( "A single ID or a comma-separated list of them" ) ), transform( Joi.string( ).label( "fields" ).meta( { in: "query" } ) ), transform( Joi.string( ).label( "X-HTTP-Method-Override" ).meta( { in: "header" } ) ) diff --git a/openapi/paths/v2/projects/{id}/posts.js b/openapi/paths/v2/projects/{id}/posts.js index 3d31b47d..c09d8bb5 100644 --- a/openapi/paths/v2/projects/{id}/posts.js +++ b/openapi/paths/v2/projects/{id}/posts.js @@ -1,7 +1,7 @@ const _ = require( "lodash" ); const Joi = require( "joi" ); const transform = require( "../../../../joi_to_openapi_parameter" ); -const ProjectsController = require( "../../../../../lib/controllers/v2/projects_controller" ); +const ProjectsController = require( "../../../../../lib/controllers/v1/projects_controller" ); const projectsPostsSchema = require( "../../../../schema/request/projects_posts" ); module.exports = sendWrapper => { @@ -10,9 +10,19 @@ module.exports = sendWrapper => { sendWrapper( req, res, null, results ); } - const parameters = _.map( - projectsPostsSchema.$_terms.keys, - child => transform( child.schema.label( child.key ) ) + const parameters = [ + transform( + Joi.array( ) + .items( Joi.number( ).integer( ) ) + .label( "id" ) + .meta( { in: "path" } ) + .required( ) + .description( "A single ID or a comma-separated list of them" ) + ) + ].concat( + _.map( projectsPostsSchema.$_terms.keys, child => ( + transform( child.schema.label( child.key ) ) + ) ) ); parameters.push( transform( Joi.string( ).label( "X-HTTP-Method-Override" ).meta( { in: "header" } ) ) diff --git a/openapi/schema/request/projects_members.js b/openapi/schema/request/projects_members.js index 169635e6..3d896a8b 100644 --- a/openapi/schema/request/projects_members.js +++ b/openapi/schema/request/projects_members.js @@ -4,8 +4,8 @@ module.exports = Joi.object( ).keys( { page: Joi.number( ).integer( ), per_page: Joi.number( ).integer( ), fields: Joi.any( ), - order_by: Joi.array( ).items( Joi.string( ).valid( + order_by: Joi.string( ).valid( "observations_count", "login" - ) ).default( "observations_count" ) + ).default( "observations_count" ) } ).unknown( false );