Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
1981 varun.gupt 1
package in.shop2020.serving.controllers;
2
 
3
import org.apache.log4j.Logger;
4
import org.apache.struts2.convention.annotation.Result;
5
import org.apache.struts2.convention.annotation.Results;
6
 
7
import in.shop2020.model.v1.user.PromotionException;
8
import in.shop2020.model.v1.user.UserContextService;
9
import in.shop2020.model.v1.user.PromotionService;
10
import in.shop2020.serving.controllers.BaseController;
11
import in.shop2020.thrift.clients.UserContextServiceClient;
12
import in.shop2020.thrift.clients.PromotionServiceClient;
13
 
2145 chandransh 14
@SuppressWarnings("serial")
1981 varun.gupt 15
@Results({
16
    @Result(name = "redirect", type = "redirectAction", params = {"actionName" , "cart"})
17
})
18
public class PromotionController extends BaseController {
19
 
20
    public PromotionController() {
21
        super();
22
    }
23
    private static Logger log = Logger.getLogger(Class.class);
24
 
25
    public String create()  {
26
        String action = request.getParameter("action");
27
        log.info("Action is: " + action);
28
 
29
        UserContextServiceClient userServiceClient = null;
30
        PromotionServiceClient promotionServiceClient = null;
31
 
32
        try {
33
            long cartId = userinfo.getCartId();
34
 
35
            if(action == null || action.isEmpty())  {
36
                addActionError("Invalid Request Action");
37
                return "redirect";
38
            }
39
            if (action.equals("applycoupon"))   {
40
                String couponCode = request.getParameter("coupon_code");
41
 
42
                if (couponCode == null || couponCode.isEmpty()) {
43
                    addActionError("Coupon Code field cannot be left empty");
44
                    return "redirect";
45
                }
46
                promotionServiceClient = new PromotionServiceClient();
47
                PromotionService.Client promotionClient = promotionServiceClient.getClient();
2145 chandransh 48
                promotionClient.applyCoupon(couponCode, cartId);
1981 varun.gupt 49
            }
50
            else if (action.equals("removecoupon"))    {
51
                userServiceClient = new UserContextServiceClient();
52
                UserContextService.Client userClient = userServiceClient.getClient();
53
                userClient.removeCoupon(cartId);
54
            }
55
        } catch (PromotionException e) {
56
            addActionError(e.getMessage());
57
        } catch (Exception e) {
58
            e.printStackTrace();
59
        }
60
        return "redirect";
61
    }
62
}