Commit 8da36854 authored by mamat-rahmat's avatar mamat-rahmat
Browse files

fix wring naming offeredVSoffer

parent 559c0b6d
......@@ -238,7 +238,7 @@ def handler(a, c):
# buat json object dari string kriteria update dan remove
kriteria2Object = {"token" : token}
# nama dan jumlah demand item yang baru setelah fetchitem
name_demand = getItemName(offer["demand_item"])
name_demand = getItemName(offer["demanded_item"])
n_demand_old = database.inventoriCollection.find_one(kriteria2Object)
n_demand = offer["n_item2"] + n_demand_old[name_demand]
# buat json object dari string kriteria update dan remove
......@@ -310,9 +310,9 @@ def handler(a, c):
elif (method == "offer"):
token = dataJSON["token"]
offer_item = dataJSON["offer_item"]
offered_item = dataJSON["offered_item"]
n_item1 = dataJSON["n1"]
demand_item = dataJSON["demand_item"]
demanded_item = dataJSON["demanded_item"]
n_item2 = dataJSON["n2"]
kriteria1Object = {"token" : token}
......@@ -320,17 +320,17 @@ def handler(a, c):
player = database.playerCollection.find_one(kriteria1Object)
inventory = database.inventoriCollection.find_one(kriteria1Object)
n_item1_inventory = inventory[getItemName(offer_item)]
n_item1_inventory = inventory[getItemName(offered_item)]
if (n_item1_inventory >= n_item1):
objectOfferToken = hashlib.md5(str.encode(str(player['username']) + str(player['player_time'])))
offered_token = objectOfferToken.hexdigest();
offer_token = objectOfferToken.hexdigest();
#kurangi offer item di inventori
kriteria2Object = {"token" : token}
kriteria3Object = {"$set" : {getItemName(offer_item) : n_item1_inventory - n_item1}}
kriteria3Object = {"$set" : {getItemName(offered_item) : n_item1_inventory - n_item1}}
database.inventoriCollection.update(kriteria2Object,kriteria3Object)
kriteria2Object = {'offer_item' : offer_item, 'n_item1' : n_item1, 'demand_item' : demand_item, 'n_item2' : n_item2, 'availability' : 'true', 'offered_token' : offered_token, 'user_token' : token}
kriteria2Object = {'offered_item' : offered_item, 'n_item1' : n_item1, 'demanded_item' : demanded_item, 'n_item2' : n_item2, 'availability' : 'true', 'offer_token' : offer_token, 'user_token' : token}
database.offerCollection.insert(kriteria2Object)
response = '{"status" : "ok"}'
else:
......@@ -345,12 +345,12 @@ def handler(a, c):
offer_self = []
for temp in database.offerCollection.find(kriteria1Object):
data = []
data.append( temp["offer_item"] )
data.append( temp["offered_item"] )
data.append( temp["n_item1"] )
data.append( temp["demand_item"] )
data.append( temp["demanded_item"] )
data.append( temp["n_item2"] )
data.append( temp["availability"] )
data.append( temp["offered_token"] )
data.append( temp["offer_token"] )
offer_self.append(data)
dictResponse = { "status" : "ok", "offers" : offer_self }
......@@ -359,17 +359,17 @@ def handler(a, c):
elif (method == 'sendfind'):
token = dataJSON['token']
item = dataJSON['item']
kriteria1Object = {"offer_item" : item}
kriteria1Object = {"offered_item" : item}
offer_all = []
for temp in database.marketCollection.find(kriteria1Object):
data = []
data.append( temp["offer_item"] )
data.append( temp["offered_item"] )
data.append( temp["n_item1"] )
data.append( temp["demand_item"] )
data.append( temp["demanded_item"] )
data.append( temp["n_item2"] )
data.append( temp["availability"] )
data.append( temp["offered_token"] )
data.append( temp["offer_token"] )
offer_self.append(data)
dictResponse = { "status" : "ok", "offers" : offer_self }
......@@ -379,17 +379,17 @@ def handler(a, c):
# TODO : AMBIL DARI SEMUA SERVER
item = dataJSON['item']
kriteria1Object = {"offer_item" : item}
kriteria1Object = {"offered_item" : item}
offer_all = []
for temp in offerCollection.find(kriteria1Object):
data = []
data.append( temp["offer_item"] )
data.append( temp["offered_item"] )
data.append( temp["n_item1"] )
data.append( temp["demand_item"] )
data.append( temp["demanded_item"] )
data.append( temp["n_item2"] )
data.append( temp["availability"] )
data.append( temp["offered_token"] )
data.append( temp["offer_token"] )
offer_self.append(data)
dictResponse = { "status" : "ok", "offers" : offer_self }
......@@ -397,8 +397,8 @@ def handler(a, c):
elif (method == 'canceloffer'):
token = dataJSON['token']
offered_token = dataJSON['offered_token']
kriteria1Object = {"offered_token" : offered_token}
offer_token = dataJSON['offer_token']
kriteria1Object = {"offer_token" : offer_token}
if (database.offerCollection.find(kriteria1Object).count() != 0):
offer = database.offerCollection.find_one(kriteria1Object)
if (offer['availability'] == 0): # already finished
......@@ -407,7 +407,7 @@ def handler(a, c):
# buat json object dari string kriteria update dan remove
kriteria2Object = {"token":token}
# nama dan jumlah offer item setelah canceloffer
name_offer = getItemName(offer['offer_item'])
name_offer = getItemName(offer['offered_item'])
n_offer_old = database.inventoriCollection.find_one(kriteria2Object)
n_offer = offer['n_item1'] + n_offer_old[name_offer]
# buat json object dari string kriteria update dan remove
......@@ -426,13 +426,13 @@ def handler(a, c):
# TODO : KIRIM PESAN ACCEPT KE SERVER LAIN
token = dataJSON['token']
offered_token = dataJSON['offered_token']
kriteria1Object = {"offered_token": offered_token}
offer_token = dataJSON['offer_token']
kriteria1Object = {"offer_token": offer_token}
if (database.marketCollection.find(kriteria1Object).count() != 0):
# Dapat jumlah item yang dioffer beserta nama itemnya
offer = database.marketCollection.find_one(kriteria1Object)
n_offer = offer['n_item1']
name_offer = getItemName(offer['offer_item'])
name_offer = getItemName(offer['offered_item'])
# Tambahkan jumlah item offer yang diterima dengan item lama
kriteria2Object = {"token" : token}
inventoriLama = database.inventoriCollection.find_one(kriteria2Object)
......@@ -444,12 +444,12 @@ def handler(a, c):
response = "{'status' : 'ok'}"
else:
kriteria2Object = {"offered_token" : offered_token}
kriteria2Object = {"offer_token" : offer_token}
response = "{'status' : 'fail', 'description' : 'not exists'}"
elif (method == 'accept'):
offered_token = dataJSON['offered_token']
kriteria1Object = {"offered_token" : offered_token,"availability" : "false"}
offer_token = dataJSON['offer_token']
kriteria1Object = {"offer_token" : offer_token,"availability" : "false"}
if (database.marketCollection.find(kriteria1Object).count() != 0):
response = "{'status':'ok'}"
else:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment