Subversion Repositories SmartDukaan

Rev

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

Rev 21440 Rev 21448
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;
-
 
4
import java.util.ArrayList;
3
import java.util.ArrayList;
5
import java.util.HashSet;
4
import java.util.HashSet;
6
import java.util.List;
5
import java.util.List;
7
import java.util.Set;
6
import java.util.Set;
8
 
7
 
9
import javax.servlet.http.HttpServletRequest;
8
import javax.servlet.http.HttpServletRequest;
10
 
9
 
11
import org.slf4j.Logger;
10
import org.slf4j.Logger;
12
import org.slf4j.LoggerFactory;
11
import org.slf4j.LoggerFactory;
13
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.http.HttpStatus;
-
 
15
import org.springframework.http.ResponseEntity;
13
import org.springframework.http.ResponseEntity;
16
import org.springframework.stereotype.Controller;
14
import org.springframework.stereotype.Controller;
17
import org.springframework.web.bind.annotation.RequestMapping;
15
import org.springframework.web.bind.annotation.RequestMapping;
18
import org.springframework.web.bind.annotation.RequestMethod;
16
import org.springframework.web.bind.annotation.RequestMethod;
19
import org.springframework.web.bind.annotation.RequestParam;
17
import org.springframework.web.bind.annotation.RequestParam;
20
 
18
 
21
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
19
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
22
import com.spice.profitmandi.common.model.ProfitMandiConstants;
20
import com.spice.profitmandi.common.model.ProfitMandiConstants;
23
import com.spice.profitmandi.dao.entity.Brand;
21
import com.spice.profitmandi.dao.entity.Brand;
24
import com.spice.profitmandi.dao.repository.BrandRepository;
22
import com.spice.profitmandi.dao.repository.BrandRepository;
25
import com.spice.profitmandi.web.model.ProfitMandiResponse;
-
 
26
import com.spice.profitmandi.web.model.Response;
-
 
27
import com.spice.profitmandi.web.model.ResponseStatus;
-
 
28
import com.spice.profitmandi.web.req.Category;
23
import com.spice.profitmandi.web.req.Category;
-
 
24
import com.spice.profitmandi.web.util.ResponseSender;
29
 
25
 
30
@Controller
26
@Controller
31
public class BrandController {
27
public class BrandController {
-
 
28
 
-
 
29
	@Autowired
-
 
30
	ResponseSender<?> responseSender;
32
	
31
	
33
	private static final Logger LOGGER=LoggerFactory.getLogger(BrandController.class);
32
	private static final Logger LOGGER=LoggerFactory.getLogger(BrandController.class);
34
	
33
	
35
	@Autowired
34
	@Autowired
36
	BrandRepository brandRepository;
35
	BrandRepository brandRepository;
Line 69... Line 68...
69
				brandModel.setId(brand.getId());
68
				brandModel.setId(brand.getId());
70
				brandModel.setName(brand.getName());
69
				brandModel.setName(brand.getName());
71
				foundCategory.getBrands().add(brandModel);
70
				foundCategory.getBrands().add(brandModel);
72
			}
71
			}
73
		}
72
		}
74
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, categories);
-
 
75
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
73
		return responseSender.ok(categories);
76
	}
74
	}
77
	
75
	
78
	@RequestMapping(value = ProfitMandiConstants.URL_BRAND_ID, method=RequestMethod.GET)
76
	@RequestMapping(value = ProfitMandiConstants.URL_BRAND_ID, method=RequestMethod.GET)
79
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
77
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
80
		LOGGER.info("requested url : "+request.getRequestURL().toString());
78
		LOGGER.info("requested url : "+request.getRequestURL().toString());
81
		try {
79
		try {
82
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, brandRepository.selectById(id));
-
 
83
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
80
			return responseSender.ok(brandRepository.selectById(id));
84
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
81
		}catch (ProfitMandiBusinessException profitMandiBusinessException) {
85
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
82
			LOGGER.error("ProfitMandi error: ",  profitMandiBusinessException);
86
			final Response response=new Response(profitMandiBusinessException.getRejectedType(), profitMandiBusinessException.getRejectedValue(),profitMandiBusinessException.getCode(), profitMandiBusinessException.getMessage());
-
 
87
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
-
 
88
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
83
			return responseSender.badRequest(profitMandiBusinessException);
89
		}
84
		}
90
	}
85
	}
91
	
86
	
92
	
87
	
93
}
88
}