zooniverse / designator

Smart task assignment system
2 stars 1 forks source link

Add API to allow updates to a user's seen subject ids for a workflow #86

Closed camallen closed 5 years ago

camallen commented 5 years ago

Closes #85 by adding an API to update a user's subjects seen_ids list

Allow a cached user to have their seen_ids updated via PUT api endpoints that accepts JSON encoded data payloads:

  1. /api/users/#{user_id}/add_seen_subjects
    • accepts { workflow_id: ${workflow_id}, subject_ids: [1,2,3]}
  2. /api/users/#{user_id}/add_seen_subject
    • accepts { workflow_id: ${workflow_id}, subject_id: 4}

The implementation is similar to the existing reliance on the ConCache ETS memory store, i.e the workflow do_remove at /api/workflows/:id/remove which wrapped the RecentlyRetired ConCache store.

It will raise an error if the workflow_id is not a string or integer that can be cast to an integer. It will check and cast all subject_ids to valid integers before storing in the user cache seen_ids. If any subject_id can not be cast it will return a 422 with a message invalid subject id supplied, must be a valid integer.

I tried to add better incoming param schema checking but it wasn't nice and added a dep, i left it as it is because it's how it already is combined with the fact it is an internal API and the manta of erlang is fail fast if you are going to fail. If this becomes an issue we can provide better param validation later.

Finally the concache is one big state store shared between tests, i couldn't get the store to reset the cache between tests so came up with a way to reset it manually. Not super happy with it but it works for now.

camallen commented 5 years ago

I might suggest an additional spec that tests the union of existing and updated subject ids, in addition to testing deduplication when the existing set is already fully included.

Done :)

zwolf commented 5 years ago

:shipit: