aw-server-rust icon indicating copy to clipboard operation
aw-server-rust copied to clipboard

REPLACE endpoint for more reliably replacing events

Open johan-bjareholt opened this issue 5 years ago • 1 comments

So it's already possible to replace events by setting the "id" property in the /insert endpoint.

So why would you want to have a separate /replace endpoint?

  • Because /insert does not fail if the "id" does not exist, it creates a new event
  • If one out of many replaces in /insert fails we have no idea what actually happened, we need to do fetch the events after to be certain which should be unnecessary
  • Any other reasons, put a comment below and I'll add it to this list

I don't think this is a high priority task right now, might be in the future if we get a use-case which replaces a lot of events.

Resources:

  • Discussion on aw-server-python PR by @leoschwarz https://github.com/ActivityWatch/aw-server/pull/57

johan-bjareholt avatar Apr 05 '20 12:04 johan-bjareholt

My main reason for the linked PR was that I think at that time there was no event updating endpoint, but since it's possible I don't see a stringent need for it anymore. Also maybe it should be named update if it were to be added.

If one out of many replaces in /insert fails we have no idea what actually happened, we need to do fetch the events after to be certain which should be unnecessary

One could change https://github.com/ActivityWatch/aw-server-rust/blob/642a5315cd7ccbcb5aa24df73ce1b6096881616a/aw-server/src/endpoints/bucket.rs#L142-L149

to return per event success/failure information in the response body (and set success in the header if everything succeeded, failure otherwise). For example, you could add an additional "success": field to events inserted, the details of this would be something to think about if this approach is chosen.

So I think it's mainly an API design choice whether to have this endpoint or not (simpler vs lower number of endpoints).

leoschwarz avatar Apr 05 '20 21:04 leoschwarz