Subversion Repositories SmartDukaan

Rev

Rev 21581 | Go to most recent revision | Details | 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;
12
import org.springframework.web.bind.annotation.ModelAttribute;
13
import org.springframework.web.bind.annotation.RequestMapping;
14
import org.springframework.web.bind.annotation.RequestParam;
15
 
16
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
17
import com.spice.profitmandi.common.model.ProfitMandiConstants;
18
import com.spice.profitmandi.dao.entity.CurrentInventorySnapshot;
19
import com.spice.profitmandi.dao.entity.FofoItemId;
20
import com.spice.profitmandi.dao.repository.CurrentInventorySnapshotRepository;
21
import com.spice.profitmandi.web.model.FofoDetails;
22
import com.spice.profitmandi.web.util.CookiesFetcher;
23
import com.spice.profitmandi.web.util.MVCResponseSender;
24
 
25
@Controller
26
public class InventoryController {
27
 
28
	private static final Logger LOGGER = LoggerFactory.getLogger(InventoryController.class);
29
 
30
	@Autowired
31
	CurrentInventorySnapshotRepository  currentInventorySnapshotRepository;
32
 
33
	@Autowired
34
	MVCResponseSender mvcResponseSender;
35
 
36
	@Autowired
37
	CookiesFetcher cookiesFetcher;
38
 
39
	@RequestMapping(value = "/checkCurrentAvailability")
40
	public String getCurrentAvailability(HttpServletRequest request, @ModelAttribute Model model) throws Exception{
41
		FofoDetails fofoDetails;
42
		try {
43
			fofoDetails = cookiesFetcher.getCookiesObject(request);
44
		} catch (ProfitMandiBusinessException e) {
45
			return mvcResponseSender.createResponseString("RTLR_1009", false, "/login");
46
		}
47
		try{
48
			List<CurrentInventorySnapshot> currentInventorySnapshots = currentInventorySnapshotRepository.getByFofoId(fofoDetails.getFofoId());
49
			model.addAttribute("currentInventorySnapshots", currentInventorySnapshots);
50
			return "dashboard";
51
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
52
			return mvcResponseSender.createResponseString("INVNTRY_SNPSHT", false, "/dashboard");
53
		}
54
	}
55
 
56
	@RequestMapping(value = "/checkItemAvailability")
57
	public String getItemAvailability(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, @ModelAttribute Model model) throws Exception{
58
		FofoDetails fofoDetails;
59
		try {
60
			fofoDetails = cookiesFetcher.getCookiesObject(request);
61
		} catch (ProfitMandiBusinessException e) {
62
			return mvcResponseSender.createResponseString("RTLR_1009", false, "/login");
63
		}
64
		try{
65
			FofoItemId fofoItemId = new FofoItemId();
66
			fofoItemId.setFofoId(fofoDetails.getFofoId());
67
			fofoItemId.setItemId(itemId);
68
			CurrentInventorySnapshot currentInventorySnapshot = currentInventorySnapshotRepository.selectByFofoItemId(fofoItemId);
69
			model.addAttribute("currentInventorySnapshots", currentInventorySnapshot);
70
			return "dashboard";
71
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
72
			return mvcResponseSender.createResponseString("INVNTRY_SNPSHT", false, "/dashboard");
73
		}
74
	}
75
 
76
}