diff --git a/soap/src/main/java/com/sayit/service/TimelineImpl.java b/soap/src/main/java/com/sayit/service/TimelineImpl.java index ca00c4967d2b960eac136a8b01b47bf5b17df8d2..3f903e5330a10961af451cf3d5977773b55d7971 100644 --- a/soap/src/main/java/com/sayit/service/TimelineImpl.java +++ b/soap/src/main/java/com/sayit/service/TimelineImpl.java @@ -13,11 +13,12 @@ import java.util.Arrays; import static java.sql.Types.NULL; @WebService -public class TimelineImpl implements Timeline{ +public class TimelineImpl extends Services implements Timeline{ @Override - public String likePost( - int user_id, - int timeline_id) { + public String likePost(int user_id, int timeline_id) { + if (!validateKey()) { + return "invalid key"; + } Database db = new Database(); Connection conn = db.getConnection(); try { @@ -32,11 +33,14 @@ public class TimelineImpl implements Timeline{ stmt.executeUpdate(query2); String query3 = "INSERT INTO post_liked (post_by, timeline_id, liked_by) VALUES (" + user_post + ", " + timeline_id + ", " + user_id + ")"; stmt.executeUpdate(query3); + log ("User " + user_id + " liked post " + timeline_id); return "liked"; } else { + log ("User " + user_id + " failed to like post " + timeline_id); return "post doesn't exist"; } } catch (Exception e) { + log ("User " + user_id + " failed to like post " + timeline_id); return "failed"; } finally { db.closeConnection(); @@ -44,9 +48,10 @@ public class TimelineImpl implements Timeline{ } @Override - public String unlikePost( - int user_id, - int timeline_id) { + public String unlikePost(int user_id, int timeline_id) { + if (!validateKey()) { + return "invalid key"; + } Database db = new Database(); Connection conn = db.getConnection(); try { @@ -60,11 +65,14 @@ public class TimelineImpl implements Timeline{ stmt.executeUpdate(query2); String query3 = "DELETE FROM post_liked WHERE timeline_id = " + timeline_id + " AND liked_by = " + user_id; stmt.executeUpdate(query3); + log ("User " + user_id + " unliked post " + timeline_id); return "unliked"; } else { + log ("User " + user_id + " failed to unlike post " + timeline_id); return "post doesn't exist"; } } catch (Exception e) { + log ("User " + user_id + " failed to unlike post " + timeline_id); return "failed"; } finally { db.closeConnection(); @@ -73,6 +81,9 @@ public class TimelineImpl implements Timeline{ @Override public String getLikedPost(int user_id) { + if (!validateKey()) { + return "invalid key"; + } Database db = new Database(); Connection conn = db.getConnection(); try { @@ -84,12 +95,15 @@ public class TimelineImpl implements Timeline{ while (result.next()) { liked_post.add(result.getString("timeline_id")); } + log ("User " + user_id + " get liked post"); return liked_post.toString(); } else { + log ("User " + user_id + " failed to get liked post"); return "no liked post"; } } catch (Exception e) { + log ("User " + user_id + " failed to get liked post"); return "failed"; } finally { db.closeConnection();