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

Fixing getTradebox(String usertoken, int itemIdx) dan getTradebox()

parent 749c41d2
......@@ -391,7 +391,7 @@ public class Database {
{
String oneOfferString = cursor.next().toJson();
JSONObject jsonObj = new JSONObject(oneOfferString);
if(jsonObj.getString("usertoken").equals(usertoken)
if(!jsonObj.getString("usertoken").equals(usertoken)
&& (jsonObj.getInt("offered_item") == itemIdx))
{
oneoffer = new ArrayList<>();
......@@ -416,6 +416,40 @@ public class Database {
return allOffer;
}
public static ArrayList<ArrayList<Object>> getTradebox()
{
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);
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;
}
public static ArrayList<ArrayList<Object>> getTradebox(int itemIdx)
{
MongoCollection<Document> collection = database.getCollection("tradebox");
......
......@@ -581,7 +581,7 @@ public class Message {
String response;
JSONObject jsonAllOffers;
try{
ArrayList<ArrayList<Object>> allOffers = Database.getTradebox(token);
ArrayList<ArrayList<Object>> allOffers = Database.getTradebox();
jsonAllOffers = new JSONObject();
if(allOffers != null)
{
......
......@@ -6,11 +6,7 @@
package server.helper;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
/**
*
......
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