| 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 |
|
|
|
33 |
|
|
|
34 |
@RequestMapping(value = ProfitMandiConstants.URL_ADDRESS_ALL, method=RequestMethod.GET)
|
|
|
35 |
public ResponseEntity<?> getAll(HttpServletRequest request){
|
|
|
36 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
37 |
try {
|
|
|
38 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, addressRepository.selectAll());
|
|
|
39 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
40 |
}catch (Exception e) {
|
|
|
41 |
LOGGER.error("Internal Server Error : ",e);
|
|
|
42 |
final Response response=new Response("","","", e.getMessage());
|
|
|
43 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
|
|
|
44 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
@RequestMapping(value = ProfitMandiConstants.URL_ADDRESS_ID, method=RequestMethod.GET)
|
|
|
48 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
|
|
49 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
|
|
50 |
try {
|
|
|
51 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, addressRepository.selectById(id));
|
|
|
52 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
53 |
}catch (ProfitMandiBusinessException pmbe) {
|
|
|
54 |
LOGGER.error("ProfitMandi error: ", pmbe);
|
|
|
55 |
final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());
|
|
|
56 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);
|
|
|
57 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);
|
|
|
58 |
}catch (Exception e) {
|
|
|
59 |
LOGGER.error("Internal Server Error : ",e);
|
|
|
60 |
final Response response=new Response("","","", e.getMessage());
|
|
|
61 |
final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.FAILURE, response);
|
|
|
62 |
return new ResponseEntity<>(chatOnResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
}
|