Subversion Repositories SmartDukaan

Rev

Rev 22037 | Rev 22273 | 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
22037 amit.gupta 63
@Transactional(rollbackFor=Throwable.class)
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());
22041 amit.gupta 166
		addressRepository.persist(addressRetailer);
21440 ashik.ali 167
		final RetailerRegisteredAddress retailerRegisteredAddress = new RetailerRegisteredAddress();
168
		retailerRegisteredAddress.setRetailerId(retailer.getId());
169
		retailerRegisteredAddress.setAddressId(addressRetailer.getId());
170
		retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
21463 ashik.ali 171
		if(!createRetailerRequest.isShopAddressSameAsRetailerAddress() && createRetailerRequest.getAddress() == null){
172
			throw new ProfitMandiBusinessException(ProfitMandiConstants.ADDRESS, "", "");
21440 ashik.ali 173
		}
21463 ashik.ali 174
		if(createRetailerRequest.isShopAddressSameAsRetailerAddress()){
175
			ShopAddress shopAddress = new ShopAddress();
176
			shopAddress.setShopId(shop.getId());
177
			shopAddress.setAddressId(addressRetailer.getId());
178
			shopAddressRepository.persist(shopAddress);
179
		}else{
180
			final Address addressShop = this.createAddress(createRetailerRequest.getShop().getAddress());
22041 amit.gupta 181
			addressRepository.persist(addressShop);
21463 ashik.ali 182
			ShopAddress shopAddress = new ShopAddress();
183
			shopAddress.setShopId(shop.getId());
184
			shopAddress.setAddressId(addressShop.getId());
185
			shopAddressRepository.persist(shopAddress);
186
		}
21768 amit.gupta 187
		UserAccounts ua = new UserAccounts();
21769 amit.gupta 188
		ua.setAccount_key(String.valueOf(saholicUser.getUserId()));
21768 amit.gupta 189
		ua.setUser_id(user.getId());
21769 amit.gupta 190
		ua.setAccount_type(AccountType.saholic);
21768 amit.gupta 191
		userAccountRepository.persist(ua);
192
 
193
		UserAccounts ua2 = new UserAccounts();
194
		ua2.setAccount_key(String.valueOf(saholicUser.getActiveCartId()));
195
		ua2.setUser_id(user.getId());
196
		ua2.setAccount_type(AccountType.cartId);
197
		userAccountRepository.persist(ua2);
198
 
199
		UserRole ur = new UserRole();
22011 ashik.ali 200
		ur.setRoleType(RoleType.RETAILER);
21768 amit.gupta 201
		ur.setUserId(user.getId());
202
		userRoleRepository.persist(ur);
21292 ashik.ali 203
	}
204
 
21768 amit.gupta 205
	private in.shop2020.model.v1.user.User createSaholicUser(String emailId) throws ProfitMandiBusinessException{
21463 ashik.ali 206
		in.shop2020.model.v1.user.User user = new in.shop2020.model.v1.user.User();
207
		user.setEmail(emailId);
208
		user.setPassword("");
209
		user.setCommunicationEmail(emailId);
210
		user.setSex(Sex.WONT_SAY);
211
 
212
		try {
213
			UserClient userContextServiceClient = new UserClient();
214
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
215
			user = userClient.createUser(user);
21768 amit.gupta 216
			return user;
21463 ashik.ali 217
		}catch (UserContextException ux){
218
			LOGGER.error("Unable to register user: " + ux.getMessage());
219
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
220
		} catch (TTransportException e) {
221
			LOGGER.error("Unable to register user." + e);
222
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
223
		}catch (TException e) {
224
			LOGGER.error("Unable to register user." + e);
225
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, emailId, "");
226
		} 
227
	}
21448 ashik.ali 228
	private void addBrandWithRetailer(int retailerId, Set<Category> categories)
229
		throws ProfitMandiBusinessException{
230
		for(Category category : categories){
231
			for(com.spice.profitmandi.web.req.Brand brandModel : category.getBrands()){
232
				Brand brand = brandRepository.selectByIdAndName(brandModel.getId(), brandModel.getName());
233
				final RetailerBrand retailerBrand = new RetailerBrand();
234
				retailerBrand.setRetailerId(retailerId);
235
				retailerBrand.setBrandId(brand.getId());
236
				retailerBrandRepository.persist(retailerBrand);
237
			}
238
		}
239
	}
21292 ashik.ali 240
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ALL,method=RequestMethod.GET)
21496 ashik.ali 241
	public ResponseEntity<?> getAll(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize){
21292 ashik.ali 242
		LOGGER.info("requested url : "+request.getRequestURL().toString());
21496 ashik.ali 243
		return responseSender.ok(retailerRepository.selectAll(pageNumber, pageSize));
21292 ashik.ali 244
	}
245
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID, method=RequestMethod.GET)
21431 ashik.ali 246
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
21292 ashik.ali 247
		LOGGER.info("requested url : "+request.getRequestURL().toString());
248
		try {
21440 ashik.ali 249
			return responseSender.ok(retailerRepository.selectById(id));
250
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
251
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
252
			return responseSender.badRequest(profitMandiBusinessException);
21292 ashik.ali 253
		}
254
	}
255
 
256
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_NAME, method=RequestMethod.GET)
257
	public ResponseEntity<?> getByName(HttpServletRequest request, @RequestParam(name = "name") String name){
258
		LOGGER.info("requested url : "+request.getRequestURL().toString());
259
		try {
21440 ashik.ali 260
			return responseSender.ok(retailerRepository.selectByName(name));
261
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
262
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
263
			return responseSender.badRequest(profitMandiBusinessException);
21292 ashik.ali 264
		}
265
	}
266
 
267
 
268
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID,method=RequestMethod.DELETE)
21431 ashik.ali 269
	public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") int id){
21292 ashik.ali 270
		LOGGER.info("requested url : "+request.getRequestURL().toString());
271
		try {
272
			retailerRepository.deleteById(id);
21440 ashik.ali 273
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
274
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
275
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
276
			return responseSender.badRequest(profitMandiBusinessException);
21292 ashik.ali 277
		}
278
	}
279
 
21426 ashik.ali 280
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ADD, method=RequestMethod.POST)
21431 ashik.ali 281
	public ResponseEntity<?> addShop(HttpServletRequest request, @RequestBody com.spice.profitmandi.web.req.Shop createShop, @RequestParam(name = "retailerId") int retailerId){
21426 ashik.ali 282
		LOGGER.info("requested url : "+request.getRequestURL().toString());
283
		try {
284
			Document document = documentRepository.selectById(createShop.getDocumentId());
285
			if(shopRepository.isExistByDocumentId(createShop.getDocumentId())){
286
				LOGGER.error("documet is already mapped with another shop");
287
				throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "");
288
			}
289
			retailerRepository.selectById(retailerId);
290
			Shop shop = new Shop();
291
			shop.setRetailerId(retailerId);
292
			Address address = this.createAddress(createShop.getAddress());
293
			addressRepository.persist(address);
294
			shop.setAddressId(address.getId());
295
			shop.setDocumentId(document.getId());
296
			shopRepository.persist(shop);
297
			ShopAddress shopAddress = new ShopAddress();
298
			shopAddress.setAddressId(address.getId());
299
			shopAddress.setShopId(shop.getId());
300
			shopAddressRepository.persist(shopAddress);
21440 ashik.ali 301
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
302
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
303
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
304
			return responseSender.badRequest(profitMandiBusinessException);
21426 ashik.ali 305
		}
306
	}
307
 
308
 
21302 ashik.ali 309
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_REMOVE, method=RequestMethod.DELETE)
21431 ashik.ali 310
	public ResponseEntity<?> removeShop(HttpServletRequest request, @RequestParam(name = "shopId") int shopId, @RequestParam(name = "retailerId") int retailerId){
21292 ashik.ali 311
		LOGGER.info("requested url : "+request.getRequestURL().toString());
312
		try {
313
			retailerRepository.removeShop(shopId, retailerId);
21440 ashik.ali 314
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
315
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
316
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
317
			return responseSender.badRequest(profitMandiBusinessException);
21292 ashik.ali 318
		}
319
	}
320
 
21426 ashik.ali 321
	private Address createAddress(com.spice.profitmandi.web.req.Address createAddress){
322
		Address address = new Address();
323
		address.setName(createAddress.getName());
324
		address.setLine1(createAddress.getLine1());
325
		address.setLine2(createAddress.getLine2());
326
		address.setLandmark(createAddress.getLandmark());
327
		address.setCity(createAddress.getCity());
328
		address.setState(createAddress.getState());
329
		address.setPinCode(createAddress.getPinCode());
330
		address.setCountry(createAddress.getCountry());
331
		address.setPhoneNumber(createAddress.getPhoneNumber());
21706 amit.gupta 332
 
21426 ashik.ali 333
		return address;
334
	}
21440 ashik.ali 335
 
21426 ashik.ali 336
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ADD, method=RequestMethod.POST)
337
	public ResponseEntity<?> addAddress(HttpServletRequest request, @RequestBody CreateRetailerAddressRequest createRetailerAddress){
338
		LOGGER.info("requested url : "+request.getRequestURL().toString());
339
		try {
340
			retailerRepository.addAddress(this.createAddress(createRetailerAddress.getAddress()), createRetailerAddress.getRetailerId());
21440 ashik.ali 341
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
342
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
343
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
344
			return responseSender.badRequest(profitMandiBusinessException);
21426 ashik.ali 345
		}
346
	}
21292 ashik.ali 347
 
21426 ashik.ali 348
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_REMOVE, method=RequestMethod.DELETE)
21431 ashik.ali 349
	public ResponseEntity<?> removeAddress(HttpServletRequest request, @RequestParam(name = "addressId") int addressId, @RequestParam(name = "retailerId") int retailerId){
21426 ashik.ali 350
		LOGGER.info("requested url : "+request.getRequestURL().toString());
351
		try {
352
			retailerRepository.removeAddress(addressId, retailerId);
21440 ashik.ali 353
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
354
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
355
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
356
			return responseSender.badRequest(profitMandiBusinessException);
21426 ashik.ali 357
		}
358
	}
359
 
360
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_ADD, method=RequestMethod.POST)
361
	public ResponseEntity<?> addBrand(HttpServletRequest request, @RequestBody RetailerAddBrandRequest retailerAddBrandRequest){
362
		LOGGER.info("requested url : "+request.getRequestURL().toString());
363
		try {
21448 ashik.ali 364
			retailerRepository.selectById(retailerAddBrandRequest.getRetailerId());
365
			this.addBrandWithRetailer(retailerAddBrandRequest.getRetailerId(), retailerAddBrandRequest.getCategories());
21440 ashik.ali 366
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
367
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
368
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
369
			return responseSender.badRequest(profitMandiBusinessException);
21426 ashik.ali 370
		}
371
	}
372
 
373
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_REMOVE, method=RequestMethod.DELETE)
21431 ashik.ali 374
	public ResponseEntity<?> removeBrand(HttpServletRequest request, @RequestParam(name = "brandId") int brandId, @RequestParam(name = "retailerId") int retailerId){
21426 ashik.ali 375
		LOGGER.info("requested url : "+request.getRequestURL().toString());
376
		try {
377
			brandRepository.selectById(brandId);
378
			retailerRepository.selectById(retailerId);
21448 ashik.ali 379
			retailerBrandRepository.deleteByRetailerAndBrandId(retailerId, brandId);
21440 ashik.ali 380
			return responseSender.ok(ResponseCodeHolder.getMessage("API_OK_1001"));
381
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
382
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
383
			return responseSender.badRequest(profitMandiBusinessException);
21426 ashik.ali 384
		}
385
	}
386
 
387
 
21448 ashik.ali 388
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_DOCUMENT, method=RequestMethod.GET)
389
	public ResponseEntity<?> getDocumentById(HttpServletRequest request, @RequestParam(name = "retailerId") int retailerId){
21426 ashik.ali 390
		LOGGER.info("requested url : "+request.getRequestURL().toString());
391
		try {
21448 ashik.ali 392
			return responseSender.ok(retailerRepository.selectDocumentById(retailerId));
21440 ashik.ali 393
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
394
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
395
			return responseSender.badRequest(profitMandiBusinessException);
21426 ashik.ali 396
		}
397
	}
398
 
21448 ashik.ali 399
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_REGISTERED_ADDRESS, method=RequestMethod.GET)
400
	public ResponseEntity<?> getRegisteredAddressById(HttpServletRequest request, @RequestParam(name = "retailerId") int retailerId){
401
		LOGGER.info("requested url : "+request.getRequestURL().toString());
402
		try {
21698 amit.gupta 403
			return responseSender.ok(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId));
21448 ashik.ali 404
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
405
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
406
			return responseSender.badRequest(profitMandiBusinessException);
407
		}
408
	}
409
 
21426 ashik.ali 410
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ALL, method=RequestMethod.GET)
21431 ashik.ali 411
	public ResponseEntity<?> getAllShops(HttpServletRequest request, @RequestParam(name = "id") int id){
21426 ashik.ali 412
		LOGGER.info("requested url : "+request.getRequestURL().toString());
413
		try {
21440 ashik.ali 414
			return responseSender.ok(shopRepository.selectByRetailerId(id));
415
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
416
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
417
			return responseSender.badRequest(profitMandiBusinessException);
21426 ashik.ali 418
		}
419
	}
420
 
421
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ALL, method=RequestMethod.GET)
21431 ashik.ali 422
	public ResponseEntity<?> getAllAddresses(HttpServletRequest request, @RequestParam(name = "id") int id){
21426 ashik.ali 423
		LOGGER.info("requested url : "+request.getRequestURL().toString());
21440 ashik.ali 424
		return responseSender.ok(retailerAddressRepository.selectAddressesByRetailerId(id));
21426 ashik.ali 425
	}
426
 
427
 
428
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_ALL, method=RequestMethod.GET)
21431 ashik.ali 429
	public ResponseEntity<?> getAllBrads(HttpServletRequest request, @RequestParam(name = "id") int id){
21426 ashik.ali 430
		LOGGER.info("requested url : "+request.getRequestURL().toString());
21440 ashik.ali 431
		return responseSender.ok(retailerBrandRepository.selectBrandNamesByRetailerId(id));
21426 ashik.ali 432
	}
433
 
21292 ashik.ali 434
}