Rev 21735 | Rev 22040 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.controller;import javax.servlet.http.HttpServletRequest;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;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 org.springframework.web.bind.annotation.RequestParam;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.model.UserCart;import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;import com.spice.profitmandi.dao.repository.user.AddressRepository;import io.swagger.annotations.ApiImplicitParam;import io.swagger.annotations.ApiImplicitParams;@Controller@Transactionalpublic class AddressController {@AutowiredResponseSender<?> responseSender;private static final Logger LOGGER=LoggerFactory.getLogger(AddressController.class);@AutowiredAddressRepository addressRepository;@AutowiredUserAccountRepository userAccountRepository;@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",required = true, dataType = "string", paramType = "header")})@RequestMapping(value = ProfitMandiConstants.URL_ADDRESS_ALL, method=RequestMethod.GET)public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize) throws Throwable{int userId = (int)request.getAttribute("userId");UserCart uc = userAccountRepository.getUserCart(userId);LOGGER.info("requested url : "+request.getRequestURL().toString());return responseSender.ok(addressRepository.selectAll(uc.getUserId(), pageNumber, pageSize));}@RequestMapping(value = ProfitMandiConstants.URL_ADDRESS_ID, method=RequestMethod.GET)public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){LOGGER.info("requested url : "+request.getRequestURL().toString());try {return responseSender.ok(addressRepository.selectById(id));}catch (ProfitMandiBusinessException profitMandiBusinessException) {LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);return responseSender.badRequest(profitMandiBusinessException);}}}