Skip to content

Commit

Permalink
merging changes related to load orders
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaikar committed Nov 26, 2015
1 parent 0666010 commit da18e3c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 23 deletions.
23 changes: 22 additions & 1 deletion src/main/java/com/ots/controller/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.ots.common.UserBean;
import com.ots.dao.OrderDaoImpl;
import com.ots.dao.PaymentDaoImpl;
import com.ots.service.OrderServiceImpl;
import com.ots.service.UserManagementServiceImpl;

@Controller
Expand All @@ -39,6 +40,9 @@ public class HomeController {
private UserManagementServiceImpl userManagementServiceImpl;
@Autowired
private PaymentDaoImpl paymentDaoImpl;

@Autowired
private OrderServiceImpl orderSerivceImpl;

@RequestMapping(value = "/home", method = RequestMethod.GET)
public String home(ModelMap model, HttpServletRequest request) {
Expand Down Expand Up @@ -206,6 +210,7 @@ public String cancelOrder(ModelMap model, @RequestParam(required = false) List<S
return ("orderSummary");
}


/**
* This rest API accepts list of Order ids and makes the payment
*
Expand Down Expand Up @@ -286,7 +291,23 @@ public String index(HttpServletRequest request, ModelMap map) {
public ModelAndView logout(ModelMap model) {
return new ModelAndView("heading");
}



/**
* This Rest API returns the Top menu jsp
*
* @param model
* @return
*/
@RequestMapping(value = "/loadOrders", method = RequestMethod.GET)
public ModelAndView loadOrders(ModelMap model,HttpServletRequest request) {
ClientBean clientBean = (ClientBean) request.getSession().getAttribute("selectedClient");
List<OrderSummaryBean> orders=orderSerivceImpl.fetchAllOrders(clientBean.getClientId());
model.addAttribute("orders", orders);
return new ModelAndView("orderSummary.jsp");
}


/**
* This Api will be used for returning the page that displays the empty
* "create new User" form
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/ots/dao/OrderDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class OrderDaoImpl {

public static final String QUERY_INSERT_TASK = "INSERT INTO orders(id,type,quantity,commission_fees,commission_type,total_amt,oil_adjusted_quantity,date_placed ) VALUES (?,?,?,?,?,?,?,?)";
public static final String SELECT_ORDER_BY_USER_ID = "SELECT * FROM orders where order_id IN (SELECT order_id FROM places where client_id=?)";
public static final String SELECT_ORDER_BY_USER_ID = "SELECT * FROM orders where order_id IN (SELECT order_id FROM places where client_id= ?) order by date_placed desc";
public static final String UPDATE_ORDER = "UPDATE orders SET payment_id = ? WHERE order_id in (?)";

private JdbcTemplate adminJdbcConnectionTemplate;
Expand All @@ -40,7 +40,7 @@ public void setDataSource(DataSource adminDataSource, DataSource traderDataSourc
}

/**
* Method for fetching details based on userName and password
* Method for fetching all orders for a client in Descending order
*
* @param userName
* @param password
Expand All @@ -54,7 +54,6 @@ public void setValues(java.sql.PreparedStatement ps) throws SQLException {
}
}, new OrderRowMapper());
return orders;

}

/**
Expand Down
27 changes: 8 additions & 19 deletions src/main/java/com/ots/service/OrderServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;
import com.ots.common.ClientBean;
import com.ots.common.OrderSummaryBean;
import com.ots.common.TraderBean;
import com.ots.common.UserBean;
import com.ots.dao.ClientDaoImpl;
import com.ots.dao.OrderDaoImpl;
import com.ots.dao.TraderDaoImpl;
import com.ots.dao.UserDaoImpl;

Expand All @@ -23,28 +25,15 @@
public class OrderServiceImpl {

@Autowired
private UserDaoImpl userDao;

@Autowired
private ClientDaoImpl clientDao;

@Autowired
private TraderDaoImpl traderDao;

private OrderDaoImpl orderDaoImpl;

/**
* This method validates whether user's credentials are correct or not and
* if not, it returns the null object.
*
* @param userName
* @param password
* This method returns All Orders applicable for selected client
* @param clientId
* @return
*/
public UserBean validateAndFetchUserDetails(String userName, String password) {
UserBean user = userDao.getUserDetails(userName, password);
if (user != null) {
user.setPassword(null);
}
return user;
public List<OrderSummaryBean> fetchAllOrders(String clientId) {
return orderDaoImpl.getOrders(clientId);
}

}
12 changes: 12 additions & 0 deletions src/main/webapp/WEB-INF/view/home.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@
});
}
function loadOrders() {
$.ajax({
type : "GET",
url : "loadOrders",
data : "userId=" + userId,
success : function(data) {
$("#container").html(data);
}
});
}
function cancelOrder() {
var orderIds = "";
$('input[type="Checkbox"]:checked').each(function() {
Expand Down

0 comments on commit da18e3c

Please sign in to comment.