Let's make a spot sale service 4 (in Python mini Hack-a-thon)

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/

additem.jpg

You can register from this UI.

New things I learned

About Entity design

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.

About query cursor processing

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

Future tasks

next time

Next, we will create the client side.

Recommended Posts

Let's make a spot sale service 4 (in Python mini Hack-a-thon)
Let's make a spot sale service 2
Let's make a spot sale service 1
Let's make a spot sale service 3
Let's make a spot sale service 9 (Task Queue edition)
Let's make a spot sale service 8 (image uploader edition)
Let's make a combination calculation in Python
Make a bookmarklet in Python
Let's make a GUI with python.
Let's make a graph with python! !!
Let's make a shiritori game with Python
Let's make a voice slowly with Python
Let's make a web framework with Python! (1)
Let's make a Twitter Bot with Python!
Let's make a web framework with Python! (2)
Make a copy of the list in Python
Make a rock-paper-scissors game in one line (python)
Let's make some notification processing samples in Python
Let's replace UWSC with Python (5) Let's make a Robot
Make a joyplot-like plot of R in python
Let's make a module for Python using SWIG
Try to make a Python module in C language
I want to write in Python! (2) Let's write a test
Make a simple Slackbot with interactive button in python
[Let's play with Python] Make a household account book
Let's make a simple game with Python 3 and iPhone
[For play] Let's make Yubaba a LINE Bot (Python)
[Super easy] Let's make a LINE BOT with Python.
Let's make a cron program in Java! !! (Task Scheduler)
Let's make a leap in the manufacturing industry by utilizing the Web in addition to Python
Let's make a websocket client with Python. (Access token authentication)
Let's use def in python
Take a screenshot in Python
Let's make a Discord Bot.
Create a function in Python
Create a dictionary in Python
Make a table of multiplication of each element in a spreadsheet (Python)
WIFI spot scan in Python
Let's create a script that registers with Ideone.com in Python.
Don't make test.py in Python!
Make a fortune with Python
Make Responder a daemon (service)
Make Opencv available in Python
Make python segfault in 2 lines
Let's make a number guessing game in your own language!
I tried to make a stopwatch using tkinter in python
Draw a heart in Python
Let's make a rock-paper-scissors game
I want to make input () a nice complement in python
Let's find pi in Python
Let's make a positive / negative judgment tool into a band graph (Python)
Let's make a web chat using WebSocket with AWS serverless (Python)!
Maybe in a python (original title: Maybe in Python)
Write a binary search in Python
Make python segfault in one line
[python] Manage functions in a list
Hit a command in Python (Windows)
Let's make a remote rumba [Software]
Let's run "python -m antigravity" in python
Draw a scatterplot matrix in python
ABC166 in Python A ~ C problem