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

Custom upload endpoints #81

Open
amercader opened this issue Dec 2, 2022 · 0 comments
Open

Custom upload endpoints #81

amercader opened this issue Dec 2, 2022 · 0 comments

Comments

@amercader
Copy link
Member

High-level spec: #65 (comment)

Update the ckanext-validation blueprint to include:

  1. An endpoint that accepts an uploaded file or a URL and creates a resource with a file (POST /dataset/<dataset_id>/resource/file). This will be used when in step 1 of creating a new resource (uploading the file). This endpoint will:

    • Do some data processing and call resource_create with the package_id and the upload / url fields
    • Decide if this resource is a tabular one, and if so detect the schema calling resource_table_schema_infer (see Add a new resource_table_schema_infer action  #76)
    • Return the dataset id, the resource id and the inferred table schema description if present
  2. An endpoint that accepts an uploaded file or a URL and updates the file of resource (POST /dataset/<dataset_id>/resource/<resource_id>/file). This will be used when updating an existing resource. This endpoint will:

    • Do some data processing and call resource_patch with the resource_id and the upload / url fields
    • Decide if this resource is a tabular one, and if so detect the schema calling resource_table_schema_infer (see Add a new resource_table_schema_infer action  #76)
    • Return the dataset id, the resource id and the inferred table schema description if present

Additional endpoints:

  • Do we need a custom endpoint for step 2 of creating a new resource (clicking "Save")? The standard resource create endpoint (POST /dataset/<dataset_id>/new) seems to support updating an existing resource if a resource id is provided so that might work out of the box. We just need to make sure client-side that the resource_id is set after getting the response from step 1 (and that the file is not submitted again). That would cover the "Finish" and "Save and Add another" buttons
  • What happens if a user hits "Previous" or leaves the page after uploading a file? CKAN does not have a concept of "draft resources" so I think we just need to delete the resource:
    • For the "Previous" rather than overriding the whole core /dataset/resource/new endpoint, I think it will be easier to have a custom endpoint (POST /dataset/<dataset_id>/resource/cancel) that accepts a resource_id (which we'll have if we have uploaded a file) and deletes the resource and the file. If there is no resource_id we just submit the default endpoint.
    • If the user leaves the page without having clicked on "Finish" we can maybe rely on beforeunload to fire a request to the previous endpoint?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant