Subversion Repositories SmartDukaan

Rev

Rev 21541 | Rev 21755 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21541 Rev 21749
Line 1... Line 1...
1
package com.spice.profitmandi.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.util.HashSet;
3
import javax.servlet.http.HttpServletRequest;
4
import java.util.Set;
-
 
5
 
4
 
-
 
5
 
-
 
6
import org.springframework.beans.factory.annotation.Autowired;
-
 
7
import org.springframework.http.ResponseEntity;
6
import org.springframework.stereotype.Controller;
8
import org.springframework.stereotype.Controller;
7
import org.springframework.ui.ModelMap;
9
import org.springframework.transaction.annotation.Transactional;
8
import org.springframework.web.bind.annotation.ModelAttribute;
10
import org.springframework.web.bind.annotation.RequestBody;
9
import org.springframework.web.bind.annotation.RequestMapping;
11
import org.springframework.web.bind.annotation.RequestMapping;
10
import org.springframework.web.bind.annotation.RequestMethod;
12
import org.springframework.web.bind.annotation.RequestMethod;
-
 
13
import org.springframework.web.bind.annotation.RequestParam;
11
 
14
 
-
 
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;
12
import com.spice.profitmandi.model.Car;
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;
13
 
22
 
14
@Controller
23
@Controller
-
 
24
@Transactional
15
public class CarController {
25
public class TagController {
16
 
26
 
-
 
27
	@Autowired
-
 
28
	TagRepository tagRepository;
-
 
29
	
-
 
30
	@Autowired
-
 
31
	ResponseSender<?> responseSender;
-
 
32
	
17
	@RequestMapping(value = "/cars", method = RequestMethod.GET)
33
	@RequestMapping(value = "/tag", method = RequestMethod.POST)
18
	public String init(@ModelAttribute("model") ModelMap model) {
34
	public ResponseEntity<?> createTag(HttpServletRequest request, @RequestBody CreateTagRequest createTagRequest) {
19
		Set<Car> cars = new HashSet<>();
35
		Tag tag = new Tag();
-
 
36
		tag.setActive(true);
-
 
37
		tag.setDescription(createTagRequest.getDescription());
20
		cars.add(new Car("Honda", "Civic"));
38
		tag.setLabel(createTagRequest.getLabel());
21
		cars.add(new Car("Toyota", "Camry"));
39
		tag.setType(createTagRequest.getTagType());
22
		cars.add(new Car("Nisaan", "Altima"));
40
		tag.setPinAll(createTagRequest.isPinAll());
23
	    model.addAttribute("cars", cars);
41
		tag.setUserAll(createTagRequest.isUserAll());
24
	    return "cars";
42
		tag.setCreatedBy(1);
-
 
43
		tagRepository.persist(tag);
-
 
44
		return responseSender.ok(ResponseCodeHolder.getMessage("TG_OK_1000"));
25
	}
45
	}
26
	
46
	
27
	@RequestMapping(value = "/index", method = RequestMethod.GET)
47
	@RequestMapping(value = "/tag/id", method = RequestMethod.GET)
-
 
48
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ID) int id) {
-
 
49
		try{
28
	public String indexPage(){
50
			return responseSender.ok(tagRepository.selectById(id));
-
 
51
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
29
		return "index";
52
			return responseSender.badRequest(profitMandiBusinessException);
-
 
53
		}
30
	}
54
	}
-
 
55
	
-
 
56
	@RequestMapping(value = "/tag/all", method = RequestMethod.GET)
-
 
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
	
31
}
61
}