Subversion Repositories SmartDukaan

Rev

Rev 23037 | Rev 23936 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
import com.spice.profitmandi.common.model.ProfitMandiConstants;
import com.spice.profitmandi.common.web.util.ResponseSender;
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
import com.spice.profitmandi.service.wallet.WalletService;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Controller
@Transactional(rollbackFor=Throwable.class)
public class WalletController {

        private static final Logger log=LogManager.getLogger(WalletController.class);

        @Autowired
        UserWalletRepository userWalletRepository;
        
        @Autowired
        WalletService walletService;
        
        @Autowired
        ResponseSender<?> responseSender;

        @RequestMapping(value = ProfitMandiConstants.URL_MY_WALLET, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
        @ApiImplicitParams({
                @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
                                required = true, dataType = "string", paramType = "header")
        })
        @ApiOperation(value = "")
        public ResponseEntity<?> getMyWallet(HttpServletRequest request) throws ProfitMandiBusinessException{
                int userId = (int)request.getAttribute("userId");
                try{
                        return responseSender.ok(walletService.getUserWalletByUserId(userId));
                }catch(ProfitMandiBusinessException profitMandiBusinessException){
                        return responseSender.badRequest(profitMandiBusinessException);
                }
        }

        @RequestMapping(value = ProfitMandiConstants.URL_MY_WALLET_HISTORY, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
        @ApiImplicitParams({
                @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
                                required = true, dataType = "string", paramType = "header")
        })
        public ResponseEntity<?> getMyWalletHistory(HttpServletRequest request) throws ProfitMandiBusinessException{
                int userId = (int)request.getAttribute("userId");
                try{
                        return responseSender.ok(walletService.getUserWalletHistoryByUserId(userId));
                }catch(ProfitMandiBusinessException profitMandiBusinessException){
                        return responseSender.badRequest(profitMandiBusinessException);
                }
        }

}