Commit f90f2004 authored by melvinfonda's avatar melvinfonda
Browse files

benerin find offer

parent c3fbb772
......@@ -188,12 +188,11 @@ public class TCPClient {
return obj;
}
public JSONObject findOfferJSON(String token, int id_item) {
public JSONObject findOfferJSON(int id_item) {
JSONObject obj = new JSONObject();
try {
obj.put("method", "findoffer");
obj.put("token", token);
obj.put("item", id_item);
} catch(Exception e) {
e.printStackTrace();
......@@ -601,11 +600,11 @@ public class TCPClient {
return responseJSON;
}
public JSONObject findoffer(String token, int id_item) throws Exception
public JSONObject findoffer(int id_item) throws Exception
{
openConnection();
System.out.println("Find Offer");
String toSend = findOfferJSON(token, id_item).toString();
String toSend = findOfferJSON(id_item).toString();
//throw ioexception
DataOutputStream outToServer;
......@@ -803,7 +802,7 @@ public class TCPClient {
// response = client.sendFind(client.token, 2);
// System.out.println(response.toString());
response = client.accept(client.token, "a");
response = client.findoffer(6);
System.out.println(response.toString());
}
......
......@@ -405,7 +405,10 @@ public class MySQLAccess {
+ "offered_item=" + id_item + " AND available = 1;");
resultSet = preparedStatement.executeQuery();
if(resultSet.first()) {
while(resultSet.next()) {
int user_id = resultSet.getInt("id_user");
if(user_id != 0)
{
response.put("status", "ok");
JSONArray array = new JSONArray();
array.put(resultSet.getInt("offered_item"));
......@@ -415,10 +418,7 @@ public class MySQLAccess {
array.put(resultSet.getBoolean("available"));
array.put(resultSet.getString("offer_token"));
response.put("offers", array);
}
else
{
response.put("status", "error");
}
}
} catch (SQLException e) {
response.put("status", "error");
......
......@@ -323,13 +323,7 @@ public class TCPServer implements Runnable {
}
public JSONObject findoffer(JSONObject clientObject) throws JSONException {
if(clientObject.getString("token").equalsIgnoreCase(token)) {
return sql.findOffer(clientObject.getInt("item"));
} else {
JSONObject responseJSON = new JSONObject();
responseJSON.put("status", "error");
return responseJSON;
}
}
public JSONObject serverstatus(JSONObject clientObject) throws JSONException {
......
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