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

sendFind from client with specific itemId ok

parent 47ff722d
......@@ -376,6 +376,45 @@ public class Database {
}
return allOffer;
}
public static ArrayList<ArrayList<Object>> getTradebox(String usertoken, int itemIdx)
{
MongoCollection<Document> collection = database.getCollection("tradebox");
MongoCursor<Document> cursor = collection.find().iterator();
ArrayList<ArrayList<Object>> allOffer;
ArrayList<Object> oneoffer;
try{
allOffer = new ArrayList<>();
while(cursor.hasNext())
{
String oneOfferString = cursor.next().toJson();
JSONObject jsonObj = new JSONObject(oneOfferString);
if(jsonObj.getString("usertoken").equals(usertoken)
&& (jsonObj.getInt("offered_item") == itemIdx))
{
oneoffer = new ArrayList<>();
oneoffer.add(jsonObj.getInt("offered_item"));
oneoffer.add(jsonObj.getInt("n1"));
oneoffer.add(jsonObj.getInt("demanded_item"));
oneoffer.add(jsonObj.getInt("n2"));
oneoffer.add(jsonObj.getBoolean("availability"));
oneoffer.add(getJsonObjId(jsonObj.toString()));
allOffer.add(oneoffer);
}
}
if(allOffer.isEmpty())
return null;
} catch (JSONException | NullPointerException ex) {
return null;
}
finally
{
cursor.close();
}
return allOffer;
}
/**
* Mengembalikan token, username, dan password dari username yang dimasukkan
* @param username
......
......@@ -25,7 +25,7 @@ import org.json.JSONObject;
*/
public class Message {
private static boolean log = false;
private static boolean log = true;
/* Main buat testing json. Jangan dihapus dulu ya? */
public static void main(String[] args) throws JSONException {
// try {
......@@ -68,7 +68,8 @@ public class Message {
// System.out.println(move("553b17283c892b1a8d00961f", 2, 5));
// System.out.println(getTradeBox("553b64d23c892b2d5b772c74"));
getTradeBox("553b64d23c892b2d5b772c74");
sendFine("553b64d23c892b2d5b772c74", 4);
}
public static String callURL(String myURL) {
......@@ -559,7 +560,6 @@ public class Message {
public static String getTradeBox(String token) //10
{
JSONObject jsonObj;
String response;
JSONObject jsonAllOffers;
try{
......@@ -586,6 +586,35 @@ public class Message {
return response;
}
public static String sendFine(String token, int itemId) //11
{
String response;
JSONObject jsonAllOffers;
try{
ArrayList<ArrayList<Object>> allOffers = Database.getTradebox(token,itemId);
jsonAllOffers = new JSONObject();
if(allOffers != null)
{
jsonAllOffers.put("status", "ok");
jsonAllOffers.put("offers", allOffers);
response = jsonAllOffers.toString();
}
else
{
response = error();
}
}
catch(JSONException ex)
{
response = error();
}
if(log)
System.out.println(response);
return response;
}
//offer
//tradebox
//sendfind
......
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