| 21292 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDateTime;
|
|
|
4 |
|
|
|
5 |
import javax.servlet.http.HttpServletRequest;
|
|
|
6 |
|
|
|
7 |
import org.slf4j.Logger;
|
|
|
8 |
import org.slf4j.LoggerFactory;
|
|
|
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
10 |
import org.springframework.http.HttpStatus;
|
|
|
11 |
import org.springframework.http.ResponseEntity;
|
|
|
12 |
import org.springframework.stereotype.Controller;
|
| 21309 |
ashik.ali |
13 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 21292 |
ashik.ali |
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;
|
| 21390 |
ashik.ali |
21 |
import com.spice.profitmandi.dao.entity.Address;
|
|
|
22 |
import com.spice.profitmandi.dao.entity.Brand;
|
|
|
23 |
import com.spice.profitmandi.dao.entity.Document;
|
| 21292 |
ashik.ali |
24 |
import com.spice.profitmandi.dao.entity.Retailer;
|
| 21390 |
ashik.ali |
25 |
import com.spice.profitmandi.dao.entity.RetailerBrand;
|
|
|
26 |
import com.spice.profitmandi.dao.entity.RetailerRegisteredAddress;
|
|
|
27 |
import com.spice.profitmandi.dao.entity.Shop;
|
|
|
28 |
import com.spice.profitmandi.dao.entity.ShopAddress;
|
|
|
29 |
import com.spice.profitmandi.dao.repository.AddressRepository;
|
|
|
30 |
import com.spice.profitmandi.dao.repository.BrandRepository;
|
|
|
31 |
import com.spice.profitmandi.dao.repository.DocumentRepository;
|
| 21426 |
ashik.ali |
32 |
import com.spice.profitmandi.dao.repository.RetailerAddressRepository;
|
| 21390 |
ashik.ali |
33 |
import com.spice.profitmandi.dao.repository.RetailerBrandRepository;
|
|
|
34 |
import com.spice.profitmandi.dao.repository.RetailerRegisteredAddressRepository;
|
| 21292 |
ashik.ali |
35 |
import com.spice.profitmandi.dao.repository.RetailerRepository;
|
| 21390 |
ashik.ali |
36 |
import com.spice.profitmandi.dao.repository.ShopAddressRepository;
|
|
|
37 |
import com.spice.profitmandi.dao.repository.ShopRepository;
|
| 21292 |
ashik.ali |
38 |
import com.spice.profitmandi.web.model.ProfitMandiResponse;
|
|
|
39 |
import com.spice.profitmandi.web.model.Response;
|
|
|
40 |
import com.spice.profitmandi.web.model.ResponseStatus;
|
| 21431 |
ashik.ali |
41 |
import com.spice.profitmandi.web.req.Category;
|
| 21426 |
ashik.ali |
42 |
import com.spice.profitmandi.web.req.CreateRetailerAddressRequest;
|
|
|
43 |
import com.spice.profitmandi.web.req.CreateRetailerRequest;
|
|
|
44 |
import com.spice.profitmandi.web.req.RetailerAddBrandRequest;
|
| 21292 |
ashik.ali |
45 |
|
| 21302 |
ashik.ali |
46 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
47 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
48 |
import io.swagger.annotations.ApiOperation;
|
|
|
49 |
|
| 21292 |
ashik.ali |
50 |
@Controller
|
|
|
51 |
public class RetailerController {
|
|
|
52 |
|
|
|
53 |
private static final Logger LOGGER=LoggerFactory.getLogger(RetailerController.class);
|
|
|
54 |
|
|
|
55 |
@Autowired
|
|
|
56 |
RetailerRepository retailerRepository;
|
|
|
57 |
|
| 21390 |
ashik.ali |
58 |
@Autowired
|
|
|
59 |
BrandRepository brandRepository;
|
|
|
60 |
|
|
|
61 |
@Autowired
|
|
|
62 |
AddressRepository addressRepository;
|
|
|
63 |
|
|
|
64 |
@Autowired
|
|
|
65 |
DocumentRepository documentRepository;
|
|
|
66 |
|
|
|
67 |
@Autowired
|
|
|
68 |
ShopRepository shopRepository;
|
|
|
69 |
|
|
|
70 |
@Autowired
|
|
|
71 |
RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
|
|
72 |
|
|
|
73 |
@Autowired
|
| 21426 |
ashik.ali |
74 |
RetailerAddressRepository retailerAddressRepository;
|
|
|
75 |
|
|
|
76 |
@Autowired
|
| 21390 |
ashik.ali |
77 |
ShopAddressRepository shopAddressRepository;
|
|
|
78 |
|
|
|
79 |
@Autowired
|
|
|
80 |
RetailerBrandRepository retailerBrandRepository;
|
|
|
81 |
|
| 21302 |
ashik.ali |
82 |
@ApiImplicitParams({
|
|
|
83 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
84 |
required = true, dataType = "string", paramType = "header")
|
|
|
85 |
})
|
| 21309 |
ashik.ali |
86 |
|
| 21302 |
ashik.ali |
87 |
@ApiOperation(value = "Create Retailer")
|
|
|
88 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER, method=RequestMethod.POST)
|
| 21426 |
ashik.ali |
89 |
public ResponseEntity<?> createRetailer(HttpServletRequest request, @RequestBody CreateRetailerRequest createRetailerRequest){
|
| 21292 |
ashik.ali |
90 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 21390 |
ashik.ali |
91 |
Retailer retailer = new Retailer();
|
| 21426 |
ashik.ali |
92 |
retailer.setName(createRetailerRequest.getName());
|
|
|
93 |
retailer.setNumber(createRetailerRequest.getNumber());
|
|
|
94 |
retailer.setType(createRetailerRequest.getType());
|
|
|
95 |
retailer.setMonthlySaleValue(createRetailerRequest.getMonthlySaleValue());
|
|
|
96 |
retailer.setSmartphoneSaleValue(createRetailerRequest.getSmartphoneSaleValue());
|
|
|
97 |
retailer.setRecharge(createRetailerRequest.getLineOfBusiness().isRecharge());
|
|
|
98 |
retailer.setMobile(createRetailerRequest.getLineOfBusiness().isMobile());
|
|
|
99 |
retailer.setAccessories(createRetailerRequest.getLineOfBusiness().isAccessories());
|
| 21431 |
ashik.ali |
100 |
retailer.setOther1(createRetailerRequest.getLineOfBusiness().getOther1());
|
|
|
101 |
retailer.setOther2(createRetailerRequest.getLineOfBusiness().getOther2());
|
|
|
102 |
//Set<String> brandNames = createRetailerRequest.getBrandNames();
|
| 21390 |
ashik.ali |
103 |
|
| 21292 |
ashik.ali |
104 |
try {
|
| 21390 |
ashik.ali |
105 |
|
| 21426 |
ashik.ali |
106 |
Document retailerDocument = documentRepository.selectById(createRetailerRequest.getDocumentId());
|
| 21390 |
ashik.ali |
107 |
if(retailerRepository.isExistByDocumentId(retailerDocument.getId())){
|
|
|
108 |
LOGGER.error("documet is already mapped with another retailer");
|
|
|
109 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, retailerDocument.getId(), "");
|
|
|
110 |
}
|
|
|
111 |
retailer.setDocumentId(retailerDocument.getId());
|
| 21292 |
ashik.ali |
112 |
retailerRepository.persist(retailer);
|
| 21426 |
ashik.ali |
113 |
final Document shopDocument = documentRepository.selectById(createRetailerRequest.getShop().getDocumentId());
|
| 21390 |
ashik.ali |
114 |
if(shopRepository.isExistByDocumentId(shopDocument.getId())){
|
|
|
115 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, shopDocument.getId(), "");
|
|
|
116 |
}
|
|
|
117 |
Shop shop = new Shop();
|
| 21426 |
ashik.ali |
118 |
shop.setName(createRetailerRequest.getShop().getName());
|
| 21390 |
ashik.ali |
119 |
shop.setDocumentId(shopDocument.getId());
|
|
|
120 |
shop.setRetailerId(retailer.getId());
|
|
|
121 |
try{
|
|
|
122 |
shopRepository.persist(shop);
|
|
|
123 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
124 |
|
|
|
125 |
}
|
| 21431 |
ashik.ali |
126 |
for(Category category : createRetailerRequest.getCategories()){
|
|
|
127 |
for(com.spice.profitmandi.web.req.Brand brandModel : category.getBrands()){
|
|
|
128 |
Brand brand = brandRepository.selectByName(brandModel.getName());
|
|
|
129 |
final RetailerBrand retailerBrand = new RetailerBrand();
|
|
|
130 |
retailerBrand.setRetailerId(retailer.getId());
|
|
|
131 |
retailerBrand.setBrandId(brand.getId());
|
|
|
132 |
retailerBrandRepository.persist(retailerBrand);
|
| 21390 |
ashik.ali |
133 |
}
|
|
|
134 |
}
|
| 21426 |
ashik.ali |
135 |
final Address addressRetailer = this.createAddress(createRetailerRequest.getAddress());
|
|
|
136 |
|
| 21390 |
ashik.ali |
137 |
if(!addressRepository.isExist(addressRetailer)){
|
|
|
138 |
addressRepository.persist(addressRetailer);
|
|
|
139 |
}
|
|
|
140 |
final RetailerRegisteredAddress retailerRegisteredAddress = new RetailerRegisteredAddress();
|
|
|
141 |
retailerRegisteredAddress.setRetailerId(retailer.getId());
|
|
|
142 |
retailerRegisteredAddress.setAddressId(addressRetailer.getId());
|
|
|
143 |
try{
|
|
|
144 |
retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
|
|
|
145 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
146 |
|
|
|
147 |
}
|
|
|
148 |
|
| 21426 |
ashik.ali |
149 |
final Address addressShop = this.createAddress(createRetailerRequest.getShop().getAddress());
|
| 21390 |
ashik.ali |
150 |
if(!addressRepository.isExist(addressShop)){
|
|
|
151 |
addressRepository.persist(addressShop);
|
|
|
152 |
ShopAddress shopAddress = new ShopAddress();
|
|
|
153 |
shopAddress.setShopId(shop.getId());
|
|
|
154 |
shopAddress.setAddressId(addressShop.getId());
|
|
|
155 |
try{
|
|
|
156 |
shopAddressRepository.persist(shopAddress);
|
|
|
157 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
158 |
|
|
|
159 |
}
|
|
|
160 |
}
|
|
|
161 |
ShopAddress shopAddress = new ShopAddress();
|
|
|
162 |
shopAddress.setShopId(shop.getId());
|
|
|
163 |
shopAddress.setAddressId(addressShop.getId());
|
|
|
164 |
try{
|
|
|
165 |
shopAddressRepository.persist(shopAddress);
|
|
|
166 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
167 |
|
|
|
168 |
}
|
| 21309 |
ashik.ali |
169 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("RTLR_OK_1000"));
|
| 21292 |
ashik.ali |
170 |
return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
|
|
|
171 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
172 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
173 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
174 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
175 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
176 |
}
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ALL,method=RequestMethod.GET)
|
|
|
180 |
public ResponseEntity<?> getAll(HttpServletRequest request){
|
|
|
181 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 21426 |
ashik.ali |
182 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, retailerRepository.selectAll());
|
|
|
183 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
| 21292 |
ashik.ali |
184 |
}
|
|
|
185 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID, method=RequestMethod.GET)
|
| 21431 |
ashik.ali |
186 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21292 |
ashik.ali |
187 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
188 |
try {
|
|
|
189 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, retailerRepository.selectById(id));
|
|
|
190 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
191 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
192 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
193 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
194 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
195 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
196 |
}
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_NAME, method=RequestMethod.GET)
|
|
|
200 |
public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){
|
|
|
201 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
202 |
try {
|
|
|
203 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, retailerRepository.selectByName(name));
|
|
|
204 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
205 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
206 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
207 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
208 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
209 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
210 |
}
|
|
|
211 |
}
|
|
|
212 |
|
|
|
213 |
|
|
|
214 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID,method=RequestMethod.DELETE)
|
| 21431 |
ashik.ali |
215 |
public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21292 |
ashik.ali |
216 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
217 |
try {
|
|
|
218 |
retailerRepository.deleteById(id);
|
|
|
219 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
|
|
|
220 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
221 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
222 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
223 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
224 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
225 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
226 |
}
|
|
|
227 |
}
|
|
|
228 |
|
| 21426 |
ashik.ali |
229 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ADD, method=RequestMethod.POST)
|
| 21431 |
ashik.ali |
230 |
public ResponseEntity<?> addShop(HttpServletRequest request, @RequestBody com.spice.profitmandi.web.req.Shop createShop, @RequestParam(name = "retailerId") int retailerId){
|
| 21426 |
ashik.ali |
231 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
232 |
try {
|
|
|
233 |
Document document = documentRepository.selectById(createShop.getDocumentId());
|
|
|
234 |
if(shopRepository.isExistByDocumentId(createShop.getDocumentId())){
|
|
|
235 |
LOGGER.error("documet is already mapped with another shop");
|
|
|
236 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "");
|
|
|
237 |
}
|
|
|
238 |
retailerRepository.selectById(retailerId);
|
|
|
239 |
Shop shop = new Shop();
|
|
|
240 |
shop.setRetailerId(retailerId);
|
|
|
241 |
Address address = this.createAddress(createShop.getAddress());
|
|
|
242 |
addressRepository.persist(address);
|
|
|
243 |
shop.setAddressId(address.getId());
|
|
|
244 |
shop.setDocumentId(document.getId());
|
|
|
245 |
shopRepository.persist(shop);
|
|
|
246 |
ShopAddress shopAddress = new ShopAddress();
|
|
|
247 |
shopAddress.setAddressId(address.getId());
|
|
|
248 |
shopAddress.setShopId(shop.getId());
|
|
|
249 |
shopAddressRepository.persist(shopAddress);
|
|
|
250 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
|
|
|
251 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
252 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
253 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
254 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
255 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
256 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
257 |
}
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
|
| 21302 |
ashik.ali |
261 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_REMOVE, method=RequestMethod.DELETE)
|
| 21431 |
ashik.ali |
262 |
public ResponseEntity<?> removeShop(HttpServletRequest request, @RequestParam(name = "shopId") int shopId, @RequestParam(name = "retailerId") int retailerId){
|
| 21292 |
ashik.ali |
263 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
264 |
try {
|
|
|
265 |
retailerRepository.removeShop(shopId, retailerId);
|
|
|
266 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
|
|
|
267 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
268 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
269 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
270 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
271 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
272 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
273 |
}
|
|
|
274 |
}
|
|
|
275 |
|
| 21426 |
ashik.ali |
276 |
private Address createAddress(com.spice.profitmandi.web.req.Address createAddress){
|
|
|
277 |
Address address = new Address();
|
|
|
278 |
address.setName(createAddress.getName());
|
|
|
279 |
address.setLine1(createAddress.getLine1());
|
|
|
280 |
address.setLine2(createAddress.getLine2());
|
|
|
281 |
address.setLandmark(createAddress.getLandmark());
|
|
|
282 |
address.setCity(createAddress.getCity());
|
|
|
283 |
address.setState(createAddress.getState());
|
|
|
284 |
address.setPinCode(createAddress.getPinCode());
|
|
|
285 |
address.setCountry(createAddress.getCountry());
|
|
|
286 |
address.setPhoneNumber(createAddress.getPhoneNumber());
|
|
|
287 |
return address;
|
|
|
288 |
}
|
|
|
289 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ADD, method=RequestMethod.POST)
|
|
|
290 |
public ResponseEntity<?> addAddress(HttpServletRequest request, @RequestBody CreateRetailerAddressRequest createRetailerAddress){
|
|
|
291 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
292 |
try {
|
|
|
293 |
retailerRepository.addAddress(this.createAddress(createRetailerAddress.getAddress()), createRetailerAddress.getRetailerId());
|
|
|
294 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
|
|
|
295 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
296 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
297 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
298 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
299 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
300 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
301 |
}
|
|
|
302 |
}
|
| 21292 |
ashik.ali |
303 |
|
| 21426 |
ashik.ali |
304 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_REMOVE, method=RequestMethod.DELETE)
|
| 21431 |
ashik.ali |
305 |
public ResponseEntity<?> removeAddress(HttpServletRequest request, @RequestParam(name = "addressId") int addressId, @RequestParam(name = "retailerId") int retailerId){
|
| 21426 |
ashik.ali |
306 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
307 |
try {
|
|
|
308 |
retailerRepository.removeAddress(addressId, retailerId);
|
|
|
309 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
|
|
|
310 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
311 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
312 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
313 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
314 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
315 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
316 |
}
|
|
|
317 |
}
|
|
|
318 |
|
|
|
319 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_ADD, method=RequestMethod.POST)
|
|
|
320 |
public ResponseEntity<?> addBrand(HttpServletRequest request, @RequestBody RetailerAddBrandRequest retailerAddBrandRequest){
|
|
|
321 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
322 |
try {
|
|
|
323 |
Retailer retailer = retailerRepository.selectById(retailerAddBrandRequest.getRetailerId());
|
|
|
324 |
for(String brandName : retailerAddBrandRequest.getBrandNames()){
|
|
|
325 |
Brand brand = null;
|
|
|
326 |
try{
|
|
|
327 |
brand = brandRepository.selectByName(brandName);
|
|
|
328 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
329 |
brand = new Brand();
|
|
|
330 |
brand.setName(brandName);
|
|
|
331 |
brandRepository.persist(brand);
|
|
|
332 |
}
|
|
|
333 |
RetailerBrand retailerBrand = new RetailerBrand();
|
|
|
334 |
retailerBrand.setBrandId(brand.getId());
|
|
|
335 |
retailerBrand.setRetailerId(retailer.getId());
|
|
|
336 |
}
|
|
|
337 |
//retailerRepository.addAddress(this.createAddress(createRetailerAddress.getAddress()), createRetailerAddress.getRetailerId());
|
|
|
338 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
|
|
|
339 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
340 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
341 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
342 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
343 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
344 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
345 |
}
|
|
|
346 |
}
|
|
|
347 |
|
|
|
348 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_REMOVE, method=RequestMethod.DELETE)
|
| 21431 |
ashik.ali |
349 |
public ResponseEntity<?> removeBrand(HttpServletRequest request, @RequestParam(name = "brandId") int brandId, @RequestParam(name = "retailerId") int retailerId){
|
| 21426 |
ashik.ali |
350 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
351 |
try {
|
|
|
352 |
brandRepository.selectById(brandId);
|
|
|
353 |
retailerRepository.selectById(retailerId);
|
|
|
354 |
retailerBrandRepository.deleteByRetailerId(retailerId, brandId);
|
|
|
355 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
|
|
|
356 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
357 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
358 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
359 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
360 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
361 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
362 |
}
|
|
|
363 |
}
|
|
|
364 |
|
|
|
365 |
|
|
|
366 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_DOCUMENT_DOCUMENT_ID, method=RequestMethod.GET)
|
| 21431 |
ashik.ali |
367 |
public ResponseEntity<?> getDocumentById(HttpServletRequest request, @RequestParam(name = "document") int documentId){
|
| 21426 |
ashik.ali |
368 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
369 |
try {
|
|
|
370 |
retailerRepository.selectByDocumentId(documentId);
|
|
|
371 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, documentRepository.selectById(documentId));
|
|
|
372 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
373 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
374 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
375 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
376 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
377 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
378 |
}
|
|
|
379 |
}
|
|
|
380 |
|
|
|
381 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ALL, method=RequestMethod.GET)
|
| 21431 |
ashik.ali |
382 |
public ResponseEntity<?> getAllShops(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21426 |
ashik.ali |
383 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
384 |
try {
|
|
|
385 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, shopRepository.selectByRetailerId(id));
|
|
|
386 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
387 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
388 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
389 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
390 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
391 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
392 |
}
|
|
|
393 |
}
|
|
|
394 |
|
|
|
395 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ALL, method=RequestMethod.GET)
|
| 21431 |
ashik.ali |
396 |
public ResponseEntity<?> getAllAddresses(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21426 |
ashik.ali |
397 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
398 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, retailerAddressRepository.selectAddressesByRetailerId(id));
|
|
|
399 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
400 |
}
|
|
|
401 |
|
|
|
402 |
|
|
|
403 |
@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_ALL, method=RequestMethod.GET)
|
| 21431 |
ashik.ali |
404 |
public ResponseEntity<?> getAllBrads(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 21426 |
ashik.ali |
405 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
406 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, retailerBrandRepository.selectBrandNamesByRetailerId(id));
|
|
|
407 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
408 |
}
|
|
|
409 |
|
| 21292 |
ashik.ali |
410 |
}
|