Commit c3fbb772 authored by melvinfonda's avatar melvinfonda
Browse files

accept fixed

parent 1ce989a2
compile.on.save=true
user.properties.file=C:\\Users\\Stephen\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
\ No newline at end of file
user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\8.0\\build.properties
......@@ -800,7 +800,10 @@ public class TCPClient {
response = client.offer(client.token, 0, 1, 7, 3);
System.out.println(response.toString());
response = client.sendFind(client.token, 2);
// response = client.sendFind(client.token, 2);
// System.out.println(response.toString());
response = client.accept(client.token, "a");
System.out.println(response.toString());
}
......
compile.on.save=true
user.properties.file=C:\\Users\\Stephen\\AppData\\Roaming\\NetBeans\\8.0.2\\build.properties
user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\8.0\\build.properties
......@@ -429,7 +429,7 @@ public class MySQLAccess {
return response;
}
public JSONObject accept(int userID, String offer_token) throws JSONException
public JSONObject sendAccept(int userID, String offer_token) throws JSONException
{
open();
JSONObject response = new JSONObject();
......@@ -522,6 +522,43 @@ public class MySQLAccess {
return response;
}
public JSONObject accept(int userID, String offer_token) throws JSONException
{
open();
JSONObject response = new JSONObject();
try {
//cek offer dengan offer token yang sesuai
preparedStatement = connect.prepareStatement("SELECT * FROM offer WHERE "
+ "offer_token=\"" + offer_token + "\";");
resultSet = preparedStatement.executeQuery();
if(resultSet.first()) {
boolean available = resultSet.getBoolean("available");
//cek apakah offer tersedia
if(available)
{
preparedStatement = connect.prepareStatement("UPDATE offer SET available = 0" + " WHERE "
+ "offer_token=\"" + offer_token + "\";");
preparedStatement.executeUpdate();
response.put("status", "ok");
}
else //offer tidak tersedia
{
response.put("status", "fail");
response.put("description", "offer is not available");
}
}
}
catch (SQLException e) {
response.put("status", "error");
e.printStackTrace();
}
close();
return response;
}
public JSONObject fetchitem(int userID, String offer_token) throws JSONException
{
open();
......
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