Commit a5aa3d35 authored by Akhmad Fakhoni Listiyan Dede's avatar Akhmad Fakhoni Listiyan Dede
Browse files

Fetch ok not tested, error cancelOffer

parent 13182a46
......@@ -552,7 +552,27 @@ public class Database {
public static boolean fetchItem(String token, String offer_token)
{
return true;
try {
//Get offer from tradebox
MongoCollection<Document> tbCollection = database.getCollection(offer_token);
JSONObject tbObj = new JSONObject(tbCollection.find(eq("_id",new ObjectId(offer_token))).first().toJson());
int demanded_item = tbObj.getInt("demanded_item");
int n2 = tbObj.getInt("n2");
//Get user inv
ArrayList<Integer> inv = getInventory(token);
inv.set(demanded_item, inv.get(demanded_item) + n2);
//Update inventory
updateInventory(token, inv);
//Delete tradebox
tbCollection.deleteOne(eq("_id", new ObjectId(token)));
return true;
} catch (JSONException ex) {
return false;
}
}
/**
......
......@@ -276,6 +276,7 @@ public class Message {
jObj.put("x", position.getInt("x"));
jObj.put("y", position.getInt("y"));
jObj.put("time", Database.getTime(0,0,0,0));
Store.generateMap(person.token);
response = jObj.toString();
}
else
......@@ -802,8 +803,13 @@ public class Message {
public static String fetchItem(String token, String offer_token) //15
{
return "";
JSONObject jObj = new JSONObject();
if(Database.fetchItem(token, offer_token))
return statusOKOnly();
else
{
return fail("Cannot fetch item");
}
}
public static String cancelOffer(String token, String offer_token)
......
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