Subversion Repositories SmartDukaan

Rev

Rev 21390 | Rev 21431 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21390 ashik.ali 1
package com.spice.profitmandi.web.controller;
2
 
3
import java.time.LocalDateTime;
4
 
5
import javax.servlet.http.HttpServletRequest;
6
 
7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.http.HttpStatus;
11
import org.springframework.http.ResponseEntity;
12
import org.springframework.stereotype.Controller;
13
import org.springframework.web.bind.annotation.RequestMapping;
14
import org.springframework.web.bind.annotation.RequestMethod;
15
import org.springframework.web.bind.annotation.RequestParam;
16
 
17
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
18
import com.spice.profitmandi.common.model.ProfitMandiConstants;
19
import com.spice.profitmandi.dao.repository.AddressRepository;
20
import com.spice.profitmandi.web.model.ProfitMandiResponse;
21
import com.spice.profitmandi.web.model.Response;
22
import com.spice.profitmandi.web.model.ResponseStatus;
23
 
24
@Controller
25
public class AddressController {
26
 
27
	private static final Logger LOGGER=LoggerFactory.getLogger(AddressController.class);
28
 
29
	@Autowired
30
	AddressRepository addressRepository;
31
 
32
	@RequestMapping(value = ProfitMandiConstants.URL_ADDRESS_ALL, method=RequestMethod.GET)
33
	public ResponseEntity<?> getAll(HttpServletRequest request){
34
		LOGGER.info("requested url : "+request.getRequestURL().toString());
21426 ashik.ali 35
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, addressRepository.selectAll());
36
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
21390 ashik.ali 37
	}
21426 ashik.ali 38
 
21390 ashik.ali 39
	@RequestMapping(value = ProfitMandiConstants.URL_ADDRESS_ID, method=RequestMethod.GET)
21426 ashik.ali 40
	public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") long id){
21390 ashik.ali 41
		LOGGER.info("requested url : "+request.getRequestURL().toString());
42
		try {
43
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, addressRepository.selectById(id));
44
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
45
		}catch (ProfitMandiBusinessException pmbe) {
46
			LOGGER.error("ProfitMandi error: ", pmbe);
47
			final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
48
			final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
49
			return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
50
		}
51
	}
52
 
53
 
54
}