Skip to content

Commit 2a9c27a

Browse files
committed
v0.3
1 parent d84d0bc commit 2a9c27a

19 files changed

+75
-50
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.osahub.thehouse.controller;
2+
3+
import java.io.IOException;
4+
import java.util.Iterator;
5+
import java.util.List;
6+
7+
import javax.servlet.http.HttpServlet;
8+
import javax.servlet.http.HttpServletRequest;
9+
import javax.servlet.http.HttpServletResponse;
10+
11+
import com.osahub.thehouse.entity.Like;
12+
13+
import static com.osahub.thehouse.dao.OfyService.ofy;
14+
15+
@SuppressWarnings("serial")
16+
public class CheckLike extends HttpServlet{
17+
public void service(HttpServletRequest req,HttpServletResponse res) throws IOException
18+
{
19+
String picID = req.getParameter("picID");
20+
String uID = req.getParameter("uID");
21+
int valid = 0;
22+
List<Like> l = ofy().load().type(Like.class).filter("picID", picID).filter("uID", uID).list();
23+
Iterator<Like> lIt = l.iterator();
24+
if(lIt.hasNext())
25+
valid=1;
26+
res.getWriter().write(valid);
27+
}
28+
}

src/com/osahub/thehouse/controller/CommentController.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ public void service(HttpServletRequest req, HttpServletResponse res)
2525
String name = (String) session.getAttribute("Name");
2626
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
2727
Date date = new Date();
28-
//Primary Key
28+
// Primary Key
2929
String id = dateFormat.format(date);
30-
//Save Comment
31-
save(picID, comm, uID, name, id + uID + picID,date);
30+
// Save Comment
31+
save(picID, comm, uID, name, id + uID, date);
3232
commentCount(picID);
3333
System.out.println("Comment Saved");
34-
//res.sendRedirect("Single.jsp?picID=" + picID);
3534
}
3635

3736
}

src/com/osahub/thehouse/controller/DeleteCommentController.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,15 @@
77
import javax.servlet.http.HttpServletResponse;
88

99
import static com.osahub.thehouse.dao.CommentsDao.delete;
10-
import static com.osahub.thehouse.dao.PictureDetailsDao.commentMinus;
1110

1211
@SuppressWarnings("serial")
1312
public class DeleteCommentController extends HttpServlet {
1413

1514
public void service(HttpServletRequest req, HttpServletResponse res)
1615
throws IOException {
17-
String picID = req.getParameter("picID");
18-
String uID = req.getParameter("uID");
19-
String comment = req.getParameter("comment");
20-
//Comment Delete
21-
delete(picID,uID,comment);
22-
commentMinus(picID);
16+
String id = req.getParameter("id");
17+
delete(id);
2318
System.out.println("Comment Deleted");
24-
res.sendRedirect("Single.jsp?picID=" + picID);
2519
}
2620

2721
}

src/com/osahub/thehouse/controller/LikeController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void service(HttpServletRequest req, HttpServletResponse res)
3232
"yyyy/MM/dd HH:mm:ss");
3333
Date date = new Date();
3434
String id = dateFormat.format(date);
35-
addLike(picID, uID, id + uID + picID);
35+
addLike(picID, uID, id + uID);
3636
} else if (likeStatus.equals("yes")) {
3737
likeMinus(picID);
3838
removeLike(picID, uID);

src/com/osahub/thehouse/controller/LoadCommentController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class LoadCommentController extends HttpServlet {
2020
public void doGet(HttpServletRequest req, HttpServletResponse res) {
2121
String picID = req.getParameter("picID");
2222
JSONArray jArray = new JSONArray();
23-
List<Comments> ls = ofy().load().type(Comments.class).filter("picID",picID).order("-date").list();
23+
List<Comments> ls = ofy().load().type(Comments.class).filter("picID",picID).filter("valid",true).order("-date").list();
2424
Iterator<Comments> it = ls.iterator();
2525
while (it.hasNext()) {
2626
Comments c = it.next();
@@ -29,6 +29,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse res) {
2929
comment.put("comment", c.getComments());
3030
comment.put("name", c.getName());
3131
comment.put("uID", c.getuID());
32+
comment.put("id",c.getId());
3233
} catch (Exception e) {
3334
e.printStackTrace();
3435
}

src/com/osahub/thehouse/dao/CommentsDao.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.util.List;
66

77
import com.osahub.thehouse.entity.Comments;
8-
8+
import static com.osahub.thehouse.dao.PictureDetailsDao.commentMinus;
99
import static com.osahub.thehouse.dao.OfyService.ofy;
1010

1111
public class CommentsDao {
@@ -18,15 +18,11 @@ public static void save(String picID, String comments, String uID,
1818
}
1919

2020
//Delete Comment
21-
public static void delete(String picID, String uID,String comment) {
22-
List<Comments> com = ofy().load().type(Comments.class).filter("comments", comment).filter("uID", uID).filter("picID",picID).list();
23-
Iterator<Comments> c = com.iterator();
24-
while(c.hasNext())
25-
{
26-
Comments cd = c.next();
27-
ofy().delete().entity(cd).now();
28-
}
29-
21+
public static void delete(String id) {
22+
Comments c = ofy().load().type(Comments.class).id(id).now();
23+
commentMinus(c.getPicID());
24+
c.setValid(false);
25+
ofy().save().entity(c).now();
3026
}
3127

3228
//Modify Name in Comment

src/com/osahub/thehouse/entity/Comments.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class Comments {
1818
String id;
1919
@Index
2020
Date date;
21+
@Index
22+
boolean valid;
2123
public Comments() {
2224
super();
2325
}
@@ -30,6 +32,13 @@ public Comments(String picID, String comments, String uID, String name,
3032
this.name = name;
3133
this.id = id;
3234
this.date = date;
35+
valid = true;
36+
}
37+
public boolean isValid() {
38+
return valid;
39+
}
40+
public void setValid(boolean valid) {
41+
this.valid = valid;
3342
}
3443
public String getPicID() {
3544
return picID;

war/Single.jsp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@
264264
var length = 2;
265265
var l;
266266
var myArr;
267+
var id;
267268
loadComment();
268269
function increaseLength()
269270
{
@@ -290,7 +291,7 @@
290291
for (i = 0; i < l; i++) {
291292
out += '<h4><b>'+arr[i].name+'</b></h4><p>'+arr[i].comment+'</p>';
292293
if(arr[i].uID=='<%=uID%>')
293-
out += '<form action="/deletecomment" method="post"> <input type="submit" value="Delete"> <input type="hidden" name="picID" value="'+'<%=picID%>'+'"> <input type="hidden" name="uID" value="'+'<%=uID%>'+'"> <input type="hidden" name="comment" value="'+arr[i].comment+'"></form><br />';
294+
out += '<button class="btn btn-default" id="'+arr[i].id+'" onClick="deleteComment(this.id)">Delete</button><br />';
294295
}
295296
if(l>0&&l<arr.length)
296297
out+='<button class="btn btn-default" onClick="increaseLength()">Show More Comments</button>';
@@ -316,8 +317,17 @@
316317
}
317318
}
318319
}
319-
function deleteComment() {
320-
320+
function deleteComment(id)
321+
{
322+
var xmlhttpDelete = new XMLHttpRequest();
323+
var url = '/deleteComment?id='+id;
324+
xmlhttpDelete.onreadystatechange = function() {
325+
if (xmlhttpDelete.readyState == 4 && xmlhttpDelete.status == 200) {
326+
loadComment();
327+
}
328+
}
329+
xmlhttpDelete.open("GET", url, true);
330+
xmlhttpDelete.send();
321331
}
322332
</script>
323333
<h3>Comments</h3>
@@ -330,7 +340,7 @@
330340
%>
331341
<h3>Leave A Comment</h3>
332342
<div class="clearfix"></div>
333-
<textarea id="commentBody" placeholder="Enter Comment" rows="2"
343+
<textarea required id="commentBody" placeholder="Enter Comment" rows="2"
334344
cols="100" name="comment" style="color: #000; background: #fff"></textarea>
335345
<button class="btn btn-default" onClick="addComment()">Submit</button>
336346
<%

war/WEB-INF/appengine-generated/datastore-indexes-auto.xml

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,32 @@
1-
<!-- Indices written at Tue, 25 Aug 2015 21:21:23 IST -->
1+
<!-- Indices written at Sat, 29 Aug 2015 11:14:08 IST -->
22

33
<datastore-indexes>
44

5-
<!-- Used 2 times in query history -->
5+
<!-- Used 4 times in query history -->
66
<datastore-index kind="PictureDetails" ancestor="false" source="auto">
77
<property name="type" direction="asc"/>
88
<property name="valid" direction="asc"/>
9-
<property name="likes" direction="desc"/>
9+
<property name="view" direction="desc"/>
1010
</datastore-index>
1111

12-
<!-- Used 2 times in query history -->
12+
<!-- Used 4 times in query history -->
1313
<datastore-index kind="PictureDetails" ancestor="false" source="auto">
1414
<property name="type" direction="asc"/>
1515
<property name="valid" direction="asc"/>
1616
<property name="date" direction="desc"/>
1717
</datastore-index>
1818

19-
<!-- Used 2 times in query history -->
19+
<!-- Used 4 times in query history -->
2020
<datastore-index kind="PictureDetails" ancestor="false" source="auto">
2121
<property name="type" direction="asc"/>
2222
<property name="valid" direction="asc"/>
23-
<property name="view" direction="desc"/>
24-
</datastore-index>
25-
26-
<!-- Used 8 times in query history -->
27-
<datastore-index kind="PictureDetails" ancestor="false" source="auto">
28-
<property name="uID" direction="asc"/>
29-
<property name="date" direction="desc"/>
30-
</datastore-index>
31-
32-
<!-- Used 4 times in query history -->
33-
<datastore-index kind="PictureDetails" ancestor="false" source="auto">
34-
<property name="claimID" direction="asc"/>
35-
<property name="claimStatus" direction="asc"/>
36-
<property name="date" direction="desc"/>
23+
<property name="likes" direction="desc"/>
3724
</datastore-index>
3825

39-
<!-- Used 1 time in query history -->
26+
<!-- Used 43 times in query history -->
4027
<datastore-index kind="Comments" ancestor="false" source="auto">
4128
<property name="picID" direction="asc"/>
29+
<property name="valid" direction="asc"/>
4230
<property name="date" direction="desc"/>
4331
</datastore-index>
4432

3.68 KB
Binary file not shown.

0 commit comments

Comments
 (0)