0

I have a parent type call TaskList. A TaskList has many Tasks.

The simple case question that I have is how to move a Task from one TaskList to another.

I run a search query to find the set of Tasks that I want to move. The Tasks then are in the _embedded attribute of the JSON that comes back from that search. I want to then move those elements to a different TaskList. How would I do this?

Would I submit a POST to /tasklists/x with the _embedded Tasks as the body of that request?

Would I submit a PATCH to /tasks/y with a tasklist_id attribute already set?

What's the proper way to do this?

Thanks!

Louis F.
  • 2,018
  • 19
  • 22
Laran Evans
  • 1,283
  • 5
  • 15
  • 31

3 Answers3

0

As you suggested, you could submit a patch request according to : https://www.rfc-editor.org/rfc/rfc6902#section-4.4

Your json would look like something like this :

[
    {
        "op": "move",
        "from": "/tasklists/id/tasks/id",
        "path": "/tasklists/anotherId/tasks/id"
    },
    {
        "op": "move",
        "from": "/tasklists/id/tasks/id2",
        "path": "/tasklists/anotherId/tasks/id2"
    }
]

Hope it helps !

Community
  • 1
  • 1
Louis F.
  • 2,018
  • 19
  • 22
  • The "move" operation is for moving properties inside a JSON document. – a better oliver Jan 04 '16 at 10:50
  • Would you mind explaining why it is not relevant in this case ? It seems to me that the OP uses JSON representation of datas, therefore PATCH could be a great match. – Louis F. Jan 04 '16 at 14:04
  • Your example requires that the task has a `tasklist` property that contains an `id` property which will be removed, while an `anotherid` property is added. That makes no sense. – a better oliver Jan 04 '16 at 14:07
  • You are right ! Changed to something that is more consistent ! But I think Json PATCH is really the way to go in this case – Louis F. Jan 04 '16 at 14:13
  • According to the OP a task has a `tasklist_id`. You could change that using a `replace` operation. Changing a task list would most likely require an `add` operation, depending on the data structure, which we don't know. I removed the downvote hoping you come up with a better solution. – a better oliver Jan 04 '16 at 14:22
  • I changed once again my example to match the OP data structure, and to show how to move multiple tasks ! – Louis F. Jan 04 '16 at 16:08
0

Moving a task implies that it already exists and has a URI. You POST that URI to the URI of the target task list.

The appropriate content type is text/uri.

a better oliver
  • 26,330
  • 2
  • 58
  • 66
0

I'm using spring-data-rest on the server. What I ended up doing was sending a patch request to the item URL that looks like this:

{TaskList:"http:/host:port/tasklists/id"}

Here's a reference to a post which game me some insight. https://stackoverflow.com/a/26426909/1174250

Thanks everyone for your comments :)

Community
  • 1
  • 1
Laran Evans
  • 1,283
  • 5
  • 15
  • 31