Subversion Repositories SmartDukaan

Rev

Rev 21390 | Rev 21431 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21292 ashik.ali 1
package com.spice.profitmandi.web.controller;
2
 
3
import java.time.LocalDateTime;
21390 ashik.ali 4
import java.util.Set;
21292 ashik.ali 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;
21309 ashik.ali 14
import org.springframework.web.bind.annotation.RequestBody;
21292 ashik.ali 15
import org.springframework.web.bind.annotation.RequestMapping;
16
import org.springframework.web.bind.annotation.RequestMethod;
17
import org.springframework.web.bind.annotation.RequestParam;
18
 
19
import com.spice.profitmandi.common.ResponseCodeHolder;
20
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
21
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21390 ashik.ali 22
import com.spice.profitmandi.dao.entity.Address;
23
import com.spice.profitmandi.dao.entity.Brand;
24
import com.spice.profitmandi.dao.entity.Document;
21292 ashik.ali 25
import com.spice.profitmandi.dao.entity.Retailer;
21390 ashik.ali 26
import com.spice.profitmandi.dao.entity.RetailerBrand;
27
import com.spice.profitmandi.dao.entity.RetailerRegisteredAddress;
28
import com.spice.profitmandi.dao.entity.Shop;
29
import com.spice.profitmandi.dao.entity.ShopAddress;
30
import com.spice.profitmandi.dao.repository.AddressRepository;
31
import com.spice.profitmandi.dao.repository.BrandRepository;
32
import com.spice.profitmandi.dao.repository.DocumentRepository;
21426 ashik.ali 33
import com.spice.profitmandi.dao.repository.RetailerAddressRepository;
21390 ashik.ali 34
import com.spice.profitmandi.dao.repository.RetailerBrandRepository;
35
import com.spice.profitmandi.dao.repository.RetailerRegisteredAddressRepository;
21292 ashik.ali 36
import com.spice.profitmandi.dao.repository.RetailerRepository;
21390 ashik.ali 37
import com.spice.profitmandi.dao.repository.ShopAddressRepository;
38
import com.spice.profitmandi.dao.repository.ShopRepository;
21292 ashik.ali 39
import com.spice.profitmandi.web.model.ProfitMandiResponse;
40
import com.spice.profitmandi.web.model.Response;
41
import com.spice.profitmandi.web.model.ResponseStatus;
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());
100
		retailer.setOther1(createRetailerRequest.getLineOfBusiness().isOther1());
101
		retailer.setOther2(createRetailerRequest.getLineOfBusiness().isOther2());
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
			}
126
			for(String brandName : brandNames){
127
				Brand brand =new Brand();
128
				brand.setName(brandName);
129
				if(!brandRepository.isExistByName(brandName)){
130
					brandRepository.persist(brand);
131
				}
132
				final RetailerBrand retailerBrand = new RetailerBrand();
133
				retailerBrand.setRetailerId(retailer.getId());
134
				retailerBrand.setBrandId(brand.getId());
135
				retailerBrandRepository.persist(retailerBrand);
136
			}
21426 ashik.ali 137
			final Address addressRetailer = this.createAddress(createRetailerRequest.getAddress());
138
 
21390 ashik.ali 139
			if(!addressRepository.isExist(addressRetailer)){
140
				addressRepository.persist(addressRetailer);
141
			}
142
			final RetailerRegisteredAddress retailerRegisteredAddress = new RetailerRegisteredAddress();
143
			retailerRegisteredAddress.setRetailerId(retailer.getId());
144
			retailerRegisteredAddress.setAddressId(addressRetailer.getId());
145
			try{
146
				retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
147
			}catch (ProfitMandiBusinessException profitMandiBusinessException) {
148
 
149
			}
150
 
21426 ashik.ali 151
			final Address addressShop = this.createAddress(createRetailerRequest.getShop().getAddress());
21390 ashik.ali 152
			if(!addressRepository.isExist(addressShop)){
153
				addressRepository.persist(addressShop);
154
				ShopAddress shopAddress = new ShopAddress();
155
				shopAddress.setShopId(shop.getId());
156
				shopAddress.setAddressId(addressShop.getId());
157
				try{
158
					shopAddressRepository.persist(shopAddress);
159
				}catch(ProfitMandiBusinessException profitMandiBusinessException){
160
 
161
				}
162
			}
163
			ShopAddress shopAddress = new ShopAddress();
164
			shopAddress.setShopId(shop.getId());
165
			shopAddress.setAddressId(addressShop.getId());
166
			try{
167
				shopAddressRepository.persist(shopAddress);
168
			}catch(ProfitMandiBusinessException profitMandiBusinessException){
169
 
170
			}
21309 ashik.ali 171
			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 172
			return new ResponseEntity<>(profitMandiResponse, HttpStatus.OK);
173
		}catch (ProfitMandiBusinessException pmbe) {
174
			LOGGER.error("ProfitMandi error: ", pmbe);
175
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
176
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
177
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
178
		}
179
	}
180
 
181
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ALL,method=RequestMethod.GET)
182
	public ResponseEntity<?> getAll(HttpServletRequest request){
183
		LOGGER.info("requested url : "+request.getRequestURL().toString());
21426 ashik.ali 184
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, retailerRepository.selectAll());
185
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
21292 ashik.ali 186
	}
187
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID, method=RequestMethod.GET)
21426 ashik.ali 188
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") long id){
21292 ashik.ali 189
		LOGGER.info("requested url : "+request.getRequestURL().toString());
190
		try {
191
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, retailerRepository.selectById(id));
192
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
193
		}catch (ProfitMandiBusinessException pmbe) {
194
			LOGGER.error("ProfitMandi error: ", pmbe);
195
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
196
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
197
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
198
		}
199
	}
200
 
201
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_NAME, method=RequestMethod.GET)
202
	public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){
203
		LOGGER.info("requested url : "+request.getRequestURL().toString());
204
		try {
205
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, retailerRepository.selectByName(name));
206
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
207
		}catch (ProfitMandiBusinessException pmbe) {
208
			LOGGER.error("ProfitMandi error: ", pmbe);
209
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
210
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
211
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
212
		}
213
	}
214
 
215
 
216
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID,method=RequestMethod.DELETE)
21426 ashik.ali 217
	public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") long id){
21292 ashik.ali 218
		LOGGER.info("requested url : "+request.getRequestURL().toString());
219
		try {
220
			retailerRepository.deleteById(id);
221
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
222
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
223
		}catch (ProfitMandiBusinessException pmbe) {
224
			LOGGER.error("ProfitMandi error: ", pmbe);
225
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
226
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
227
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
228
		}
229
	}
230
 
21426 ashik.ali 231
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ADD, method=RequestMethod.POST)
232
	public ResponseEntity<?> addShop(HttpServletRequest request, @RequestBody com.spice.profitmandi.web.req.Shop createShop, @RequestParam(name = "retailerId") long retailerId){
233
		LOGGER.info("requested url : "+request.getRequestURL().toString());
234
		try {
235
			Document document = documentRepository.selectById(createShop.getDocumentId());
236
			if(shopRepository.isExistByDocumentId(createShop.getDocumentId())){
237
				LOGGER.error("documet is already mapped with another shop");
238
				throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "");
239
			}
240
			retailerRepository.selectById(retailerId);
241
			Shop shop = new Shop();
242
			shop.setRetailerId(retailerId);
243
			Address address = this.createAddress(createShop.getAddress());
244
			addressRepository.persist(address);
245
			shop.setAddressId(address.getId());
246
			shop.setDocumentId(document.getId());
247
			shopRepository.persist(shop);
248
			ShopAddress shopAddress = new ShopAddress();
249
			shopAddress.setAddressId(address.getId());
250
			shopAddress.setShopId(shop.getId());
251
			shopAddressRepository.persist(shopAddress);
252
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
253
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
254
		}catch (ProfitMandiBusinessException pmbe) {
255
			LOGGER.error("ProfitMandi error: ", pmbe);
256
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
257
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
258
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
259
		}
260
	}
261
 
262
 
21302 ashik.ali 263
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_REMOVE, method=RequestMethod.DELETE)
21426 ashik.ali 264
	public ResponseEntity<?> removeShop(HttpServletRequest request, @RequestParam(name = "shopId") long shopId, @RequestParam(name = "retailerId") long retailerId){
21292 ashik.ali 265
		LOGGER.info("requested url : "+request.getRequestURL().toString());
266
		try {
267
			retailerRepository.removeShop(shopId, retailerId);
268
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
269
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
270
		}catch (ProfitMandiBusinessException pmbe) {
271
			LOGGER.error("ProfitMandi error: ", pmbe);
272
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
273
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
274
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
275
		}
276
	}
277
 
21426 ashik.ali 278
	private Address createAddress(com.spice.profitmandi.web.req.Address createAddress){
279
		Address address = new Address();
280
		address.setName(createAddress.getName());
281
		address.setLine1(createAddress.getLine1());
282
		address.setLine2(createAddress.getLine2());
283
		address.setLandmark(createAddress.getLandmark());
284
		address.setCity(createAddress.getCity());
285
		address.setState(createAddress.getState());
286
		address.setPinCode(createAddress.getPinCode());
287
		address.setCountry(createAddress.getCountry());
288
		address.setPhoneNumber(createAddress.getPhoneNumber());
289
		return address;
290
	}
291
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ADD, method=RequestMethod.POST)
292
	public ResponseEntity<?> addAddress(HttpServletRequest request, @RequestBody CreateRetailerAddressRequest createRetailerAddress){
293
		LOGGER.info("requested url : "+request.getRequestURL().toString());
294
		try {
295
			retailerRepository.addAddress(this.createAddress(createRetailerAddress.getAddress()), createRetailerAddress.getRetailerId());
296
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
297
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
298
		}catch (ProfitMandiBusinessException pmbe) {
299
			LOGGER.error("ProfitMandi error: ", pmbe);
300
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
301
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
302
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
303
		}
304
	}
21292 ashik.ali 305
 
21426 ashik.ali 306
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_REMOVE, method=RequestMethod.DELETE)
307
	public ResponseEntity<?> removeAddress(HttpServletRequest request, @RequestParam(name = "addressId") long addressId, @RequestParam(name = "retailerId") long retailerId){
308
		LOGGER.info("requested url : "+request.getRequestURL().toString());
309
		try {
310
			retailerRepository.removeAddress(addressId, retailerId);
311
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
312
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
313
		}catch (ProfitMandiBusinessException pmbe) {
314
			LOGGER.error("ProfitMandi error: ", pmbe);
315
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
316
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
317
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
318
		}
319
	}
320
 
321
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_ADD, method=RequestMethod.POST)
322
	public ResponseEntity<?> addBrand(HttpServletRequest request, @RequestBody RetailerAddBrandRequest retailerAddBrandRequest){
323
		LOGGER.info("requested url : "+request.getRequestURL().toString());
324
		try {
325
			Retailer retailer = retailerRepository.selectById(retailerAddBrandRequest.getRetailerId());
326
			for(String brandName : retailerAddBrandRequest.getBrandNames()){
327
				Brand brand = null;
328
				try{
329
					brand = brandRepository.selectByName(brandName);
330
				}catch(ProfitMandiBusinessException profitMandiBusinessException){
331
					brand = new Brand();
332
					brand.setName(brandName);
333
					brandRepository.persist(brand);
334
				}
335
				RetailerBrand retailerBrand = new RetailerBrand();
336
				retailerBrand.setBrandId(brand.getId());
337
				retailerBrand.setRetailerId(retailer.getId());
338
			}
339
			//retailerRepository.addAddress(this.createAddress(createRetailerAddress.getAddress()), createRetailerAddress.getRetailerId());
340
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
341
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
342
		}catch (ProfitMandiBusinessException pmbe) {
343
			LOGGER.error("ProfitMandi error: ", pmbe);
344
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
345
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
346
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
347
		}
348
	}
349
 
350
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_REMOVE, method=RequestMethod.DELETE)
351
	public ResponseEntity<?> removeBrand(HttpServletRequest request, @RequestParam(name = "brandId") long brandId, @RequestParam(name = "retailerId") long retailerId){
352
		LOGGER.info("requested url : "+request.getRequestURL().toString());
353
		try {
354
			brandRepository.selectById(brandId);
355
			retailerRepository.selectById(retailerId);
356
			retailerBrandRepository.deleteByRetailerId(retailerId, brandId);
357
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, ResponseCodeHolder.getMessage("API_OK_1001"));
358
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
359
		}catch (ProfitMandiBusinessException pmbe) {
360
			LOGGER.error("ProfitMandi error: ", pmbe);
361
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
362
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
363
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
364
		}
365
	}
366
 
367
 
368
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_DOCUMENT_DOCUMENT_ID, method=RequestMethod.GET)
369
	public ResponseEntity<?> getDocumentById(HttpServletRequest request, @RequestParam(name = "document") long documentId){
370
		LOGGER.info("requested url : "+request.getRequestURL().toString());
371
		try {
372
			retailerRepository.selectByDocumentId(documentId);
373
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, documentRepository.selectById(documentId));
374
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
375
		}catch (ProfitMandiBusinessException pmbe) {
376
			LOGGER.error("ProfitMandi error: ", pmbe);
377
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
378
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
379
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
380
		}
381
	}
382
 
383
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ALL, method=RequestMethod.GET)
384
	public ResponseEntity<?> getAllShops(HttpServletRequest request, @RequestParam(name = "id") long id){
385
		LOGGER.info("requested url : "+request.getRequestURL().toString());
386
		try {
387
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, shopRepository.selectByRetailerId(id));
388
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
389
		}catch (ProfitMandiBusinessException pmbe) {
390
			LOGGER.error("ProfitMandi error: ", pmbe);
391
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
392
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
393
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
394
		}
395
	}
396
 
397
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ALL, method=RequestMethod.GET)
398
	public ResponseEntity<?> getAllAddresses(HttpServletRequest request, @RequestParam(name = "id") long id){
399
		LOGGER.info("requested url : "+request.getRequestURL().toString());
400
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, retailerAddressRepository.selectAddressesByRetailerId(id));
401
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
402
	}
403
 
404
 
405
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_ALL, method=RequestMethod.GET)
406
	public ResponseEntity<?> getAllBrads(HttpServletRequest request, @RequestParam(name = "id") long id){
407
		LOGGER.info("requested url : "+request.getRequestURL().toString());
408
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, retailerBrandRepository.selectBrandNamesByRetailerId(id));
409
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
410
	}
411
 
21292 ashik.ali 412
}