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 {
|
body:json {
|
||||||
{"name":"Card holder wallet"}
|
{
|
||||||
|
"sku":"TEST-001",
|
||||||
|
"name":"Card holder wallet"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,5 +11,5 @@ post {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body:json {
|
body:json {
|
||||||
{"id":2}
|
{"sku":"TEST-001"}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ post {
|
|||||||
|
|
||||||
body:json {
|
body:json {
|
||||||
{
|
{
|
||||||
"id":3,
|
"sku":"TEST-001",
|
||||||
"name":"Card holder"
|
"name":"Card holder"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,5 @@ post {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body:json {
|
body:json {
|
||||||
{
|
{"sku":"TEST-001"}
|
||||||
"id":3
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,16 +20,16 @@ class item:
|
|||||||
c1 = 0
|
c1 = 0
|
||||||
for d1 in l1:
|
for d1 in l1:
|
||||||
ls.append({
|
ls.append({
|
||||||
"id" :d1["id" ],
|
"sku" :d1["sku" ],
|
||||||
"name" :d1["name" ],
|
"name" :d1["name" ],
|
||||||
"price" :{
|
"price" :{
|
||||||
"buy":[],
|
"buy":[],
|
||||||
"sell":[]
|
"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()
|
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()
|
ls[c1]["price"]["sell"] = self.cursor.fetchall()
|
||||||
c1+=1
|
c1+=1
|
||||||
loggorilla.prcss(APIADDR, "Giving response")
|
loggorilla.prcss(APIADDR, "Giving response")
|
||||||
@ -52,22 +52,22 @@ class item:
|
|||||||
APIADDR = "/api/invlab/item/detail"
|
APIADDR = "/api/invlab/item/detail"
|
||||||
response = {}
|
response = {}
|
||||||
loggorilla.prcss(APIADDR, "Define parameters")
|
loggorilla.prcss(APIADDR, "Define parameters")
|
||||||
id = params["id"]
|
sku = params["sku"]
|
||||||
self.cursor.execute("BEGIN;")
|
self.cursor.execute("BEGIN;")
|
||||||
try:
|
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()
|
r = self.cursor.fetchone()
|
||||||
data = {
|
data = {
|
||||||
"id" :r["id" ],
|
"sku" :r["sku" ],
|
||||||
"name" :r["name" ],
|
"name" :r["name" ],
|
||||||
"price" :{
|
"price" :{
|
||||||
"buy":[],
|
"buy":[],
|
||||||
"sell":[]
|
"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()
|
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()
|
data["price"]["sell"] = self.cursor.fetchall()
|
||||||
loggorilla.prcss(APIADDR, "Giving response")
|
loggorilla.prcss(APIADDR, "Giving response")
|
||||||
response["status" ] = "success"
|
response["status" ] = "success"
|
||||||
@ -89,11 +89,12 @@ class item:
|
|||||||
APIADDR = "/api/invlab/item/add"
|
APIADDR = "/api/invlab/item/add"
|
||||||
response = {}
|
response = {}
|
||||||
loggorilla.prcss(APIADDR, "Define parameters")
|
loggorilla.prcss(APIADDR, "Define parameters")
|
||||||
name = params["name" ]
|
sku = params["sku" ]
|
||||||
|
name = params["name" ]
|
||||||
self.cursor.execute("BEGIN;")
|
self.cursor.execute("BEGIN;")
|
||||||
try:
|
try:
|
||||||
loggorilla.prcss(APIADDR, "Inserting")
|
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")
|
loggorilla.prcss(APIADDR, "Giving response")
|
||||||
response["status" ] = "success"
|
response["status" ] = "success"
|
||||||
response["desc" ] = "data added"
|
response["desc" ] = "data added"
|
||||||
@ -102,7 +103,7 @@ class item:
|
|||||||
loggorilla.error(APIADDR, str(e) )
|
loggorilla.error(APIADDR, str(e) )
|
||||||
loggorilla.prcss(APIADDR, "Giving response")
|
loggorilla.prcss(APIADDR, "Giving response")
|
||||||
response["status" ] = "failed"
|
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:
|
finally:
|
||||||
self.cursor.execute("COMMIT;")
|
self.cursor.execute("COMMIT;")
|
||||||
self.cursor.close()
|
self.cursor.close()
|
||||||
@ -113,12 +114,12 @@ class item:
|
|||||||
APIADDR = "/api/invlab/item/edit"
|
APIADDR = "/api/invlab/item/edit"
|
||||||
response = {}
|
response = {}
|
||||||
loggorilla.prcss(APIADDR, "Define parameters")
|
loggorilla.prcss(APIADDR, "Define parameters")
|
||||||
key = params["id" ]
|
key = params["sku" ]
|
||||||
name = params["name" ]
|
name = params["name" ]
|
||||||
self.cursor.execute("BEGIN;")
|
self.cursor.execute("BEGIN;")
|
||||||
try:
|
try:
|
||||||
loggorilla.prcss(APIADDR, "Updating")
|
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")
|
loggorilla.prcss(APIADDR, "Giving response")
|
||||||
response["status" ] = "success"
|
response["status" ] = "success"
|
||||||
response["desc" ] = "data change"
|
response["desc" ] = "data change"
|
||||||
@ -138,11 +139,11 @@ class item:
|
|||||||
APIADDR = "/api/invlab/item/remove"
|
APIADDR = "/api/invlab/item/remove"
|
||||||
response = {}
|
response = {}
|
||||||
loggorilla.prcss(APIADDR, "Define parameters")
|
loggorilla.prcss(APIADDR, "Define parameters")
|
||||||
key = params["id" ]
|
key = params["sku" ]
|
||||||
self.cursor.execute("BEGIN;")
|
self.cursor.execute("BEGIN;")
|
||||||
try:
|
try:
|
||||||
loggorilla.prcss(APIADDR, "Deleting")
|
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")
|
loggorilla.prcss(APIADDR, "Giving response")
|
||||||
response["status" ] = "success"
|
response["status" ] = "success"
|
||||||
response["desc" ] = "data removed"
|
response["desc" ] = "data removed"
|
||||||
|
Loading…
Reference in New Issue
Block a user