| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.util.HashSet;
|
| 3 |
import java.util.List;
|
4 |
import java.util.List;
|
| 4 |
|
5 |
|
| 5 |
import javax.servlet.http.HttpServletRequest;
|
6 |
import javax.servlet.http.HttpServletRequest;
|
| 6 |
|
7 |
|
| 7 |
import org.apache.logging.log4j.LogManager;
|
8 |
import org.apache.logging.log4j.LogManager;
|
| 8 |
import org.apache.logging.log4j.Logger;
|
9 |
import org.apache.logging.log4j.Logger;
|
| 9 |
import org.springframework.beans.factory.annotation.Autowired;
|
10 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
11 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 10 |
import org.springframework.stereotype.Controller;
|
12 |
import org.springframework.stereotype.Controller;
|
| 11 |
import org.springframework.transaction.annotation.Transactional;
|
13 |
import org.springframework.transaction.annotation.Transactional;
|
| 12 |
import org.springframework.ui.Model;
|
14 |
import org.springframework.ui.Model;
|
| 13 |
import org.springframework.web.bind.annotation.RequestBody;
|
15 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 14 |
import org.springframework.web.bind.annotation.RequestMapping;
|
16 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 15 |
import org.springframework.web.bind.annotation.RequestMethod;
|
17 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 16 |
import org.springframework.web.bind.annotation.RequestParam;
|
18 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 17 |
|
19 |
|
| 18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
20 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 19 |
import com.spice.profitmandi.common.model.CreateWarehouseRequest;
|
21 |
import com.spice.profitmandi.common.model.CreateWarehouseRequest;
|
| - |
|
22 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 20 |
import com.spice.profitmandi.common.util.Utils;
|
23 |
import com.spice.profitmandi.common.util.Utils;
|
| - |
|
24 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 21 |
import com.spice.profitmandi.dao.entity.nonbillable.Warehouse;
|
25 |
import com.spice.profitmandi.dao.entity.nonbillable.Warehouse;
|
| - |
|
26 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| - |
|
27 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| - |
|
28 |
import com.spice.profitmandi.dao.repository.nonbillable.UserWarehouseRepository;
|
| 22 |
import com.spice.profitmandi.dao.repository.nonbillable.WarehouseRepository;
|
29 |
import com.spice.profitmandi.dao.repository.nonbillable.WarehouseRepository;
|
| 23 |
import com.spice.profitmandi.service.nonbillable.WarehouseService;
|
30 |
import com.spice.profitmandi.service.nonbillable.WarehouseService;
|
| 24 |
|
31 |
|
| 25 |
@Controller
|
32 |
@Controller
|
| 26 |
@Transactional
|
33 |
@Transactional
|
| Line 32... |
Line 39... |
| 32 |
private WarehouseRepository warehouseRepository;
|
39 |
private WarehouseRepository warehouseRepository;
|
| 33 |
|
40 |
|
| 34 |
@Autowired
|
41 |
@Autowired
|
| 35 |
private WarehouseService warehouseService;
|
42 |
private WarehouseService warehouseService;
|
| 36 |
|
43 |
|
| - |
|
44 |
@Autowired
|
| - |
|
45 |
@Qualifier("userRepository")
|
| - |
|
46 |
private UserRepository userRepository;
|
| - |
|
47 |
|
| - |
|
48 |
@Autowired
|
| - |
|
49 |
private UserAccountRepository userAccountRepository;
|
| - |
|
50 |
|
| - |
|
51 |
@Autowired
|
| - |
|
52 |
private UserWarehouseRepository userWarehouseRepository;
|
| - |
|
53 |
|
| 37 |
@RequestMapping(value = "/createWarehouse", method = RequestMethod.GET)
|
54 |
@RequestMapping(value = "/createWarehouse", method = RequestMethod.GET)
|
| 38 |
public String createWarehouse(HttpServletRequest request, Model model) {
|
55 |
public String createWarehouse(HttpServletRequest request, Model model) {
|
| 39 |
model.addAttribute("stateNames", Utils.getAllStateNames());
|
56 |
model.addAttribute("stateNames", Utils.getAllStateNames());
|
| 40 |
return "create-warehouse";
|
57 |
return "create-warehouse";
|
| 41 |
}
|
58 |
}
|
| Line 77... |
Line 94... |
| 77 |
List<Warehouse> warehouses = warehouseRepository.selectAll(offset, limit);
|
94 |
List<Warehouse> warehouses = warehouseRepository.selectAll(offset, limit);
|
| 78 |
model.addAttribute("warehouses", warehouses);
|
95 |
model.addAttribute("warehouses", warehouses);
|
| 79 |
return "warehouses-paginated";
|
96 |
return "warehouses-paginated";
|
| 80 |
}
|
97 |
}
|
| 81 |
|
98 |
|
| - |
|
99 |
@RequestMapping(value = "/getAddRemoveWarehouse", method = RequestMethod.GET)
|
| - |
|
100 |
public String getAddRemoveWarehouse(HttpServletRequest request) {
|
| - |
|
101 |
return "add-remove-warehouse";
|
| - |
|
102 |
}
|
| - |
|
103 |
|
| - |
|
104 |
@RequestMapping(value = "/userWarehouses", method = RequestMethod.GET)
|
| - |
|
105 |
public String userWarehouses(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber, Model model) throws Exception{
|
| - |
|
106 |
User user = userRepository.selectByEmailIdOrMobileNumber(emailIdOrMobileNumber);
|
| - |
|
107 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
| - |
|
108 |
List<Integer> warehouseIds = userWarehouseRepository.selectWarehouseIdsByUserId(retailerId);
|
| - |
|
109 |
List<Warehouse> warehouses = warehouseRepository.selectAll();
|
| - |
|
110 |
model.addAttribute("userWarehouseIds", warehouseIds);
|
| - |
|
111 |
model.addAttribute("warehouses", warehouses);
|
| - |
|
112 |
return "user-warehouses";
|
| - |
|
113 |
}
|
| - |
|
114 |
|
| - |
|
115 |
@RequestMapping(value = "/addRemoveWarehouses", method = RequestMethod.POST)
|
| - |
|
116 |
public String addRemoveRoles(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.EMAIL_ID_OR_MOBILE_NUMBER) String emailIdOrMobileNumber, @RequestBody List<Integer> warehouseIds, Model model) throws Exception{
|
| - |
|
117 |
warehouseService.addRemoveWarehouses(emailIdOrMobileNumber, new HashSet<>(warehouseIds));
|
| - |
|
118 |
return "add-remove-warehouse";
|
| - |
|
119 |
}
|
| - |
|
120 |
|
| 82 |
}
|
121 |
}
|