| 21292 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDateTime;
|
|
|
4 |
import java.util.Map;
|
|
|
5 |
|
|
|
6 |
import javax.servlet.http.HttpServletRequest;
|
|
|
7 |
|
| 23568 |
govind |
8 |
import org.apache.logging.log4j.Logger;
|
|
|
9 |
import org.apache.logging.log4j.LogManager;
|
| 21292 |
ashik.ali |
10 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
11 |
import org.springframework.http.ResponseEntity;
|
|
|
12 |
import org.springframework.stereotype.Controller;
|
| 21702 |
ashik.ali |
13 |
import org.springframework.transaction.annotation.Transactional;
|
| 21292 |
ashik.ali |
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.ResponseCodeHolder;
|
|
|
19 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
20 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21740 |
ashik.ali |
21 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 21735 |
ashik.ali |
22 |
import com.spice.profitmandi.dao.entity.dtr.Shop;
|
|
|
23 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
|
|
24 |
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
|
| 21292 |
ashik.ali |
25 |
|
|
|
26 |
@Controller
|
| 22037 |
amit.gupta |
27 |
@Transactional(rollbackFor=Throwable.class)
|
| 21292 |
ashik.ali |
28 |
public class ShopController {
|
|
|
29 |
|
| 21448 |
ashik.ali |
30 |
@Autowired
|
| 22931 |
ashik.ali |
31 |
private ResponseSender<?> responseSender;
|
| 21448 |
ashik.ali |
32 |
|
| 23568 |
govind |
33 |
private static final Logger LOGGER=LogManager.getLogger(ShopController.class);
|
| 21292 |
ashik.ali |
34 |
|
|
|
35 |
@Autowired
|
|
|
36 |
ShopRepository shopRepository;
|
|
|
37 |
|
|
|
38 |
@Autowired
|
|
|
39 |
RetailerRepository retailerRepository;
|
|
|
40 |
|
|
|
41 |
@RequestMapping(value = ProfitMandiConstants.URL_SHOP, method=RequestMethod.POST)
|
| 22931 |
ashik.ali |
42 |
public ResponseEntity<?> createShop(HttpServletRequest request) throws ProfitMandiBusinessException{
|
| 21292 |
ashik.ali |
43 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
44 |
@SuppressWarnings("unchecked")
|
|
|
45 |
final Map<String, Object> createShopMap = (Map<String, Object>)request.getAttribute(ProfitMandiConstants.CREATE_SHOP_MAP);
|
|
|
46 |
request.removeAttribute(ProfitMandiConstants.CREATE_SHOP_MAP);
|
|
|
47 |
|
| 22931 |
ashik.ali |
48 |
Shop shop = new Shop();
|
|
|
49 |
shop.setRetailerId((int)createShopMap.get(ProfitMandiConstants.RETAILER_ID));
|
|
|
50 |
//shop.setRetailer(retailer);
|
|
|
51 |
shop.setName(createShopMap.get(ProfitMandiConstants.NAME).toString());
|
|
|
52 |
shop.setCreateTimestamp(LocalDateTime.now());
|
|
|
53 |
shop.setUpdateTimestamp(LocalDateTime.now());
|
|
|
54 |
shopRepository.persist(shop);
|
|
|
55 |
return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1000"));
|
|
|
56 |
|
| 21292 |
ashik.ali |
57 |
}
|
|
|
58 |
|
|
|
59 |
@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ID, method=RequestMethod.GET)
|
| 22931 |
ashik.ali |
60 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id)throws ProfitMandiBusinessException{
|
| 21292 |
ashik.ali |
61 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 22931 |
ashik.ali |
62 |
return responseSender.ok(shopRepository.selectById(id));
|
| 21292 |
ashik.ali |
63 |
}
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ID, method=RequestMethod.DELETE)
|
| 22931 |
ashik.ali |
67 |
public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") int id)throws ProfitMandiBusinessException{
|
| 21292 |
ashik.ali |
68 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 22931 |
ashik.ali |
69 |
shopRepository.deleteById(id);
|
|
|
70 |
return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
|
| 21292 |
ashik.ali |
71 |
}
|
|
|
72 |
|
|
|
73 |
}
|