| 21749 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
| 21541 |
ashik.ali |
2 |
|
| 21749 |
ashik.ali |
3 |
import javax.servlet.http.HttpServletRequest;
|
| 21541 |
ashik.ali |
4 |
|
| 21749 |
ashik.ali |
5 |
|
|
|
6 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
7 |
import org.springframework.http.ResponseEntity;
|
| 21541 |
ashik.ali |
8 |
import org.springframework.stereotype.Controller;
|
| 21749 |
ashik.ali |
9 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
10 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 21541 |
ashik.ali |
11 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
12 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21749 |
ashik.ali |
13 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21541 |
ashik.ali |
14 |
|
| 21749 |
ashik.ali |
15 |
import com.spice.profitmandi.common.ResponseCodeHolder;
|
|
|
16 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
17 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
18 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
|
|
19 |
import com.spice.profitmandi.dao.entity.fofo.Tag;
|
|
|
20 |
import com.spice.profitmandi.dao.repository.fofo.TagRepository;
|
|
|
21 |
import com.spice.profitmandi.web.request.CreateTagRequest;
|
| 21541 |
ashik.ali |
22 |
|
|
|
23 |
@Controller
|
| 21749 |
ashik.ali |
24 |
@Transactional
|
|
|
25 |
public class TagController {
|
| 21541 |
ashik.ali |
26 |
|
| 21749 |
ashik.ali |
27 |
@Autowired
|
|
|
28 |
TagRepository tagRepository;
|
|
|
29 |
|
|
|
30 |
@Autowired
|
|
|
31 |
ResponseSender<?> responseSender;
|
|
|
32 |
|
| 21755 |
ashik.ali |
33 |
@RequestMapping(value = ProfitMandiConstants.URL_TAG, method = RequestMethod.POST)
|
| 21749 |
ashik.ali |
34 |
public ResponseEntity<?> createTag(HttpServletRequest request, @RequestBody CreateTagRequest createTagRequest) {
|
|
|
35 |
Tag tag = new Tag();
|
|
|
36 |
tag.setActive(true);
|
|
|
37 |
tag.setDescription(createTagRequest.getDescription());
|
|
|
38 |
tag.setLabel(createTagRequest.getLabel());
|
|
|
39 |
tag.setType(createTagRequest.getTagType());
|
|
|
40 |
tag.setPinAll(createTagRequest.isPinAll());
|
|
|
41 |
tag.setUserAll(createTagRequest.isUserAll());
|
|
|
42 |
tag.setCreatedBy(1);
|
|
|
43 |
tagRepository.persist(tag);
|
|
|
44 |
return responseSender.ok(ResponseCodeHolder.getMessage("TG_OK_1000"));
|
| 21541 |
ashik.ali |
45 |
}
|
|
|
46 |
|
| 21755 |
ashik.ali |
47 |
@RequestMapping(value = ProfitMandiConstants.URL_TAG_ID, method = RequestMethod.GET)
|
| 21749 |
ashik.ali |
48 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ID) int id) {
|
|
|
49 |
try{
|
|
|
50 |
return responseSender.ok(tagRepository.selectById(id));
|
|
|
51 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
52 |
return responseSender.badRequest(profitMandiBusinessException);
|
|
|
53 |
}
|
| 21541 |
ashik.ali |
54 |
}
|
| 21749 |
ashik.ali |
55 |
|
| 21755 |
ashik.ali |
56 |
@RequestMapping(value = ProfitMandiConstants.URL_TAG_ALL, method = RequestMethod.GET)
|
| 21749 |
ashik.ali |
57 |
public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize) {
|
|
|
58 |
return responseSender.ok(tagRepository.selectAll(pageNumber, pageSize));
|
|
|
59 |
}
|
|
|
60 |
|
| 21755 |
ashik.ali |
61 |
@RequestMapping(value = ProfitMandiConstants.URL_TAG_ACTIVE, method = RequestMethod.PUT)
|
|
|
62 |
public ResponseEntity<?> setActive(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ID) int id) {
|
|
|
63 |
try {
|
|
|
64 |
tagRepository.updateActiveById(id, true);
|
|
|
65 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
66 |
return responseSender.badRequest(profitMandiBusinessException);
|
|
|
67 |
}
|
|
|
68 |
return responseSender.ok(ResponseCodeHolder.getMessage("TG_OK_1001"));
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
@RequestMapping(value = ProfitMandiConstants.URL_TAG_INACTIVE, method = RequestMethod.PUT)
|
|
|
72 |
public ResponseEntity<?> setInActive(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ID) int id) {
|
|
|
73 |
try {
|
|
|
74 |
tagRepository.updateActiveById(id, false);
|
|
|
75 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
76 |
return responseSender.badRequest(profitMandiBusinessException);
|
|
|
77 |
}
|
|
|
78 |
return responseSender.ok(ResponseCodeHolder.getMessage("TG_OK_1002"));
|
|
|
79 |
}
|
|
|
80 |
|
| 21541 |
ashik.ali |
81 |
}
|