Commit b6336d55 authored by Rikysamuel's avatar Rikysamuel
Browse files

Merge branch 'master' of...

Merge branch 'master' of http://gitlab.informatika.org/sinambelajunita/IF3230-Tugas-Besar-Sister-2015
parents eb1bdad6 15a13d1f
......@@ -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;
}
}
/**
......@@ -565,7 +585,7 @@ public class Database {
{
MongoCollection<Document> collection = database.getCollection("tradebox");
try {
JSONObject data = new JSONObject(collection.find(eq("_id", new ObjectId(offer_token))));
JSONObject data = new JSONObject(collection.find(eq("_id", new ObjectId(offer_token))).first().toJson());
if(isAvailable(offer_token)) //If isavailable untuk dicancel
{
......
......@@ -79,8 +79,9 @@ public class Message {
// System.out.println(move("553cd35d3c892b2c6768f77d", 4, 4));
// System.out.println(receive("{\"method\":\"field\",\"token\":\"553cd35d3c892b2c6768f77d\"}"));
// System.out.println(receive("{\"method\":\"inventory\",\"token\":\"553cd35d3c892b2c6768f77d\"}"));
System.out.println(login("ja","j"));
// System.out.println(login("ja","j"));
// System.out.println(receive("{\"method\": \"canceloffer\",\"token\": \"553cf0913c892b417db5bd82\",\"offer_token\": \"553cf11f3c892b417db5bd83\"}"));
System.out.println("cancel: " + cancelOffer("553cd35d3c892b2c6768f77d", "553cdce03c892b37e1ce2493"));
}
public static String callURL(String myURL) {
......@@ -276,6 +277,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 +804,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