In any event my first iteration on it resulting in a cruddy little app for Eat. http://eat-lift-move.appspot.com/
It took me like 3 hours to get there but probably more than half of that I was trying to figure out how to frickin' delete 'eat' entries. The tutorial talked about deleting via 'keys' and deleting entities directly. Not enough info to encode a 'Delete' link in a cruddy little HTML table. Old school baby!
But I finally figured it out. The key is using the KeyFactory http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/KeyFactory.html
On the entity there is an implicity 'key' field that you can encode for a web link via 'KeyFactory.keyToString()' and then later on when parsing the parameters you can 'add water' to it by calling 'KeyFactory.stringToKey()'. Once you have the actual key you can do key.delete(). But nowhere in the little tutorial did it tell me that.
I still like Gaelyk and plan to play with it more. It's like the code I wrote 10 years ago but less of it. Deployments are free and I don't have to invest much to get going. Even deploying a Grails app public seem like too much work initially.
I might actually see this project through! Not likely but we'll see.
Posting my code to github -> git@github.com:twcrone/eat-lift-move.git
list.gptl
>>
...
<tr>
<td>${eat.year}-${eat.month}-${eat.day}</td>
<td>${eat.name}</td>
<td>${eat.protein}</td>
<td>${eat.carbs}</td>
<td>${eat.fat}</td>
<td>${eat.calories}</td>
<td><a href="/eat/delete?id=${KeyFactory.keyToString(eat.key)}">Delete</a></td>
</tr>
...
<<
delete.groovy
>>
import com.google.appengine.api.datastore.*
import static com.google.appengine.api.datastore.FetchOptions.Builder.*
def keyStr = params.id
if(!keyStr) {
throw new RuntimeException("Key for delete was null")
}
def key = KeyFactory.stringToKey(keyStr)
key.delete()
redirect "/"
<<
No comments:
Post a Comment