| 21292 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDateTime;
|
|
|
4 |
import java.util.Map;
|
|
|
5 |
|
|
|
6 |
import javax.servlet.http.HttpServletRequest;
|
|
|
7 |
|
|
|
8 |
import org.slf4j.Logger;
|
|
|
9 |
import org.slf4j.LoggerFactory;
|
|
|
10 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
11 |
import org.springframework.http.HttpStatus;
|
|
|
12 |
import org.springframework.http.ResponseEntity;
|
|
|
13 |
import org.springframework.stereotype.Controller;
|
|
|
14 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
15 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
16 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
17 |
|
|
|
18 |
import com.spice.profitmandi.common.ResponseCodeHolder;
|
|
|
19 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
20 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
21 |
import com.spice.profitmandi.dao.entity.Shop;
|
|
|
22 |
import com.spice.profitmandi.dao.repository.RetailerRepository;
|
|
|
23 |
import com.spice.profitmandi.dao.repository.ShopRepository;
|
|
|
24 |
import com.spice.profitmandi.web.model.ProfitMandiResponse;
|
|
|
25 |
import com.spice.profitmandi.web.model.Response;
|
|
|
26 |
import com.spice.profitmandi.web.model.ResponseStatus;
|
|
|
27 |
|
|
|
28 |
@Controller
|
|
|
29 |
public class ShopController {
|
|
|
30 |
|
|
|
31 |
private static final Logger LOGGER=LoggerFactory.getLogger(ShopController.class);
|
|
|
32 |
|
|
|
33 |
@Autowired
|
|
|
34 |
ShopRepository shopRepository;
|
|
|
35 |
|
|
|
36 |
@Autowired
|
|
|
37 |
RetailerRepository retailerRepository;
|
|
|
38 |
|
|
|
39 |
@RequestMapping(value = ProfitMandiConstants.URL_SHOP, method=RequestMethod.POST)
|
| 21302 |
ashik.ali |
40 |
public ResponseEntity<?> createShop(HttpServletRequest request){
|
| 21292 |
ashik.ali |
41 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
42 |
@SuppressWarnings("unchecked")
|
|
|
43 |
final Map<String, Object> createShopMap = (Map<String, Object>)request.getAttribute(ProfitMandiConstants.CREATE_SHOP_MAP);
|
|
|
44 |
request.removeAttribute(ProfitMandiConstants.CREATE_SHOP_MAP);
|
|
|
45 |
|
|
|
46 |
try {
|
|
|
47 |
Shop shop = new Shop();
|
| 21426 |
ashik.ali |
48 |
shop.setRetailerId((int)createShopMap.get(ProfitMandiConstants.RETAILER_ID));
|
| 21390 |
ashik.ali |
49 |
//shop.setRetailer(retailer);
|
| 21292 |
ashik.ali |
50 |
shop.setName(createShopMap.get(ProfitMandiConstants.NAME).toString());
|
|
|
51 |
shop.setCreateTimestamp(LocalDateTime.now());
|
|
|
52 |
shop.setUpdateTimestamp(LocalDateTime.now());
|
|
|
53 |
shopRepository.persist(shop);
|
|
|
54 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1000"));
|
|
|
55 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
|
|
|
56 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
57 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
58 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
59 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
60 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ALL, method=RequestMethod.GET)
|
|
|
65 |
public ResponseEntity<?> getAll(HttpServletRequest request){
|
|
|
66 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 21426 |
ashik.ali |
67 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, shopRepository.selectAll());
|
|
|
68 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
| 21292 |
ashik.ali |
69 |
}
|
|
|
70 |
@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ID, method=RequestMethod.GET)
|
| 21431 |
ashik.ali |
71 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21292 |
ashik.ali |
72 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
73 |
try {
|
|
|
74 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, shopRepository.selectById(id));
|
|
|
75 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
76 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
77 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
78 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
79 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
80 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
@RequestMapping(value = ProfitMandiConstants.URL_SHOP_NAME, method=RequestMethod.GET)
|
|
|
85 |
public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){
|
|
|
86 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
87 |
try {
|
|
|
88 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, shopRepository.selectByName(name));
|
|
|
89 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
90 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
91 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
92 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
93 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
94 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ID, method=RequestMethod.DELETE)
|
| 21431 |
ashik.ali |
101 |
public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21292 |
ashik.ali |
102 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
103 |
try {
|
|
|
104 |
shopRepository.deleteById(id);
|
|
|
105 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
|
|
|
106 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
107 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
108 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
109 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
110 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
111 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
}
|