Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] add response example for bulk entities upload #1166

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

spwoodcock
Copy link
Contributor

Issue

  • Currently the docs for POST /projects/{projectId}/datasets/{name}/entities show the response type for uploading a single Entity.
  • They have not been updated to show the response type when bulk uploading multiple Entities.
  • Ideally the response would return the Entity data, but this is not trivial, due to having to re-fetch data from the db for each Entity (line 98 & 113):
    if (!entities) {
    // not a bulk operation
    const partial = await Entity.fromJson(body, properties, dataset);
    const sourceId = await Entities.createSource();
    const entity = await Entities.createNew(dataset, partial, null, sourceId, userAgent);
    // Entities.createNew doesn't return enough information for a full response so re-fetch.
    return Entities.getById(dataset.id, entity.uuid).then(getOrNotFound);
    } else {
    // bulk operation
    if (!Array.isArray(body.entities))
    return reject(Problem.user.unexpectedAttributes({ expected: ['entities: [...]'], actual: ['not an array'] }));
    if (!body.entities.length)
    return reject(Problem.user.unexpectedAttributes({ expected: ['entities: [...]'], actual: ['empty array'] }));
    const partials = body.entities.map(e => Entity.fromJson(e, properties, dataset));
    const sourceId = await Entities.createSource(extractBulkSource(source, partials.length, userAgent));
    await Entities.createMany(dataset, partials, sourceId, userAgent);
    return success();
    }

Solution

  • The endpoint currently returns 'success': true.
  • I updated the docs to reflect this, until the endpoint returns the Entity data (if possible).
  • I reused the pattern in the docs for return type application/json; extended to use application/json; bulk, allowing us to display two examples side-by-side - not sure if this is the preferred approach!

@matthew-white matthew-white self-requested a review October 1, 2024 21:21
Copy link
Member

@matthew-white matthew-white left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @spwoodcock! I definitely agree that it's useful to document this response.

@matthew-white matthew-white merged commit 911739b into getodk:master Dec 3, 2024
1 check passed
@spwoodcock spwoodcock deleted the docs/bulk-entity-response branch December 4, 2024 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants