| 23784 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.util.List;
|
|
|
4 |
|
|
|
5 |
import javax.servlet.http.HttpServletRequest;
|
|
|
6 |
|
|
|
7 |
import org.apache.logging.log4j.LogManager;
|
|
|
8 |
import org.apache.logging.log4j.Logger;
|
|
|
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
10 |
import org.springframework.stereotype.Controller;
|
|
|
11 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
12 |
import org.springframework.ui.Model;
|
|
|
13 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
14 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
15 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
16 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
17 |
|
|
|
18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
19 |
import com.spice.profitmandi.common.model.CreateWarehouseRequest;
|
|
|
20 |
import com.spice.profitmandi.common.util.Utils;
|
|
|
21 |
import com.spice.profitmandi.dao.entity.nonbillable.Warehouse;
|
|
|
22 |
import com.spice.profitmandi.dao.repository.nonbillable.WarehouseRepository;
|
|
|
23 |
import com.spice.profitmandi.service.nonbillable.WarehouseService;
|
|
|
24 |
|
|
|
25 |
@Controller
|
|
|
26 |
@Transactional
|
|
|
27 |
public class WarehouseController {
|
|
|
28 |
|
|
|
29 |
private static final Logger LOGGER = LogManager.getLogger(WarehouseController.class);
|
|
|
30 |
|
|
|
31 |
@Autowired
|
|
|
32 |
private WarehouseRepository warehouseRepository;
|
|
|
33 |
|
|
|
34 |
@Autowired
|
|
|
35 |
private WarehouseService warehouseService;
|
|
|
36 |
|
|
|
37 |
@RequestMapping(value = "/createWarehouse", method = RequestMethod.GET)
|
|
|
38 |
public String createWarehouse(HttpServletRequest request, Model model) {
|
|
|
39 |
model.addAttribute("stateNames", Utils.getAllStateNames());
|
|
|
40 |
return "create-warehouse";
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
@RequestMapping(value = "/createWarehouse", method = RequestMethod.POST)
|
|
|
44 |
public String createWarehouse(HttpServletRequest request, @RequestBody CreateWarehouseRequest createWarehouseRequest, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
|
|
45 |
LOGGER.info("Request Received at url {} with body {}", request.getRequestURI(), createWarehouseRequest);
|
|
|
46 |
warehouseService.createWarehouse(createWarehouseRequest);
|
|
|
47 |
List<Warehouse> warehouses = warehouseRepository.selectAll(offset, limit);
|
|
|
48 |
long size = warehouseRepository.selectAllCount();
|
|
|
49 |
model.addAttribute("warehouses", warehouses);
|
|
|
50 |
model.addAttribute("start", offset + 1);
|
|
|
51 |
model.addAttribute("size", size);
|
|
|
52 |
if (warehouses.size() < limit){
|
|
|
53 |
model.addAttribute("end", offset + warehouses.size());
|
|
|
54 |
}else{
|
|
|
55 |
model.addAttribute("end", offset + limit);
|
|
|
56 |
}
|
|
|
57 |
return "warehouses";
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
@RequestMapping(value = "/getWarehouses", method = RequestMethod.GET)
|
|
|
61 |
public String getWarehouses(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
|
|
62 |
List<Warehouse> warehouses = warehouseRepository.selectAll(offset, limit);
|
|
|
63 |
long size = warehouseRepository.selectAllCount();
|
|
|
64 |
model.addAttribute("warehouses", warehouses);
|
|
|
65 |
model.addAttribute("start", offset + 1);
|
|
|
66 |
model.addAttribute("size", size);
|
|
|
67 |
if (warehouses.size() < limit){
|
|
|
68 |
model.addAttribute("end", offset + warehouses.size());
|
|
|
69 |
}else{
|
|
|
70 |
model.addAttribute("end", offset + limit);
|
|
|
71 |
}
|
|
|
72 |
return "warehouses";
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
@RequestMapping(value = "/getPaginatedWarehouses", method = RequestMethod.GET)
|
|
|
76 |
public String getPaginatedWarehouses(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
|
|
77 |
List<Warehouse> warehouses = warehouseRepository.selectAll(offset, limit);
|
|
|
78 |
model.addAttribute("warehouses", warehouses);
|
|
|
79 |
return "warehouses-paginated";
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
}
|