Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Snir001/ShareIT
Browse files Browse the repository at this point in the history
i changed search to smartSearch in /ResultsServlet.java
  • Loading branch information
IdanShp committed Apr 19, 2020
2 parents b4e0f0b + 87fb317 commit 63c1770
Show file tree
Hide file tree
Showing 24 changed files with 677 additions and 140 deletions.
57 changes: 57 additions & 0 deletions WebContent/content/AllItems.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
this is list of ${name} Offers
<%@page import="model.Users"%>
<%@page import="model.Requests"%>
<%@page import="java.util.*"%>

<div class="w3-container">
<h2>Users:</h2>

<table class="w3-table w3-striped">
<tr>
<th>Item ID</th>
<th>Item Name</th>
<th>Item Owner</th>
<th>Category</th>
<th>Value</th>
<th>Condition</th>
<th>Picture</th>
<th>Delete</th>



</tr>

<%
model.Model mod = (model.Model)getServletContext().getAttribute("model");
List<model.Items> items=(List<model.Items>)request.getAttribute("items");
String status;
model.Items item;
for(int i=0;i<items.size();i++) {
item=items.get(i);
/*
<th>Item ID</th>
<th>Item Name</th>
<th>Item Owner</th>
<th>Category</th>
<th>Value</th>
<th>Condition</th>
<th>Picture</th>
<th>Delete</th>
http://localhost:8080/ShareIT/ProfilePageServlet?user_name=Idan_Sh
*/
out.println("<tr>");
out.println("<td>"+item.getItemID()+"</td>");
out.println("<td>"+item.getName()+"</td>");
out.println("<td><a href='ProfilePageServlet?user_name="+mod.getUserByID(item.getOwnerID()).getUserName()+"'>"+mod.getUserByID(item.getOwnerID()).getUserName()+"</a></td>");
out.println("<td>"+item.getCategory()+"</td>");
out.println("<td>"+item.getItemValue()+"</td>");
out.println("<td>"+item.getCondition()+"</td>");
out.println("<td>"+item.getPicture()+"</td>");
out.println("<td><a href='RemoveItemServlet?item_id="+item.getItemID()+"'>X</a></td>");
out.println("</tr>");
}
%>
</table>
</div>

67 changes: 67 additions & 0 deletions WebContent/content/AllUsers.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
this is list of ${name} Offers
<%@page import="model.Users"%>
<%@page import="model.Requests"%>
<%@page import="java.util.*"%>

<div class="w3-container">
<h2>Users:</h2>

<table class="w3-table w3-striped">
<tr>
<th>User ID</th>
<th>User Name</th>
<th>Last Name</th>
<th>First Name</th>
<th>Mail</th>
<th>City</th>
<th>Address</th>
<th>Phone</th>
<th>Gender</th>
<th>privleges</th>
<th>Make Admin</th>

<th>Delete</th>



</tr>

<%
List<model.Users> users=(List<model.Users>)request.getAttribute("users");
String status;
Users u;
for(int i=0;i<users.size();i++) {
u=users.get(i);
/*
<th>User ID</th>
<th>User Name</th>
<th>Last Name</th>
<th>First Name</th>
<th>Mail</th>
<th>City</th>
<th>Address</th>
<th>Phone</th>
<th>Gender</th>
<th>privleges</th>
http://localhost:8080/ShareIT/ProfilePageServlet?user_name=Idan_Sh
*/
out.println("<tr>");
out.println("<td>"+u.getUserID()+"</td>");
out.println("<td><a href='ProfilePageServlet?user_name="+u.getUserName()+"'>"+u.getUserName()+"</a></td>");
out.println("<td>"+u.getLastName()+"</td>");
out.println("<td>"+u.getFirstName()+"</td>");
out.println("<td>"+u.getMail()+"</td>");
out.println("<td>"+u.getCity()+"</td>");
out.println("<td>"+u.getAddress()+"</td>");
out.println("<td>"+u.getPhone()+"</td>");
out.println("<td>"+u.getGender()+"</td>");
out.println("<td>"+u.getPrivileges()+"</td>");
out.println("<td><a href='MakeAdminServlet?user_id="+u.getUserID()+"'>A</a></td>");
out.println("<td><a href='RemoveUserServlet?user_id="+u.getUserID()+"'>X</a></td>");
out.println("</tr>");
}
%>
</table>
</div>

2 changes: 0 additions & 2 deletions WebContent/content/Explore.jsp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<%@page import="java.util.List"%>

<a href="ProfileServlet"> users only!</a>
<a href="ExploreServlet"> Explore Page </a>
<!-- Items -->
<h3 class="w3-margin">New Items!</h3>
<%
Expand Down
7 changes: 5 additions & 2 deletions WebContent/content/ItemDetails.jsp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<%@page import="model.Items"%>
<%
model.Model mod = (model.Model)getServletContext().getAttribute("model");
Items item=(Items)request.getAttribute("item");
out.print("Item ID: "+item.getItemID()+"<br>");
out.print("Item Name: "+item.getName()+"<br>");
out.print("Item Owner: "+item.getOwnerID()+"<br>");
out.print("Item Owner: <a href='ProfilePageServlet?user_name="+mod.getUserByID(item.getOwnerID()).getUserName()+"'>"+mod.getUserByID(item.getOwnerID()).getUserName()+"</a><br>"
);
out.print("Item Value: "+item.getItemValue()+"<br>");
out.print("Item Condition: "+item.getCondition()+"<br>");
out.print("Item Category: "+item.getCategory()+"<br>");
Expand All @@ -19,5 +22,5 @@ if(item.getPicture().equals("1")) {
out.print("<img src='" + pictureUrl + "' class='w3-round w3-padding-16' height='150' width='150'>");
out.print("<a href='ReqestItemServlet?id="+item.getItemID()+"'>Request Item</a>");
//TODO: add option to delete for the owner
%>
12 changes: 12 additions & 0 deletions WebContent/content/ProfilePage.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%@page import="model.Users"%>
<%model.Users u=(model.Users)request.getAttribute("show_user"); %>
User Name: <%out.print(u.getUserName()); %> <br>
First Name:<%out.print(u.getFirstName()); %> <br>
Last Name:<%out.print(u.getLastName()); %> <br>
Email:<%out.print(u.getMail()); %> <br>
City:<%out.print(u.getCity()); %> <br>
Address:<%out.print(u.getAddress()); %> <br>
Phone:<%out.print(u.getPhone()); %> <br>
Gender:<%out.print(u.getGender()); %> <br>


11 changes: 6 additions & 5 deletions WebContent/jsp/bodyHeader.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@
-->
<a href="AddItemServlet" class="w3-bar-item w3-button">Add Item</a>
<a href="MyItemsServlet" class="w3-bar-item w3-button">My Items</a>
<a href="RequestsServlet" class="w3-bar-item w3-button">Requests</a>
<a href="RequestsServlet" class="w3-bar-item w3-button">Requests</a>
<a href="OffersServlet" class="w3-bar-item w3-button">Offers</a>
<%
if (session.getAttribute("privilege") != null) {
model.Users u=(model.Users)session.getAttribute("user");
if (u!= null&&u.getPrivileges().equals("0")) {
//TODO OPTION:make this text different color
out.print("<a href=\"SearchHistoryServlet\" class=\"w3-bar-item w3-button\">Serach History</a>");
out.print("<a href=\"UsersListServlet\" class=\"w3-bar-item w3-button\">Users List</a>");
out.print("<a href=\"AllItemsServlet\" class=\"w3-bar-item w3-button\">All Items List</a>");
//out.print("<a href=\"SearchHistoryServlet\" class=\"w3-bar-item w3-button\">Serach History</a>");
out.print("<a href=\"ShowAllUsersListServlet\" class=\"w3-bar-item w3-button\">Users List</a>");
out.print("<a href=\"ShowAllItemsListServlet\" class=\"w3-bar-item w3-button\">All Items List</a>");
}
%>

Expand Down
17 changes: 5 additions & 12 deletions src/controller/AddItemHandlerServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,12 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
response.setContentType("text/html");
PrintWriter out=response.getWriter();


model.Model mod = (model.Model)getServletContext().getAttribute("model");
HttpSession session=request.getSession(false);
if(session==null){
request.setAttribute("page","content/LoginFirst.jsp");
}
else
{
request.setAttribute("page","content/LoginFirst.jsp");
if(session!=null) {
model.Users user=(model.Users)session.getAttribute("user");
if(user==null) {
request.setAttribute("page","content/LoginFirst.jsp");
} else {
if(user!=null){
String ItemName=request.getParameter("name");
String ItemCategory=request.getParameter("category");
String ItemValue=request.getParameter("value");
Expand All @@ -103,7 +97,6 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)


if(picture.equals("1")) {
System.out.println("we have file");
String fileName = getSubmittedFileName(filePart); // MSIE fix.
InputStream fileContent = filePart.getInputStream();

Expand All @@ -112,7 +105,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
//create new folder:
// C:\\Users\\SnirY\\OneDrive\\Documents\\Bar Ilan\\sems5\\Software eng\\ShareIT\\WebContent\\ItemPictures\\
String upload_path=getServletContext().getInitParameter("upload_location")+ItemID;
System.out.println("upload_path is : " + upload_path);
// System.out.println("upload_path is : " + upload_path);

new File(upload_path).mkdir();
File uploads = new File(upload_path);
Expand All @@ -125,7 +118,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
}

//show list of pictures
System.out.println("file path at : " +file.getPath() );
// System.out.println("file path at : " +file.getPath() );
}

StringBuffer msg=new StringBuffer("<h1>You added a new item:</h1>");
Expand Down
34 changes: 17 additions & 17 deletions src/controller/AddItemServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
@WebServlet("/AddItemServlet")
public class AddItemServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public AddItemServlet() {
super();
}

/**
* @see HttpServlet#HttpServlet()
*/
public AddItemServlet() {
super();
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
Expand All @@ -34,21 +34,21 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
request.setAttribute("title","New Item");

model.Model mod = (model.Model)getServletContext().getAttribute("model");
HttpSession session=request.getSession(false);
model.Users user=(model.Users)session.getAttribute("user");
if(user!=null){
String name=(String)session.getAttribute("name");
request.setAttribute("name",name);
request.setAttribute("page","content/AddItem.jsp");
}
else{
request.setAttribute("page","content/LoginFirst.jsp");
HttpSession session=request.getSession(false);
request.setAttribute("page","content/LoginFirst.jsp");
if(session!=null) {
model.Users user=(model.Users)session.getAttribute("user");
if(user!=null){
String name=(String)session.getAttribute("name");
request.setAttribute("name",name);
request.setAttribute("page","content/AddItem.jsp");
}
}
RequestDispatcher rd=request.getRequestDispatcher("template.jsp");
rd.forward(request, response);
out.close();
}


/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
Expand Down
71 changes: 40 additions & 31 deletions src/controller/ChangeRequestResponeServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,54 +17,63 @@
@WebServlet("/ChangeRequestResponeServlet")
public class ChangeRequestResponeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ChangeRequestResponeServlet() {
super();
}

/**
* @see HttpServlet#HttpServlet()
*/
public ChangeRequestResponeServlet() {
super();
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out=response.getWriter();

request.setAttribute("title","Request Approve");

model.Model mod = (model.Model)getServletContext().getAttribute("model");
model.Requests req=mod.getRequestByID(request.getParameter("req_id"));
String newResp=request.getParameter("new_resp");
HttpSession session=request.getSession(false);
if(session==null){
request.setAttribute("page","content/LoginFirst.jsp");
}
else
{
request.setAttribute("page","content/LoginFirst.jsp");
if(session!=null) {
model.Users user=(model.Users)session.getAttribute("user");
if(user==null) {
request.setAttribute("page","content/LoginFirst.jsp");
} else {
if(user!=null){
String name=(String)session.getAttribute("name");
request.setAttribute("name",name);
if(req.getOwnerID().equals(user.getUserID())) {
//TODO:check if owner to aprove and deny and dnoe. check if borower if cancel
//TODO:add user details page
req.setResponse(newResp);
mod.editRequest(req);
String msg;
if(newResp.equals("1")) {msg="request approved";}
if(newResp.equals("2")) {msg="request Denyed";}
if(newResp.equals("3")) {msg="request Done";}
if(newResp.equals("4")) {msg="request Canceled";}
else {msg="Unknown request status";}

request.setAttribute("message", msg);
String msg="";
if(newResp.equals("1")||newResp.equals("2")||newResp.equals("3")) {
if(req.getOwnerID().equals(user.getUserID())) {
//TODO:check if owner to aprove and deny and dnoe. check if borower if cancel
//TODO:add user details page

if(newResp.equals("1")) {msg="request approved";}
else if(newResp.equals("2")) {msg="request Denyed";}
else if(newResp.equals("3")) {msg="request Done";}
req.setResponse(newResp);
mod.editRequest(req);
} else {
msg= "you are not the owner of this item! go away!";
}
} else if(newResp.equals("4")){
if(req.getBorrowerID().equals(user.getUserID())) {
{msg="request Canceled";}
req.setResponse(newResp);
mod.editRequest(req);
} else {
//not the request creaator:
msg="you are not the owner of this request! go away!";

}
} else {
request.setAttribute("message", "you are not the owner! go away!");
//some strange respone code:
msg="What are you trying to do with respone code="+newResp+"?";
}

request.setAttribute("message", msg);
request.setAttribute("page","content/FreeMessage.jsp");
}

Expand Down
3 changes: 1 addition & 2 deletions src/controller/InitiateModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public class InitiateModel extends HttpServlet {

public void init() throws ServletException
{
System.out.println("---------- Here shoud come the code that create model instance----------");
System.out.println("---------- Reloading Content ----------");
model.Model myModel=new model.Model();
getServletContext().setAttribute("model", myModel);
System.out.println("----");
}
}
Loading

0 comments on commit 63c1770

Please sign in to comment.