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