| 21390 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import javax.servlet.http.HttpServletRequest;
|
|
|
4 |
|
|
|
5 |
import org.slf4j.Logger;
|
|
|
6 |
import org.slf4j.LoggerFactory;
|
|
|
7 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
8 |
import org.springframework.http.ResponseEntity;
|
|
|
9 |
import org.springframework.stereotype.Controller;
|
| 21699 |
ashik.ali |
10 |
import org.springframework.transaction.annotation.Transactional;
|
| 21390 |
ashik.ali |
11 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
12 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
13 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
14 |
|
|
|
15 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
16 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21666 |
amit.gupta |
17 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 21390 |
ashik.ali |
18 |
import com.spice.profitmandi.dao.repository.AddressRepository;
|
| 21666 |
amit.gupta |
19 |
import com.spice.profitmandi.dao.repository.UserAccountRepository;
|
| 21448 |
ashik.ali |
20 |
import com.spice.profitmandi.web.util.ResponseSender;
|
| 21390 |
ashik.ali |
21 |
|
| 21666 |
amit.gupta |
22 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
23 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
24 |
|
| 21390 |
ashik.ali |
25 |
@Controller
|
| 21699 |
ashik.ali |
26 |
@Transactional
|
| 21390 |
ashik.ali |
27 |
public class AddressController {
|
|
|
28 |
|
| 21448 |
ashik.ali |
29 |
@Autowired
|
|
|
30 |
ResponseSender<?> responseSender;
|
|
|
31 |
|
| 21390 |
ashik.ali |
32 |
private static final Logger LOGGER=LoggerFactory.getLogger(AddressController.class);
|
|
|
33 |
|
|
|
34 |
@Autowired
|
|
|
35 |
AddressRepository addressRepository;
|
|
|
36 |
|
| 21666 |
amit.gupta |
37 |
@Autowired
|
|
|
38 |
UserAccountRepository userAccountRepository;
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
@ApiImplicitParams({
|
|
|
42 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
43 |
required = true, dataType = "string", paramType = "header")
|
|
|
44 |
})
|
| 21390 |
ashik.ali |
45 |
@RequestMapping(value = ProfitMandiConstants.URL_ADDRESS_ALL, method=RequestMethod.GET)
|
| 21666 |
amit.gupta |
46 |
public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize) throws Throwable{
|
|
|
47 |
int userId = (int)request.getAttribute("userId");
|
|
|
48 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
| 21390 |
ashik.ali |
49 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 21666 |
amit.gupta |
50 |
return responseSender.ok(addressRepository.selectAll(uc.getUserId(), pageNumber, pageSize));
|
| 21390 |
ashik.ali |
51 |
}
|
| 21426 |
ashik.ali |
52 |
|
| 21390 |
ashik.ali |
53 |
@RequestMapping(value = ProfitMandiConstants.URL_ADDRESS_ID, method=RequestMethod.GET)
|
| 21431 |
ashik.ali |
54 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21390 |
ashik.ali |
55 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
56 |
try {
|
| 21448 |
ashik.ali |
57 |
return responseSender.ok(addressRepository.selectById(id));
|
| 21440 |
ashik.ali |
58 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
59 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 21448 |
ashik.ali |
60 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 21390 |
ashik.ali |
61 |
}
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
}
|