asolfre / appengine-rest-server

Automatically exported from code.google.com/p/appengine-rest-server
Other
0 stars 0 forks source link

Add to/Subtract from values #52

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

I probably should not post this as an issue but i have a question.

I'm planning to use this project and i have the requirement to be able to 
increment/decrement a certain property of an entity.
But i'm having trouble finding out how to implement this while still preserve 
the RESTfullness.

Let's say i have a "Person" resource which has a "score" property that must be 
incremented/decremented.

After googling a bit i found a couple of ideas:

1. Just GET the person first, increment client side and POST back with updated 
values. This brings allong concurrency issues and overhead I suppose.

2. Create a "Score" resource. And create a new entity for each change?
Seems like a lot of overhead too. Would need to calculate the total score each 
time a Person is requested?

3. Override the "put" method in Person model to add/subtract the value instead 
of replace. But a don't think the is good practice?

(BTW I'n new to GAE and Python)

How can i do this?

thnx

Original issue reported on code.google.com by muijsenb...@gmail.com on 14 Feb 2012 at 9:47

GoogleCodeExporter commented 9 years ago
you're right, this isn't really the place to ask questions.  1. is really the 
only option that fits with this library, but you are also right that there are 
concurrency issues.  you would need to add some sort of version field and 
implement some sort of "put if up to date" handling.  2 is the wrong approach.  
3 is possible, but would involve custom value handling code on your part 
(probably more so than 1).

Original comment by jahlborn@gmail.com on 15 May 2012 at 12:17