Now that we have a circle-related api, we will create an item-related api. This time (42nd) I participated in and worked on the Python mini Hack-a-thon. http://connpass.com/event/5775/
You can register from this UI.
The things to do are almost the same as last time, but this time the number of registered thumbnails varies from 1 to 4
#Item information sold by the circle. 1 entity=1 item
class CircleItem(BaseModel):
circleInfomation = ndb.KeyProperty(kind=CircleInfomation) #Sales circle
name = ndb.StringProperty() #Item name
thumbUrls1 = ndb.StringProperty() #Item thumbnail part 1
thumbUrls2 = ndb.StringProperty() #Item thumbnail part 2
thumbUrls3 = ndb.StringProperty() #Item thumbnail part 3
thumbUrls4 = ndb.StringProperty() #Item thumbnail part 4
description = ndb.StringProperty() #Item description
count = ndb.IntegerProperty() #Number of units sold
price = ndb.IntegerProperty() #price
You can put properties for each thumbnail, but the purpose of thumbnail properties is the same. It seems good to put them all in one property.
#Item information sold by the circle. 1 entity=1 item
class CircleItem(BaseModel):
circleInfomation = ndb.KeyProperty(kind=CircleInfomation) #Sales circle
name = ndb.StringProperty() #Item name
thumbUrls = ndb.StringProperty(repeated=True) #Item thumbnail URL(Up to 4)
description = ndb.StringProperty() #Item description
count = ndb.IntegerProperty() #Number of units sold
price = ndb.IntegerProperty() #price
I did this.
If you try to display it in multiple requests in the server, cursor processing will be performed. The AppEngineSDK has useful functions, so I try to attach the URL if there is a continuation based on that. Webapp2 # uri_for was useful for URL generation.
#Query Data Store
entitylist, next_curs, more = CircleItem.query(CircleItem.circleInfomation==circleInfo.key).fetch_page(limit, start_cursor=cursor)
#Generate the following URL if there is a continuation
next_url = None
if more:
next_url = webapp2.uri_for('Infomation',circleid=circleid,limit=limit,cursor=next_curs.urlsafe())
#Set this data
itemList = []
for e in entitylist:
item = Common.createCircleItemResponseFromEntity(e)
itemList.append(item)
res = dict(
itemList = itemList,
next = next_url
)
#Convert to JSON and return to client
Common.writeUserResponseSuccess(self, res )
For example http://localhost:8080/user/api/circleitem/infomation?circleid=1 If you make such a request,
{
"response":
{
"status":200
},
"next":"http://localhost:8080/user/api/circleitem/infomation?circleid=1&limit=1&cursor=E-ABAIICLWoSZGV2fmZyZWVtYXJrZXQtYXBwchcLEgpDaXJjbGVJdGVtGICAgICA4JcJDBQ=",
"itemList":
[
{
"price":1000,
"thumbUrls":[
"http://localhost:8080/user/api/circleitem/thumbnail?circleitemid=5171003185430528&no=0"
],
"count":12,
"name":"Item name",
"description":"Item details"}
]
}
When such a request is returned, `" next ":" http: // localhost: 8080 / user / api / circleitem / infomation? Circleid = 1 & limit = 1 & cursor = E-ABAIICLWoSZGV2fmZyZWVtYXJrZXQtYXBwchcLEgpDaXJjbGVJdGVtGICAg You can get them in order.
That's how the brunch to date was made https://github.com/nagai/freemarket/tree/20140412
I want to change the UI color
Unknown shipping method
I want to decide the error handling It's better to decide what to do if the client's request is invalid ・ Restart the app ・ Make the same request again Is it right?
I want to test Right now I'm experimenting with chrome extention's Advanced REST client. It's getting more and more work, so I'd like to introduce another method.
Next, we will create the client side.
Recommended Posts