Subversion Repositories SmartDukaan

Rev

Rev 22037 | Rev 23273 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 22037 Rev 22931
Line 26... Line 26...
26
@Controller
26
@Controller
27
@Transactional(rollbackFor=Throwable.class)
27
@Transactional(rollbackFor=Throwable.class)
28
public class ShopController {
28
public class ShopController {
29
	
29
	
30
	@Autowired
30
	@Autowired
31
	ResponseSender<?> responseSender;
31
	private ResponseSender<?> responseSender;
32
	
-
 
33
	
32
	
34
	private static final Logger LOGGER=LoggerFactory.getLogger(ShopController.class);
33
	private static final Logger LOGGER=LoggerFactory.getLogger(ShopController.class);
35
	
34
	
36
	@Autowired
35
	@Autowired
37
	ShopRepository shopRepository;
36
	ShopRepository shopRepository;
38
	
37
	
39
	@Autowired
38
	@Autowired
40
	RetailerRepository retailerRepository;
39
	RetailerRepository retailerRepository;
41
	
40
	
42
	@RequestMapping(value = ProfitMandiConstants.URL_SHOP, method=RequestMethod.POST)
41
	@RequestMapping(value = ProfitMandiConstants.URL_SHOP, method=RequestMethod.POST)
43
	public ResponseEntity<?> createShop(HttpServletRequest request){
42
	public ResponseEntity<?> createShop(HttpServletRequest request) throws ProfitMandiBusinessException{
44
		LOGGER.info("requested url : "+request.getRequestURL().toString());
43
		LOGGER.info("requested url : "+request.getRequestURL().toString());
45
		@SuppressWarnings("unchecked")
44
		@SuppressWarnings("unchecked")
46
		final Map<String, Object>  createShopMap = (Map<String, Object>)request.getAttribute(ProfitMandiConstants.CREATE_SHOP_MAP);
45
		final Map<String, Object>  createShopMap = (Map<String, Object>)request.getAttribute(ProfitMandiConstants.CREATE_SHOP_MAP);
47
		request.removeAttribute(ProfitMandiConstants.CREATE_SHOP_MAP);
46
		request.removeAttribute(ProfitMandiConstants.CREATE_SHOP_MAP);
48
		
47
		
49
		try {
-
 
50
			Shop shop = new Shop();
48
		Shop shop = new Shop();
51
			shop.setRetailerId((int)createShopMap.get(ProfitMandiConstants.RETAILER_ID));
49
		shop.setRetailerId((int)createShopMap.get(ProfitMandiConstants.RETAILER_ID));
52
			//shop.setRetailer(retailer);
50
		//shop.setRetailer(retailer);
53
			shop.setName(createShopMap.get(ProfitMandiConstants.NAME).toString());
51
		shop.setName(createShopMap.get(ProfitMandiConstants.NAME).toString());
54
			shop.setCreateTimestamp(LocalDateTime.now());
52
		shop.setCreateTimestamp(LocalDateTime.now());
55
			shop.setUpdateTimestamp(LocalDateTime.now());
53
		shop.setUpdateTimestamp(LocalDateTime.now());
56
			shopRepository.persist(shop);
54
		shopRepository.persist(shop);
57
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1000"));
55
		return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1000"));
58
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
59
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
-
 
60
			return responseSender.badRequest(profitMandiBusinessException);
-
 
61
		}
56
		
62
	}
57
	}
63
	
58
	
64
	@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ALL, method=RequestMethod.GET)
59
	@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ALL, method=RequestMethod.GET)
65
	public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize){
60
	public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize){
66
		LOGGER.info("requested url : "+request.getRequestURL().toString());
61
		LOGGER.info("requested url : "+request.getRequestURL().toString());
67
		return responseSender.ok(shopRepository.selectAll(pageNumber, pageSize));
62
		return responseSender.ok(shopRepository.selectAll(pageNumber, pageSize));
68
	}
63
	}
69
	@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ID, method=RequestMethod.GET)
64
	@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ID, method=RequestMethod.GET)
70
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
65
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id)throws ProfitMandiBusinessException{
71
		LOGGER.info("requested url : "+request.getRequestURL().toString());
66
		LOGGER.info("requested url : "+request.getRequestURL().toString());
72
		try {
-
 
73
			return responseSender.ok(shopRepository.selectById(id));
67
		return responseSender.ok(shopRepository.selectById(id));
74
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
75
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
-
 
76
			return responseSender.badRequest(profitMandiBusinessException);
-
 
77
		}
-
 
78
	}
68
	}
79
	
69
	
80
	
70
	
81
	@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ID, method=RequestMethod.DELETE)
71
	@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ID, method=RequestMethod.DELETE)
82
	public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") int id){
72
	public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") int id)throws ProfitMandiBusinessException{
83
		LOGGER.info("requested url : "+request.getRequestURL().toString());
73
		LOGGER.info("requested url : "+request.getRequestURL().toString());
84
		try {
-
 
85
			shopRepository.deleteById(id);
74
		shopRepository.deleteById(id);
86
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
75
		return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
87
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
88
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
-
 
89
			return responseSender.badRequest(profitMandiBusinessException);
-
 
90
		}
-
 
91
	}
76
	}
92
	
77
	
93
}
78
}