| 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.Retailer;
|
|
|
22 |
import com.spice.profitmandi.dao.entity.Shop;
|
|
|
23 |
import com.spice.profitmandi.dao.repository.RetailerRepository;
|
|
|
24 |
import com.spice.profitmandi.dao.repository.ShopRepository;
|
|
|
25 |
import com.spice.profitmandi.web.model.ProfitMandiResponse;
|
|
|
26 |
import com.spice.profitmandi.web.model.Response;
|
|
|
27 |
import com.spice.profitmandi.web.model.ResponseStatus;
|
|
|
28 |
|
|
|
29 |
@Controller
|
|
|
30 |
public class ShopController {
|
|
|
31 |
|
|
|
32 |
private static final Logger LOGGER=LoggerFactory.getLogger(ShopController.class);
|
|
|
33 |
|
|
|
34 |
@Autowired
|
|
|
35 |
ShopRepository shopRepository;
|
|
|
36 |
|
|
|
37 |
@Autowired
|
|
|
38 |
RetailerRepository retailerRepository;
|
|
|
39 |
|
|
|
40 |
@RequestMapping(value = ProfitMandiConstants.URL_SHOP, method=RequestMethod.POST)
|
| 21302 |
ashik.ali |
41 |
public ResponseEntity<?> createShop(HttpServletRequest request){
|
| 21292 |
ashik.ali |
42 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
43 |
@SuppressWarnings("unchecked")
|
|
|
44 |
final Map<String, Object> createShopMap = (Map<String, Object>)request.getAttribute(ProfitMandiConstants.CREATE_SHOP_MAP);
|
|
|
45 |
request.removeAttribute(ProfitMandiConstants.CREATE_SHOP_MAP);
|
|
|
46 |
|
|
|
47 |
try {
|
| 21390 |
ashik.ali |
48 |
final Retailer retailer = retailerRepository.selectById((int)createShopMap.get(ProfitMandiConstants.RETAILER_ID));
|
| 21292 |
ashik.ali |
49 |
Shop shop = new Shop();
|
| 21390 |
ashik.ali |
50 |
//shop.setRetailer(retailer);
|
| 21292 |
ashik.ali |
51 |
shop.setName(createShopMap.get(ProfitMandiConstants.NAME).toString());
|
|
|
52 |
shop.setCreateTimestamp(LocalDateTime.now());
|
|
|
53 |
shop.setUpdateTimestamp(LocalDateTime.now());
|
|
|
54 |
shopRepository.persist(shop);
|
|
|
55 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1000"));
|
|
|
56 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
|
|
|
57 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
58 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
59 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
60 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
61 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
62 |
}catch (Exception e) {
|
|
|
63 |
LOGGER.error("Internal Server Error : ",e);
|
|
|
64 |
final Response response=new Response("","","", e.getMessage());
|
|
|
65 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
|
|
|
66 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ALL, method=RequestMethod.GET)
|
|
|
71 |
public ResponseEntity<?> getAll(HttpServletRequest request){
|
|
|
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.selectAll());
|
|
|
75 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
76 |
}catch (Exception e) {
|
|
|
77 |
LOGGER.error("Internal Server Error : ",e);
|
|
|
78 |
final Response response=new Response("","","", e.getMessage());
|
|
|
79 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
|
|
|
80 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ID, method=RequestMethod.GET)
|
| 21390 |
ashik.ali |
84 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21292 |
ashik.ali |
85 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
86 |
try {
|
|
|
87 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, shopRepository.selectById(id));
|
|
|
88 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
89 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
90 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
91 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
92 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
93 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
94 |
}catch (Exception e) {
|
|
|
95 |
LOGGER.error("Internal Server Error : ",e);
|
|
|
96 |
final Response response=new Response("","","", e.getMessage());
|
|
|
97 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
|
|
|
98 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
@RequestMapping(value = ProfitMandiConstants.URL_SHOP_NAME, method=RequestMethod.GET)
|
|
|
103 |
public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){
|
|
|
104 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
105 |
try {
|
|
|
106 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, shopRepository.selectByName(name));
|
|
|
107 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
108 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
109 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
110 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
111 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
112 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
113 |
}catch (Exception e) {
|
|
|
114 |
LOGGER.error("Internal Server Error : ",e);
|
|
|
115 |
final Response response=new Response("","","", e.getMessage());
|
|
|
116 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
|
|
|
117 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
@RequestMapping(value = ProfitMandiConstants.URL_SHOP_ID, method=RequestMethod.DELETE)
|
| 21390 |
ashik.ali |
124 |
public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21292 |
ashik.ali |
125 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
126 |
try {
|
|
|
127 |
shopRepository.deleteById(id);
|
|
|
128 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
|
|
|
129 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
130 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
131 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
132 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
133 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
134 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
135 |
}catch (Exception e) {
|
|
|
136 |
LOGGER.error("Internal Server error : ",e);
|
|
|
137 |
final Response response=new Response("","","", e.getMessage());
|
|
|
138 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
|
|
|
139 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
}
|