Subversion Repositories SmartDukaan

Rev

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