Subversion Repositories SmartDukaan

Rev

Rev 21426 | Rev 21435 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21426 Rev 21431
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.time.LocalDateTime;
3
import java.time.LocalDateTime;
4
import java.util.Set;
-
 
5
 
4
 
6
import javax.servlet.http.HttpServletRequest;
5
import javax.servlet.http.HttpServletRequest;
7
 
6
 
8
import org.slf4j.Logger;
7
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
8
import org.slf4j.LoggerFactory;
Line 37... Line 36...
37
import com.spice.profitmandi.dao.repository.ShopAddressRepository;
36
import com.spice.profitmandi.dao.repository.ShopAddressRepository;
38
import com.spice.profitmandi.dao.repository.ShopRepository;
37
import com.spice.profitmandi.dao.repository.ShopRepository;
39
import com.spice.profitmandi.web.model.ProfitMandiResponse;
38
import com.spice.profitmandi.web.model.ProfitMandiResponse;
40
import com.spice.profitmandi.web.model.Response;
39
import com.spice.profitmandi.web.model.Response;
41
import com.spice.profitmandi.web.model.ResponseStatus;
40
import com.spice.profitmandi.web.model.ResponseStatus;
-
 
41
import com.spice.profitmandi.web.req.Category;
42
import com.spice.profitmandi.web.req.CreateRetailerAddressRequest;
42
import com.spice.profitmandi.web.req.CreateRetailerAddressRequest;
43
import com.spice.profitmandi.web.req.CreateRetailerRequest;
43
import com.spice.profitmandi.web.req.CreateRetailerRequest;
44
import com.spice.profitmandi.web.req.RetailerAddBrandRequest;
44
import com.spice.profitmandi.web.req.RetailerAddBrandRequest;
45
 
45
 
46
import io.swagger.annotations.ApiImplicitParam;
46
import io.swagger.annotations.ApiImplicitParam;
Line 95... Line 95...
95
		retailer.setMonthlySaleValue(createRetailerRequest.getMonthlySaleValue());
95
		retailer.setMonthlySaleValue(createRetailerRequest.getMonthlySaleValue());
96
		retailer.setSmartphoneSaleValue(createRetailerRequest.getSmartphoneSaleValue());
96
		retailer.setSmartphoneSaleValue(createRetailerRequest.getSmartphoneSaleValue());
97
		retailer.setRecharge(createRetailerRequest.getLineOfBusiness().isRecharge());
97
		retailer.setRecharge(createRetailerRequest.getLineOfBusiness().isRecharge());
98
		retailer.setMobile(createRetailerRequest.getLineOfBusiness().isMobile());
98
		retailer.setMobile(createRetailerRequest.getLineOfBusiness().isMobile());
99
		retailer.setAccessories(createRetailerRequest.getLineOfBusiness().isAccessories());
99
		retailer.setAccessories(createRetailerRequest.getLineOfBusiness().isAccessories());
100
		retailer.setOther1(createRetailerRequest.getLineOfBusiness().isOther1());
100
		retailer.setOther1(createRetailerRequest.getLineOfBusiness().getOther1());
101
		retailer.setOther2(createRetailerRequest.getLineOfBusiness().isOther2());
101
		retailer.setOther2(createRetailerRequest.getLineOfBusiness().getOther2());
102
		Set<String> brandNames = createRetailerRequest.getBrandNames();
102
		//Set<String> brandNames = createRetailerRequest.getBrandNames();
103
		
103
		
104
		try {
104
		try {
105
			
105
			
106
			Document retailerDocument = documentRepository.selectById(createRetailerRequest.getDocumentId());
106
			Document retailerDocument = documentRepository.selectById(createRetailerRequest.getDocumentId());
107
			if(retailerRepository.isExistByDocumentId(retailerDocument.getId())){
107
			if(retailerRepository.isExistByDocumentId(retailerDocument.getId())){
Line 121... Line 121...
121
			try{
121
			try{
122
				shopRepository.persist(shop);
122
				shopRepository.persist(shop);
123
			}catch(ProfitMandiBusinessException profitMandiBusinessException){
123
			}catch(ProfitMandiBusinessException profitMandiBusinessException){
124
				
124
				
125
			}
125
			}
-
 
126
			for(Category category : createRetailerRequest.getCategories()){
-
 
127
				for(com.spice.profitmandi.web.req.Brand brandModel : category.getBrands()){
126
			for(String brandName : brandNames){
128
					Brand brand = brandRepository.selectByName(brandModel.getName());
127
				Brand brand =new Brand();
129
					final RetailerBrand retailerBrand = new RetailerBrand();
128
				brand.setName(brandName);
130
					retailerBrand.setRetailerId(retailer.getId());
129
				if(!brandRepository.isExistByName(brandName)){
131
					retailerBrand.setBrandId(brand.getId());
130
					brandRepository.persist(brand);
132
					retailerBrandRepository.persist(retailerBrand);
131
				}
133
				}
132
				final RetailerBrand retailerBrand = new RetailerBrand();
-
 
133
				retailerBrand.setRetailerId(retailer.getId());
-
 
134
				retailerBrand.setBrandId(brand.getId());
-
 
135
				retailerBrandRepository.persist(retailerBrand);
-
 
136
			}
134
			}
137
			final Address addressRetailer = this.createAddress(createRetailerRequest.getAddress());
135
			final Address addressRetailer = this.createAddress(createRetailerRequest.getAddress());
138
			
136
			
139
			if(!addressRepository.isExist(addressRetailer)){
137
			if(!addressRepository.isExist(addressRetailer)){
140
				addressRepository.persist(addressRetailer);
138
				addressRepository.persist(addressRetailer);
Line 183... Line 181...
183
		LOGGER.info("requested url : "+request.getRequestURL().toString());
181
		LOGGER.info("requested url : "+request.getRequestURL().toString());
184
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, retailerRepository.selectAll());
182
		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);
183
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
186
	}
184
	}
187
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID, method=RequestMethod.GET)
185
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID, method=RequestMethod.GET)
188
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") long id){
186
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
189
		LOGGER.info("requested url : "+request.getRequestURL().toString());
187
		LOGGER.info("requested url : "+request.getRequestURL().toString());
190
		try {
188
		try {
191
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, retailerRepository.selectById(id));
189
			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);
190
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
193
		}catch (ProfitMandiBusinessException pmbe) {
191
		}catch (ProfitMandiBusinessException pmbe) {
Line 212... Line 210...
212
		}
210
		}
213
	}
211
	}
214
		
212
		
215
	
213
	
216
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID,method=RequestMethod.DELETE)
214
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ID,method=RequestMethod.DELETE)
217
	public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") long id){
215
	public ResponseEntity<?> removeById(HttpServletRequest request, @RequestParam(name = "id") int id){
218
		LOGGER.info("requested url : "+request.getRequestURL().toString());
216
		LOGGER.info("requested url : "+request.getRequestURL().toString());
219
		try {
217
		try {
220
			retailerRepository.deleteById(id);
218
			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"));
219
			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);
220
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
Line 227... Line 225...
227
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
225
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
228
		}
226
		}
229
	}
227
	}
230
	
228
	
231
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ADD, method=RequestMethod.POST)
229
	@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){
230
	public ResponseEntity<?> addShop(HttpServletRequest request, @RequestBody com.spice.profitmandi.web.req.Shop createShop, @RequestParam(name = "retailerId") int retailerId){
233
		LOGGER.info("requested url : "+request.getRequestURL().toString());
231
		LOGGER.info("requested url : "+request.getRequestURL().toString());
234
		try {
232
		try {
235
			Document document = documentRepository.selectById(createShop.getDocumentId());
233
			Document document = documentRepository.selectById(createShop.getDocumentId());
236
			if(shopRepository.isExistByDocumentId(createShop.getDocumentId())){
234
			if(shopRepository.isExistByDocumentId(createShop.getDocumentId())){
237
				LOGGER.error("documet is already mapped with another shop");
235
				LOGGER.error("documet is already mapped with another shop");
Line 259... Line 257...
259
		}
257
		}
260
	}
258
	}
261
	
259
	
262
	
260
	
263
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_REMOVE, method=RequestMethod.DELETE)
261
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_REMOVE, method=RequestMethod.DELETE)
264
	public ResponseEntity<?> removeShop(HttpServletRequest request, @RequestParam(name = "shopId") long shopId, @RequestParam(name = "retailerId") long retailerId){
262
	public ResponseEntity<?> removeShop(HttpServletRequest request, @RequestParam(name = "shopId") int shopId, @RequestParam(name = "retailerId") int retailerId){
265
		LOGGER.info("requested url : "+request.getRequestURL().toString());
263
		LOGGER.info("requested url : "+request.getRequestURL().toString());
266
		try {
264
		try {
267
			retailerRepository.removeShop(shopId, retailerId);
265
			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"));
266
			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);
267
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
Line 302... Line 300...
302
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
300
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
303
		}
301
		}
304
	}
302
	}
305
	
303
	
306
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_REMOVE, method=RequestMethod.DELETE)
304
	@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){
305
	public ResponseEntity<?> removeAddress(HttpServletRequest request, @RequestParam(name = "addressId") int addressId, @RequestParam(name = "retailerId") int retailerId){
308
		LOGGER.info("requested url : "+request.getRequestURL().toString());
306
		LOGGER.info("requested url : "+request.getRequestURL().toString());
309
		try {
307
		try {
310
			retailerRepository.removeAddress(addressId, retailerId);
308
			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"));
309
			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);
310
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
Line 346... Line 344...
346
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
344
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
347
		}
345
		}
348
	}
346
	}
349
	
347
	
350
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_REMOVE, method=RequestMethod.DELETE)
348
	@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){
349
	public ResponseEntity<?> removeBrand(HttpServletRequest request, @RequestParam(name = "brandId") int brandId, @RequestParam(name = "retailerId") int retailerId){
352
		LOGGER.info("requested url : "+request.getRequestURL().toString());
350
		LOGGER.info("requested url : "+request.getRequestURL().toString());
353
		try {
351
		try {
354
			brandRepository.selectById(brandId);
352
			brandRepository.selectById(brandId);
355
			retailerRepository.selectById(retailerId);
353
			retailerRepository.selectById(retailerId);
356
			retailerBrandRepository.deleteByRetailerId(retailerId, brandId);
354
			retailerBrandRepository.deleteByRetailerId(retailerId, brandId);
Line 364... Line 362...
364
		}
362
		}
365
	}
363
	}
366
	
364
	
367
	
365
	
368
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_DOCUMENT_DOCUMENT_ID, method=RequestMethod.GET)
366
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_DOCUMENT_DOCUMENT_ID, method=RequestMethod.GET)
369
	public ResponseEntity<?> getDocumentById(HttpServletRequest request, @RequestParam(name = "document") long documentId){
367
	public ResponseEntity<?> getDocumentById(HttpServletRequest request, @RequestParam(name = "document") int documentId){
370
		LOGGER.info("requested url : "+request.getRequestURL().toString());
368
		LOGGER.info("requested url : "+request.getRequestURL().toString());
371
		try {
369
		try {
372
			retailerRepository.selectByDocumentId(documentId);
370
			retailerRepository.selectByDocumentId(documentId);
373
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, documentRepository.selectById(documentId));
371
			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);
372
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
Line 379... Line 377...
379
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
377
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
380
		}
378
		}
381
	}
379
	}
382
	
380
	
383
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ALL, method=RequestMethod.GET)
381
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_SHOP_ALL, method=RequestMethod.GET)
384
	public ResponseEntity<?> getAllShops(HttpServletRequest request, @RequestParam(name = "id") long id){
382
	public ResponseEntity<?> getAllShops(HttpServletRequest request, @RequestParam(name = "id") int id){
385
		LOGGER.info("requested url : "+request.getRequestURL().toString());
383
		LOGGER.info("requested url : "+request.getRequestURL().toString());
386
		try {
384
		try {
387
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, shopRepository.selectByRetailerId(id));
385
			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);
386
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
389
		}catch (ProfitMandiBusinessException pmbe) {
387
		}catch (ProfitMandiBusinessException pmbe) {
Line 393... Line 391...
393
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
391
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
394
		}
392
		}
395
	}
393
	}
396
	
394
	
397
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ALL, method=RequestMethod.GET)
395
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_ADDRESS_ALL, method=RequestMethod.GET)
398
	public ResponseEntity<?> getAllAddresses(HttpServletRequest request, @RequestParam(name = "id") long id){
396
	public ResponseEntity<?> getAllAddresses(HttpServletRequest request, @RequestParam(name = "id") int id){
399
		LOGGER.info("requested url : "+request.getRequestURL().toString());
397
		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));
398
		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);
399
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
402
	}
400
	}
403
	
401
	
404
	
402
	
405
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_ALL, method=RequestMethod.GET)
403
	@RequestMapping(value = ProfitMandiConstants.URL_RETAILER_BRAND_ALL, method=RequestMethod.GET)
406
	public ResponseEntity<?> getAllBrads(HttpServletRequest request, @RequestParam(name = "id") long id){
404
	public ResponseEntity<?> getAllBrads(HttpServletRequest request, @RequestParam(name = "id") int id){
407
		LOGGER.info("requested url : "+request.getRequestURL().toString());
405
		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));
406
		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);
407
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
410
	}
408
	}
411
		
409