Rev 21735 | Blame | 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.ResponseCodeHolder;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.dtr.RoleRepository;/*** @author ashikali**/@Controller@Transactionalpublic class RoleController {@AutowiredResponseSender<?> responseSender;private static final Logger LOGGER=LoggerFactory.getLogger(RoleController.class);@AutowiredRoleRepository roleRepository;@RequestMapping(value = ProfitMandiConstants.URL_ROLE_ALL,method=RequestMethod.GET)public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize){LOGGER.info("requested url : "+request.getRequestURL().toString());return responseSender.ok(roleRepository.selectAll(pageNumber, pageSize));}@RequestMapping(value = ProfitMandiConstants.URL_ROLE_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(roleRepository.selectById(id));}catch (ProfitMandiBusinessException profitMandiBusinessException) {LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);return responseSender.badRequest(profitMandiBusinessException);}}@RequestMapping(value = ProfitMandiConstants.URL_ROLE_TYPE,method=RequestMethod.GET)public ResponseEntity<?> getByType(HttpServletRequest request, @RequestParam(name = "type") String typeName){LOGGER.info("requested url : "+request.getRequestURL().toString());return responseSender.ok(roleRepository.selectByType(null));}@RequestMapping(value = ProfitMandiConstants.URL_ROLE_NAME,method=RequestMethod.GET)public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){LOGGER.info("requested url : "+request.getRequestURL().toString());try {return responseSender.ok(roleRepository.selectByName(name));}catch (ProfitMandiBusinessException profitMandiBusinessException) {LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);return responseSender.badRequest(profitMandiBusinessException);}}@RequestMapping(value = ProfitMandiConstants.URL_ROLE_ID,method=RequestMethod.DELETE)public ResponseEntity<?> deleteById(HttpServletRequest request, @RequestParam(name = "id") int id){LOGGER.info("requested url : "+request.getRequestURL().toString());try {roleRepository.deleteById(id);return responseSender.ok(ResponseCodeHolder.getMessage("ROL_OK_1001"));}catch (ProfitMandiBusinessException profitMandiBusinessException) {LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);return responseSender.badRequest(profitMandiBusinessException);}}}