Rev 21541 | Rev 21755 | 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.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.RequestBody;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.entity.fofo.Tag;import com.spice.profitmandi.dao.repository.fofo.TagRepository;import com.spice.profitmandi.web.request.CreateTagRequest;@Controller@Transactionalpublic class TagController {@AutowiredTagRepository tagRepository;@AutowiredResponseSender<?> responseSender;@RequestMapping(value = "/tag", method = RequestMethod.POST)public ResponseEntity<?> createTag(HttpServletRequest request, @RequestBody CreateTagRequest createTagRequest) {Tag tag = new Tag();tag.setActive(true);tag.setDescription(createTagRequest.getDescription());tag.setLabel(createTagRequest.getLabel());tag.setType(createTagRequest.getTagType());tag.setPinAll(createTagRequest.isPinAll());tag.setUserAll(createTagRequest.isUserAll());tag.setCreatedBy(1);tagRepository.persist(tag);return responseSender.ok(ResponseCodeHolder.getMessage("TG_OK_1000"));}@RequestMapping(value = "/tag/id", method = RequestMethod.GET)public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ID) int id) {try{return responseSender.ok(tagRepository.selectById(id));}catch(ProfitMandiBusinessException profitMandiBusinessException){return responseSender.badRequest(profitMandiBusinessException);}}@RequestMapping(value = "/tag/all", method = RequestMethod.GET)public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize) {return responseSender.ok(tagRepository.selectAll(pageNumber, pageSize));}}