Subversion Repositories SmartDukaan

Rev

Rev 21577 | Rev 21612 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21577 ashik.ali 1
package com.spice.profitmandi.web.controller;
2
 
3
import java.util.List;
4
 
5
import javax.servlet.http.HttpServletRequest;
6
 
7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.stereotype.Controller;
11
import org.springframework.ui.Model;
21581 ashik.ali 12
import org.springframework.ui.ModelMap;
21577 ashik.ali 13
import org.springframework.web.bind.annotation.ModelAttribute;
14
import org.springframework.web.bind.annotation.RequestMapping;
15
import org.springframework.web.bind.annotation.RequestParam;
16
 
17
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
18
import com.spice.profitmandi.common.model.ProfitMandiConstants;
19
import com.spice.profitmandi.dao.entity.CurrentInventorySnapshot;
20
import com.spice.profitmandi.dao.entity.FofoItemId;
21
import com.spice.profitmandi.dao.repository.CurrentInventorySnapshotRepository;
22
import com.spice.profitmandi.web.model.FofoDetails;
23
import com.spice.profitmandi.web.util.CookiesFetcher;
24
import com.spice.profitmandi.web.util.MVCResponseSender;
25
 
26
@Controller
27
public class InventoryController {
28
 
29
	private static final Logger LOGGER = LoggerFactory.getLogger(InventoryController.class);
30
 
31
	@Autowired
32
	CurrentInventorySnapshotRepository  currentInventorySnapshotRepository;
33
 
34
	@Autowired
35
	MVCResponseSender mvcResponseSender;
36
 
37
	@Autowired
38
	CookiesFetcher cookiesFetcher;
39
 
40
	@RequestMapping(value = "/checkCurrentAvailability")
21581 ashik.ali 41
	public String getCurrentAvailability(HttpServletRequest request, @ModelAttribute ModelMap model) throws Exception{
21577 ashik.ali 42
		FofoDetails fofoDetails;
43
		try {
44
			fofoDetails = cookiesFetcher.getCookiesObject(request);
45
		} catch (ProfitMandiBusinessException e) {
21581 ashik.ali 46
			model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
47
			return "response";
21577 ashik.ali 48
		}
49
		try{
50
			List<CurrentInventorySnapshot> currentInventorySnapshots = currentInventorySnapshotRepository.getByFofoId(fofoDetails.getFofoId());
51
			model.addAttribute("currentInventorySnapshots", currentInventorySnapshots);
52
			return "dashboard";
53
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
21581 ashik.ali 54
			model.addAttribute("loginResponse", mvcResponseSender.createResponseString("INVNTRY_SNPSHT", false, "/dashboard"));
55
			return "response";
21577 ashik.ali 56
		}
57
	}
58
 
59
	@RequestMapping(value = "/checkItemAvailability")
60
	public String getItemAvailability(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, @ModelAttribute Model model) throws Exception{
61
		FofoDetails fofoDetails;
62
		try {
63
			fofoDetails = cookiesFetcher.getCookiesObject(request);
64
		} catch (ProfitMandiBusinessException e) {
21581 ashik.ali 65
			model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
66
			return "response";
21577 ashik.ali 67
		}
68
		try{
69
			FofoItemId fofoItemId = new FofoItemId();
70
			fofoItemId.setFofoId(fofoDetails.getFofoId());
71
			fofoItemId.setItemId(itemId);
72
			CurrentInventorySnapshot currentInventorySnapshot = currentInventorySnapshotRepository.selectByFofoItemId(fofoItemId);
73
			model.addAttribute("currentInventorySnapshots", currentInventorySnapshot);
74
			return "dashboard";
75
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
21581 ashik.ali 76
			model.addAttribute("loginResponse", mvcResponseSender.createResponseString("INVNTRY_SNPSHT", false, "/dashboard"));
77
			return "response";
21577 ashik.ali 78
		}
79
	}
80
 
81
}