Subversion Repositories SmartDukaan

Rev

Rev 21740 | Rev 21769 | 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
 
21448 ashik.ali 3
import java.util.Set;
4
 
21292 ashik.ali 5
import javax.servlet.http.HttpServletRequest;
6
 
21463 ashik.ali 7
import org.apache.thrift.TException;
8
import org.apache.thrift.transport.TTransportException;
21292 ashik.ali 9
import org.slf4j.Logger;
10
import org.slf4j.LoggerFactory;
11
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.http.ResponseEntity;
13
import org.springframework.stereotype.Controller;
21692 amit.gupta 14
import org.springframework.transaction.annotation.Transactional;
21309 ashik.ali 15
import org.springframework.web.bind.annotation.RequestBody;
21292 ashik.ali 16
import org.springframework.web.bind.annotation.RequestMapping;
17
import org.springframework.web.bind.annotation.RequestMethod;
18
import org.springframework.web.bind.annotation.RequestParam;
19
 
20
import com.spice.profitmandi.common.ResponseCodeHolder;
21
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
22
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21463 ashik.ali 23
import com.spice.profitmandi.common.model.UserInfo;
21740 ashik.ali 24
import com.spice.profitmandi.common.web.util.ResponseSender;
21735 ashik.ali 25
import com.spice.profitmandi.dao.entity.dtr.Brand;
26
import com.spice.profitmandi.dao.entity.dtr.Document;
27
import com.spice.profitmandi.dao.entity.dtr.Retailer;
28
import com.spice.profitmandi.dao.entity.dtr.RetailerBrand;
29
import com.spice.profitmandi.dao.entity.dtr.RetailerRegisteredAddress;
30
import com.spice.profitmandi.dao.entity.dtr.Shop;
31
import com.spice.profitmandi.dao.entity.dtr.ShopAddress;
32
import com.spice.profitmandi.dao.entity.dtr.User;
21768 amit.gupta 33
import com.spice.profitmandi.dao.entity.dtr.UserAccounts;
34
import com.spice.profitmandi.dao.entity.dtr.UserRole;
21735 ashik.ali 35
import com.spice.profitmandi.dao.entity.user.Address;
21768 amit.gupta 36
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
37
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
21735 ashik.ali 38
import com.spice.profitmandi.dao.repository.dtr.BrandRepository;
39
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
40
import com.spice.profitmandi.dao.repository.dtr.RetailerAddressRepository;
41
import com.spice.profitmandi.dao.repository.dtr.RetailerBrandRepository;
42
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
43
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
44
import com.spice.profitmandi.dao.repository.dtr.ShopAddressRepository;
45
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
21768 amit.gupta 46
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
21735 ashik.ali 47
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
21768 amit.gupta 48
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
21735 ashik.ali 49
import com.spice.profitmandi.dao.repository.user.AddressRepository;
21463 ashik.ali 50
import com.spice.profitmandi.thrift.clients.UserClient;
21431 ashik.ali 51
import com.spice.profitmandi.web.req.Category;
21426 ashik.ali 52
import com.spice.profitmandi.web.req.CreateRetailerAddressRequest;
53
import com.spice.profitmandi.web.req.CreateRetailerRequest;
54
import com.spice.profitmandi.web.req.RetailerAddBrandRequest;
21292 ashik.ali 55
 
21463 ashik.ali 56
import in.shop2020.model.v1.user.Sex;
57
import in.shop2020.model.v1.user.UserContextException;
21302 ashik.ali 58
import io.swagger.annotations.ApiImplicitParam;
59
import io.swagger.annotations.ApiImplicitParams;
60
import io.swagger.annotations.ApiOperation;
61
 
21292 ashik.ali 62
@Controller
21692 amit.gupta 63
@Transactional
21292 ashik.ali 64
public class RetailerController {
65
 
66
	private static final Logger LOGGER=LoggerFactory.getLogger(RetailerController.class);
67
 
68
	@Autowired
21463 ashik.ali 69
	UserRepository userRepository;
70
 
71
	@Autowired
21768 amit.gupta 72
	UserRoleRepository userRoleRepository;
73
 
74
	@Autowired
21440 ashik.ali 75
	ResponseSender<?> responseSender;
76
 
77
	@Autowired
21292 ashik.ali 78
	RetailerRepository retailerRepository;
79
 
21390 ashik.ali 80
	@Autowired
81
	BrandRepository brandRepository;
82
 
83
	@Autowired
84
	AddressRepository addressRepository;
85
 
86
	@Autowired
87
	DocumentRepository documentRepository;
88
 
89
	@Autowired
90
	ShopRepository shopRepository;
91
 
92
	@Autowired
21768 amit.gupta 93
	UserAccountRepository userAccountRepository;
94
 
95
	@Autowired
21390 ashik.ali 96
	RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
97
 
98
	@Autowired
21426 ashik.ali 99
	RetailerAddressRepository retailerAddressRepository;
100
 
101
	@Autowired
21390 ashik.ali 102
	ShopAddressRepository shopAddressRepository;
103
 
104
	@Autowired
105
	RetailerBrandRepository retailerBrandRepository;
106
 
21302 ashik.ali 107
	@ApiImplicitParams({
108
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
109
				required = true, dataType = "string", paramType = "header")
110
	})
21309 ashik.ali 111
 
21302 ashik.ali 112
	@ApiOperation(value = "Create Retailer")
113
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER, method=RequestMethod.POST)
21426 ashik.ali 114
	public ResponseEntity<?> createRetailer(HttpServletRequest request, @RequestBody CreateRetailerRequest createRetailerRequest){
21292 ashik.ali 115
		LOGGER.info("requested url : "+request.getRequestURL().toString());
21440 ashik.ali 116
		try{
21691 amit.gupta 117
			UserInfo userInfo = (UserInfo)request.getAttribute("userInfo");
21463 ashik.ali 118
			User user = userRepository.selectById(userInfo.getUserId());
21768 amit.gupta 119
			this.createRetailer(user, createRetailerRequest);
21440 ashik.ali 120
			return responseSender.ok(ResponseCodeHolder.getMessage("RTLR_OK_1000"));
121
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
122
			LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
123
			return responseSender.badRequest(profitMandiBusinessException);
124
		}
125
	}
126
 
21768 amit.gupta 127
	private void createRetailer(User user, CreateRetailerRequest createRetailerRequest) 
21440 ashik.ali 128
			throws ProfitMandiBusinessException{
21390 ashik.ali 129
		Retailer retailer = new Retailer();
21426 ashik.ali 130
		retailer.setName(createRetailerRequest.getName());
131
		retailer.setNumber(createRetailerRequest.getNumber());
132
		retailer.setType(createRetailerRequest.getType());
133
		retailer.setMonthlySaleValue(createRetailerRequest.getMonthlySaleValue());
134
		retailer.setSmartphoneSaleValue(createRetailerRequest.getSmartphoneSaleValue());
135
		retailer.setRecharge(createRetailerRequest.getLineOfBusiness().isRecharge());
136
		retailer.setMobile(createRetailerRequest.getLineOfBusiness().isMobile());
137
		retailer.setAccessories(createRetailerRequest.getLineOfBusiness().isAccessories());
21431 ashik.ali 138
		retailer.setOther1(createRetailerRequest.getLineOfBusiness().getOther1());
139
		retailer.setOther2(createRetailerRequest.getLineOfBusiness().getOther2());
21440 ashik.ali 140
		Document retailerDocument = documentRepository.selectById(createRetailerRequest.getDocumentId());
141
		if(retailerRepository.isExistByDocumentId(retailerDocument.getId())){
142
			LOGGER.error("documet is already mapped with another retailer");
21448 ashik.ali 143
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, retailerDocument.getId(), "DCMNT_1000");
21440 ashik.ali 144
		}
145
		retailer.setDocumentId(retailerDocument.getId());
146
		final Document shopDocument = documentRepository.selectById(createRetailerRequest.getShop().getDocumentId());
147
		if(shopRepository.isExistByDocumentId(shopDocument.getId())){
21448 ashik.ali 148
			throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, shopDocument.getId(), "DCMNT_1000");
21440 ashik.ali 149
		}
21463 ashik.ali 150
		documentRepository.markDocumentAsPersisted(retailerDocument.getId());
21448 ashik.ali 151
		if(retailerRepository.isExistByNumberAndType(retailer.getNumber(), retailer.getType())){
152
			throw new ProfitMandiBusinessException(ProfitMandiConstants.NUMBER + ", " + ProfitMandiConstants.TYPE, retailer.getNumber() + ", " + retailer.getType(), "RTLR_1001");
153
		}
21463 ashik.ali 154
		documentRepository.markDocumentAsPersisted(shopDocument.getId());
21768 amit.gupta 155
		in.shop2020.model.v1.user.User saholicUser = this.createSaholicUser(user.getEmailId()); 
156
		retailer.setId((int)saholicUser.getUserId());
21440 ashik.ali 157
		retailerRepository.persist(retailer);
158
		Shop shop = new Shop();
159
		shop.setName(createRetailerRequest.getShop().getName());
160
		shop.setDocumentId(shopDocument.getId());
161
		shop.setRetailerId(retailer.getId());
162
		shopRepository.persist(shop);
21448 ashik.ali 163
		this.addBrandWithRetailer(retailer.getId(), createRetailerRequest.getCategories());
21440 ashik.ali 164
		final Address addressRetailer = this.createAddress(createRetailerRequest.getAddress());
21706 amit.gupta 165
		addressRetailer.setRetaierId(retailer.getId());
21426 ashik.ali 166
 
21440 ashik.ali 167
		if(!addressRepository.isExist(addressRetailer)){
168
			addressRepository.persist(addressRetailer);
21292 ashik.ali 169
		}
21440 ashik.ali 170
		final RetailerRegisteredAddress retailerRegisteredAddress = new RetailerRegisteredAddress();
171
		retailerRegisteredAddress.setRetailerId(retailer.getId());
172
		retailerRegisteredAddress.setAddressId(addressRetailer.getId());
173
		retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
21463 ashik.ali 174
		if(!createRetailerRequest.isShopAddressSameAsRetailerAddress() && createRetailerRequest.getAddress() == null){
175
			throw new ProfitMandiBusinessException(ProfitMandiConstants.ADDRESS, "", "");
21440 ashik.ali 176
		}
21463 ashik.ali 177
		if(createRetailerRequest.isShopAddressSameAsRetailerAddress()){
178
			ShopAddress shopAddress = new ShopAddress();
179
			shopAddress.setShopId(shop.getId());
180
			shopAddress.setAddressId(addressRetailer.getId());
181
			shopAddressRepository.persist(shopAddress);
182
		}else{
183
			final Address addressShop = this.createAddress(createRetailerRequest.getShop().getAddress());
184
			if(!addressRepository.isExist(addressShop)){
185
				addressRepository.persist(addressShop);
186
			}
187
			ShopAddress shopAddress = new ShopAddress();
188
			shopAddress.setShopId(shop.getId());
189
			shopAddress.setAddressId(addressShop.getId());
190
			shopAddressRepository.persist(shopAddress);
191
		}
21768 amit.gupta 192
		UserAccounts ua = new UserAccounts();
193
		ua.setAccount_key(String.valueOf(saholicUser.getActiveCartId()));
194
		ua.setUser_id(user.getId());
195
		ua.setAccount_type(AccountType.cartId);
196
		userAccountRepository.persist(ua);
197
 
198
		UserAccounts ua2 = new UserAccounts();
199
		ua2.setAccount_key(String.valueOf(saholicUser.getActiveCartId()));
200
		ua2.setUser_id(user.getId());
201
		ua2.setAccount_type(AccountType.cartId);
202
		userAccountRepository.persist(ua2);
203
 
204
		UserRole ur = new UserRole();
205
		ur.setRoleId(RoleType.RETAILER.getValue());
206
		ur.setUserId(user.getId());
207
		userRoleRepository.persist(ur);
21292 ashik.ali 208
	}
209
 
21768 amit.gupta 210
	private in.shop2020.model.v1.user.User createSaholicUser(String emailId) throws ProfitMandiBusinessException{
21463 ashik.ali 211
		in.shop2020.model.v1.user.User user = new in.shop2020.model.v1.user.User();
212
		user.setEmail(emailId);
213
		user.setPassword("");
214
		user.setCommunicationEmail(emailId);
215
		user.setSex(Sex.WONT_SAY);
216
 
217
		try {
218
			UserClient userContextServiceClient = new UserClient();
219
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
220
			user = userClient.createUser(user);
21768 amit.gupta 221
			return user;
21463 ashik.ali 222
		}catch (UserContextException ux){
223
			LOGGER.error("Unable to register user: " + ux.getMessage());
224
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
225
		} catch (TTransportException e) {
226
			LOGGER.error("Unable to register user." + e);
227
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
228
		}catch (TException e) {
229
			LOGGER.error("Unable to register user." + e);
230
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
231
		} 
232
	}
21448 ashik.ali 233
	private void addBrandWithRetailer(int retailerId, Set<Category> categories)
234
		throws ProfitMandiBusinessException{
235
		for(Category category : categories){
236
			for(com.spice.profitmandi.web.req.Brand brandModel : category.getBrands()){
237
				Brand brand = brandRepository.selectByIdAndName(brandModel.getId(), brandModel.getName());
238
				final RetailerBrand retailerBrand = new RetailerBrand();
239
				retailerBrand.setRetailerId(retailerId);
240
				retailerBrand.setBrandId(brand.getId());
241
				retailerBrandRepository.persist(retailerBrand);
242
			}
243
		}
244
	}
21292 ashik.ali 245
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ALL,method=RequestMethod.GET)
21496 ashik.ali 246
	public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize){
21292 ashik.ali 247
		LOGGER.info("requested url : "+request.getRequestURL().toString());
21496 ashik.ali 248
		return responseSender.ok(retailerRepository.selectAll(pageNumber, pageSize));
21292 ashik.ali 249
	}
250
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID, method=RequestMethod.GET)
21431 ashik.ali 251
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
21292 ashik.ali 252
		LOGGER.info("requested url : "+request.getRequestURL().toString());
253
		try {
21440 ashik.ali 254
			return responseSender.ok(retailerRepository.selectById(id));
255
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
256
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
257
			return responseSender.badRequest(profitMandiBusinessException);
21292 ashik.ali 258
		}
259
	}
260
 
261
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_NAME, method=RequestMethod.GET)
262
	public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){
263
		LOGGER.info("requested url : "+request.getRequestURL().toString());
264
		try {
21440 ashik.ali 265
			return responseSender.ok(retailerRepository.selectByName(name));
266
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
267
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
268
			return responseSender.badRequest(profitMandiBusinessException);
21292 ashik.ali 269
		}
270
	}
271
 
272
 
273
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID,method=RequestMethod.DELETE)
21431 ashik.ali 274
	public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") int id){
21292 ashik.ali 275
		LOGGER.info("requested url : "+request.getRequestURL().toString());
276
		try {
277
			retailerRepository.deleteById(id);
21440 ashik.ali 278
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
279
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
280
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
281
			return responseSender.badRequest(profitMandiBusinessException);
21292 ashik.ali 282
		}
283
	}
284
 
21426 ashik.ali 285
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ADD, method=RequestMethod.POST)
21431 ashik.ali 286
	public ResponseEntity<?> addShop(HttpServletRequest request, @RequestBody com.spice.profitmandi.web.req.Shop createShop, @RequestParam(name = "retailerId") int retailerId){
21426 ashik.ali 287
		LOGGER.info("requested url : "+request.getRequestURL().toString());
288
		try {
289
			Document document = documentRepository.selectById(createShop.getDocumentId());
290
			if(shopRepository.isExistByDocumentId(createShop.getDocumentId())){
291
				LOGGER.error("documet is already mapped with another shop");
292
				throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "");
293
			}
294
			retailerRepository.selectById(retailerId);
295
			Shop shop = new Shop();
296
			shop.setRetailerId(retailerId);
297
			Address address = this.createAddress(createShop.getAddress());
298
			addressRepository.persist(address);
299
			shop.setAddressId(address.getId());
300
			shop.setDocumentId(document.getId());
301
			shopRepository.persist(shop);
302
			ShopAddress shopAddress = new ShopAddress();
303
			shopAddress.setAddressId(address.getId());
304
			shopAddress.setShopId(shop.getId());
305
			shopAddressRepository.persist(shopAddress);
21440 ashik.ali 306
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
307
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
308
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
309
			return responseSender.badRequest(profitMandiBusinessException);
21426 ashik.ali 310
		}
311
	}
312
 
313
 
21302 ashik.ali 314
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_REMOVE, method=RequestMethod.DELETE)
21431 ashik.ali 315
	public ResponseEntity<?> removeShop(HttpServletRequest request, @RequestParam(name = "shopId") int shopId, @RequestParam(name = "retailerId") int retailerId){
21292 ashik.ali 316
		LOGGER.info("requested url : "+request.getRequestURL().toString());
317
		try {
318
			retailerRepository.removeShop(shopId, retailerId);
21440 ashik.ali 319
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
320
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
321
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
322
			return responseSender.badRequest(profitMandiBusinessException);
21292 ashik.ali 323
		}
324
	}
325
 
21426 ashik.ali 326
	private Address createAddress(com.spice.profitmandi.web.req.Address createAddress){
327
		Address address = new Address();
328
		address.setName(createAddress.getName());
329
		address.setLine1(createAddress.getLine1());
330
		address.setLine2(createAddress.getLine2());
331
		address.setLandmark(createAddress.getLandmark());
332
		address.setCity(createAddress.getCity());
333
		address.setState(createAddress.getState());
334
		address.setPinCode(createAddress.getPinCode());
335
		address.setCountry(createAddress.getCountry());
336
		address.setPhoneNumber(createAddress.getPhoneNumber());
21706 amit.gupta 337
 
21426 ashik.ali 338
		return address;
339
	}
21440 ashik.ali 340
 
21426 ashik.ali 341
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ADD, method=RequestMethod.POST)
342
	public ResponseEntity<?> addAddress(HttpServletRequest request, @RequestBody CreateRetailerAddressRequest createRetailerAddress){
343
		LOGGER.info("requested url : "+request.getRequestURL().toString());
344
		try {
345
			retailerRepository.addAddress(this.createAddress(createRetailerAddress.getAddress()), createRetailerAddress.getRetailerId());
21440 ashik.ali 346
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
347
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
348
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
349
			return responseSender.badRequest(profitMandiBusinessException);
21426 ashik.ali 350
		}
351
	}
21292 ashik.ali 352
 
21426 ashik.ali 353
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_REMOVE, method=RequestMethod.DELETE)
21431 ashik.ali 354
	public ResponseEntity<?> removeAddress(HttpServletRequest request, @RequestParam(name = "addressId") int addressId, @RequestParam(name = "retailerId") int retailerId){
21426 ashik.ali 355
		LOGGER.info("requested url : "+request.getRequestURL().toString());
356
		try {
357
			retailerRepository.removeAddress(addressId, retailerId);
21440 ashik.ali 358
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
359
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
360
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
361
			return responseSender.badRequest(profitMandiBusinessException);
21426 ashik.ali 362
		}
363
	}
364
 
365
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_ADD, method=RequestMethod.POST)
366
	public ResponseEntity<?> addBrand(HttpServletRequest request, @RequestBody RetailerAddBrandRequest retailerAddBrandRequest){
367
		LOGGER.info("requested url : "+request.getRequestURL().toString());
368
		try {
21448 ashik.ali 369
			retailerRepository.selectById(retailerAddBrandRequest.getRetailerId());
370
			this.addBrandWithRetailer(retailerAddBrandRequest.getRetailerId(), retailerAddBrandRequest.getCategories());
21440 ashik.ali 371
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
372
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
373
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
374
			return responseSender.badRequest(profitMandiBusinessException);
21426 ashik.ali 375
		}
376
	}
377
 
378
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_REMOVE, method=RequestMethod.DELETE)
21431 ashik.ali 379
	public ResponseEntity<?> removeBrand(HttpServletRequest request, @RequestParam(name = "brandId") int brandId, @RequestParam(name = "retailerId") int retailerId){
21426 ashik.ali 380
		LOGGER.info("requested url : "+request.getRequestURL().toString());
381
		try {
382
			brandRepository.selectById(brandId);
383
			retailerRepository.selectById(retailerId);
21448 ashik.ali 384
			retailerBrandRepository.deleteByRetailerAndBrandId(retailerId, brandId);
21440 ashik.ali 385
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
386
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
387
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
388
			return responseSender.badRequest(profitMandiBusinessException);
21426 ashik.ali 389
		}
390
	}
391
 
392
 
21448 ashik.ali 393
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_DOCUMENT, method=RequestMethod.GET)
394
	public ResponseEntity<?> getDocumentById(HttpServletRequest request, @RequestParam(name = "retailerId") int retailerId){
21426 ashik.ali 395
		LOGGER.info("requested url : "+request.getRequestURL().toString());
396
		try {
21448 ashik.ali 397
			return responseSender.ok(retailerRepository.selectDocumentById(retailerId));
21440 ashik.ali 398
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
399
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
400
			return responseSender.badRequest(profitMandiBusinessException);
21426 ashik.ali 401
		}
402
	}
403
 
21448 ashik.ali 404
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_REGISTERED_ADDRESS, method=RequestMethod.GET)
405
	public ResponseEntity<?> getRegisteredAddressById(HttpServletRequest request, @RequestParam(name = "retailerId") int retailerId){
406
		LOGGER.info("requested url : "+request.getRequestURL().toString());
407
		try {
21698 amit.gupta 408
			return responseSender.ok(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId));
21448 ashik.ali 409
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
410
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
411
			return responseSender.badRequest(profitMandiBusinessException);
412
		}
413
	}
414
 
21426 ashik.ali 415
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ALL, method=RequestMethod.GET)
21431 ashik.ali 416
	public ResponseEntity<?> getAllShops(HttpServletRequest request, @RequestParam(name = "id") int id){
21426 ashik.ali 417
		LOGGER.info("requested url : "+request.getRequestURL().toString());
418
		try {
21440 ashik.ali 419
			return responseSender.ok(shopRepository.selectByRetailerId(id));
420
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
421
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
422
			return responseSender.badRequest(profitMandiBusinessException);
21426 ashik.ali 423
		}
424
	}
425
 
426
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ALL, method=RequestMethod.GET)
21431 ashik.ali 427
	public ResponseEntity<?> getAllAddresses(HttpServletRequest request, @RequestParam(name = "id") int id){
21426 ashik.ali 428
		LOGGER.info("requested url : "+request.getRequestURL().toString());
21440 ashik.ali 429
		return responseSender.ok(retailerAddressRepository.selectAddressesByRetailerId(id));
21426 ashik.ali 430
	}
431
 
432
 
433
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_ALL, method=RequestMethod.GET)
21431 ashik.ali 434
	public ResponseEntity<?> getAllBrads(HttpServletRequest request, @RequestParam(name = "id") int id){
21426 ashik.ali 435
		LOGGER.info("requested url : "+request.getRequestURL().toString());
21440 ashik.ali 436
		return responseSender.ok(retailerBrandRepository.selectBrandNamesByRetailerId(id));
21426 ashik.ali 437
	}
438
 
21292 ashik.ali 439
}