Update item class to use sku as primary key of item
This commit is contained in:
parent
4f2f612c94
commit
0121f3fcd0
@ -11,5 +11,8 @@ post {
|
||||
}
|
||||
|
||||
body:json {
|
||||
{"name":"Card holder wallet"}
|
||||
{
|
||||
"sku":"TEST-001",
|
||||
"name":"Card holder wallet"
|
||||
}
|
||||
}
|
||||
|
@ -11,5 +11,5 @@ post {
|
||||
}
|
||||
|
||||
body:json {
|
||||
{"id":2}
|
||||
{"sku":"TEST-001"}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ post {
|
||||
|
||||
body:json {
|
||||
{
|
||||
"id":3,
|
||||
"sku":"TEST-001",
|
||||
"name":"Card holder"
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,5 @@ post {
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"id":3
|
||||
}
|
||||
{"sku":"TEST-001"}
|
||||
}
|
||||
|
@ -20,16 +20,16 @@ class item:
|
||||
c1 = 0
|
||||
for d1 in l1:
|
||||
ls.append({
|
||||
"id" :d1["id" ],
|
||||
"sku" :d1["sku" ],
|
||||
"name" :d1["name" ],
|
||||
"price" :{
|
||||
"buy":[],
|
||||
"sell":[]
|
||||
}
|
||||
})
|
||||
self.cursor.execute("SELECT `id`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` from item_price WHERE `item` = %s AND `type`='buy' ORDER BY periods DESC, id DESC; ", ( d1["id"], ) )
|
||||
self.cursor.execute("SELECT `id`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` from item_price WHERE `sku` = %s AND `type`='buy' ORDER BY periods DESC, id DESC; ", ( d1["sku"], ) )
|
||||
ls[c1]["price"]["buy" ] = self.cursor.fetchall()
|
||||
self.cursor.execute("SELECT `id`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` from item_price WHERE `item` = %s AND `type`='sell' ORDER BY periods DESC, id DESC; ", ( d1["id"], ) )
|
||||
self.cursor.execute("SELECT `id`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` from item_price WHERE `sku` = %s AND `type`='sell' ORDER BY periods DESC, id DESC; ", ( d1["sku"], ) )
|
||||
ls[c1]["price"]["sell"] = self.cursor.fetchall()
|
||||
c1+=1
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
@ -52,22 +52,22 @@ class item:
|
||||
APIADDR = "/api/invlab/item/detail"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
id = params["id"]
|
||||
sku = params["sku"]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
self.cursor.execute("SELECT * FROM `item` WHERE `id`= %s ;", ( id, ) )
|
||||
self.cursor.execute("SELECT * FROM `item` WHERE `sku` = %s ;", ( sku, ) )
|
||||
r = self.cursor.fetchone()
|
||||
data = {
|
||||
"id" :r["id" ],
|
||||
"sku" :r["sku" ],
|
||||
"name" :r["name" ],
|
||||
"price" :{
|
||||
"buy":[],
|
||||
"sell":[]
|
||||
}
|
||||
}
|
||||
self.cursor.execute("SELECT `id`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` from item_price WHERE `item` = %s AND `type`='buy' ORDER BY periods DESC, id DESC; ", ( r["id"], ) )
|
||||
self.cursor.execute("SELECT `id`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` from item_price WHERE `sku` = %s AND `type`='buy' ORDER BY periods DESC, id DESC; ", ( sku, ) )
|
||||
data["price"]["buy" ] = self.cursor.fetchall()
|
||||
self.cursor.execute("SELECT `id`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` from item_price WHERE `item` = %s AND `type`='sell' ORDER BY periods DESC, id DESC; ", ( r["id"], ) )
|
||||
self.cursor.execute("SELECT `id`, `currency`, `value`, DATE_FORMAT(`periods`, '%Y-%m-%d %H:%i:%S') AS `periods` from item_price WHERE `sku` = %s AND `type`='sell' ORDER BY periods DESC, id DESC; ", ( sku, ) )
|
||||
data["price"]["sell"] = self.cursor.fetchall()
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
@ -89,11 +89,12 @@ class item:
|
||||
APIADDR = "/api/invlab/item/add"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
name = params["name" ]
|
||||
sku = params["sku" ]
|
||||
name = params["name" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Inserting")
|
||||
self.cursor.execute("INSERT INTO `item` VALUES (DEFAULT, %s) ;", (name,) )
|
||||
self.cursor.execute("INSERT INTO `item` VALUES (%s, %s) ;", (sku, name) )
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data added"
|
||||
@ -102,7 +103,7 @@ class item:
|
||||
loggorilla.error(APIADDR, str(e) )
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "failed"
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
|
||||
finally:
|
||||
self.cursor.execute("COMMIT;")
|
||||
self.cursor.close()
|
||||
@ -113,12 +114,12 @@ class item:
|
||||
APIADDR = "/api/invlab/item/edit"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
key = params["id" ]
|
||||
name = params["name" ]
|
||||
key = params["sku" ]
|
||||
name = params["name" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Updating")
|
||||
self.cursor.execute("UPDATE `item` SET `name` = %s WHERE `id` = %s ;", (name, key) )
|
||||
self.cursor.execute("UPDATE `item` SET `name` = %s WHERE `sku` = %s ;", (name, key) )
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data change"
|
||||
@ -138,11 +139,11 @@ class item:
|
||||
APIADDR = "/api/invlab/item/remove"
|
||||
response = {}
|
||||
loggorilla.prcss(APIADDR, "Define parameters")
|
||||
key = params["id" ]
|
||||
key = params["sku" ]
|
||||
self.cursor.execute("BEGIN;")
|
||||
try:
|
||||
loggorilla.prcss(APIADDR, "Deleting")
|
||||
self.cursor.execute("DELETE FROM `item` WHERE `id` = %s ;", (key,) )
|
||||
self.cursor.execute("DELETE FROM `item` WHERE `sku` = %s ;", (key,) )
|
||||
loggorilla.prcss(APIADDR, "Giving response")
|
||||
response["status" ] = "success"
|
||||
response["desc" ] = "data removed"
|
||||
|
Loading…
Reference in New Issue
Block a user