| 21390 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 22372 |
amit.gupta |
3 |
import java.util.HashMap;
|
|
|
4 |
import java.util.Map;
|
|
|
5 |
|
| 21390 |
ashik.ali |
6 |
import javax.servlet.http.HttpServletRequest;
|
|
|
7 |
|
|
|
8 |
import org.slf4j.Logger;
|
|
|
9 |
import org.slf4j.LoggerFactory;
|
|
|
10 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 22372 |
amit.gupta |
11 |
import org.springframework.beans.factory.annotation.Value;
|
| 21390 |
ashik.ali |
12 |
import org.springframework.http.ResponseEntity;
|
|
|
13 |
import org.springframework.stereotype.Controller;
|
| 21699 |
ashik.ali |
14 |
import org.springframework.transaction.annotation.Transactional;
|
| 22372 |
amit.gupta |
15 |
import org.springframework.web.bind.annotation.PathVariable;
|
| 21390 |
ashik.ali |
16 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
17 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
18 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
19 |
|
| 22372 |
amit.gupta |
20 |
import com.eclipsesource.json.Json;
|
|
|
21 |
import com.eclipsesource.json.JsonObject;
|
|
|
22 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
| 21390 |
ashik.ali |
23 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
24 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 22372 |
amit.gupta |
25 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 21740 |
ashik.ali |
26 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 21666 |
amit.gupta |
27 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 21735 |
ashik.ali |
28 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
29 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 21390 |
ashik.ali |
30 |
|
| 21666 |
amit.gupta |
31 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
32 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
33 |
|
| 21390 |
ashik.ali |
34 |
@Controller
|
| 22040 |
amit.gupta |
35 |
@Transactional(rollbackFor=Throwable.class)
|
| 21390 |
ashik.ali |
36 |
public class AddressController {
|
|
|
37 |
|
| 22372 |
amit.gupta |
38 |
@Value("${python.api.host}")
|
|
|
39 |
private String host;
|
|
|
40 |
@Value("${python.api.port}")
|
|
|
41 |
private int port;
|
|
|
42 |
|
| 21448 |
ashik.ali |
43 |
@Autowired
|
| 22931 |
ashik.ali |
44 |
private ResponseSender<?> responseSender;
|
| 21448 |
ashik.ali |
45 |
|
| 21390 |
ashik.ali |
46 |
private static final Logger LOGGER=LoggerFactory.getLogger(AddressController.class);
|
|
|
47 |
|
|
|
48 |
@Autowired
|
| 22931 |
ashik.ali |
49 |
private AddressRepository addressRepository;
|
| 21390 |
ashik.ali |
50 |
|
| 21666 |
amit.gupta |
51 |
@Autowired
|
| 22931 |
ashik.ali |
52 |
private UserAccountRepository userAccountRepository;
|
| 21666 |
amit.gupta |
53 |
|
|
|
54 |
|
|
|
55 |
@ApiImplicitParams({
|
|
|
56 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
57 |
required = true, dataType = "string", paramType = "header")
|
|
|
58 |
})
|
| 21390 |
ashik.ali |
59 |
@RequestMapping(value = ProfitMandiConstants.URL_ADDRESS_ALL, method=RequestMethod.GET)
|
| 21666 |
amit.gupta |
60 |
public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize) throws Throwable{
|
|
|
61 |
int userId = (int)request.getAttribute("userId");
|
|
|
62 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
| 21390 |
ashik.ali |
63 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 21666 |
amit.gupta |
64 |
return responseSender.ok(addressRepository.selectAll(uc.getUserId(), pageNumber, pageSize));
|
| 21390 |
ashik.ali |
65 |
}
|
| 21426 |
ashik.ali |
66 |
|
| 21390 |
ashik.ali |
67 |
@RequestMapping(value = ProfitMandiConstants.URL_ADDRESS_ID, method=RequestMethod.GET)
|
| 21431 |
ashik.ali |
68 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21390 |
ashik.ali |
69 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
70 |
try {
|
| 21448 |
ashik.ali |
71 |
return responseSender.ok(addressRepository.selectById(id));
|
| 21440 |
ashik.ali |
72 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
73 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
74 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21390 |
ashik.ali |
75 |
}
|
|
|
76 |
}
|
| 22372 |
amit.gupta |
77 |
|
|
|
78 |
@RequestMapping(value = "/pin-info/{pinCode}", method=RequestMethod.GET)
|
|
|
79 |
public ResponseEntity<?> getPinInfo(HttpServletRequest request, @PathVariable(value="pinCode") String pinCode){
|
|
|
80 |
try {
|
|
|
81 |
RestClient rc = new RestClient(SchemeType.HTTP, host, port);
|
|
|
82 |
Map<String, String> params = new HashMap<>();
|
|
|
83 |
String response = rc.get("pincodeValidation/" + pinCode, params);
|
|
|
84 |
JsonObject result_json = Json.parse(response).asObject();
|
|
|
85 |
return responseSender.ok(result_json);
|
|
|
86 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
87 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
|
|
88 |
return responseSender.badRequest(profitMandiBusinessException);
|
|
|
89 |
}
|
|
|
90 |
}
|
| 21390 |
ashik.ali |
91 |
|
|
|
92 |
}
|