| 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 |
|
- |
|
| 5 |
import javax.servlet.http.HttpServletRequest;
|
3 |
import javax.servlet.http.HttpServletRequest;
|
| 6 |
|
4 |
|
| 7 |
import org.slf4j.Logger;
|
5 |
import org.slf4j.Logger;
|
| 8 |
import org.slf4j.LoggerFactory;
|
6 |
import org.slf4j.LoggerFactory;
|
| 9 |
import org.springframework.beans.factory.annotation.Autowired;
|
7 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 10 |
import org.springframework.http.HttpStatus;
|
- |
|
| 11 |
import org.springframework.http.ResponseEntity;
|
8 |
import org.springframework.http.ResponseEntity;
|
| 12 |
import org.springframework.stereotype.Controller;
|
9 |
import org.springframework.stereotype.Controller;
|
| 13 |
import org.springframework.web.bind.annotation.RequestMapping;
|
10 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 14 |
import org.springframework.web.bind.annotation.RequestMethod;
|
11 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 15 |
import org.springframework.web.bind.annotation.RequestParam;
|
12 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 16 |
|
13 |
|
| 17 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
14 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 18 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
15 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 19 |
import com.spice.profitmandi.dao.repository.AddressRepository;
|
16 |
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;
|
17 |
import com.spice.profitmandi.web.util.ResponseSender;
|
| 23 |
|
18 |
|
| 24 |
@Controller
|
19 |
@Controller
|
| 25 |
public class AddressController {
|
20 |
public class AddressController {
|
| 26 |
|
21 |
|
| - |
|
22 |
@Autowired
|
| - |
|
23 |
ResponseSender<?> responseSender;
|
| - |
|
24 |
|
| 27 |
private static final Logger LOGGER=LoggerFactory.getLogger(AddressController.class);
|
25 |
private static final Logger LOGGER=LoggerFactory.getLogger(AddressController.class);
|
| 28 |
|
26 |
|
| 29 |
@Autowired
|
27 |
@Autowired
|
| 30 |
AddressRepository addressRepository;
|
28 |
AddressRepository addressRepository;
|
| 31 |
|
29 |
|
| 32 |
@RequestMapping(value = ProfitMandiConstants.URL_ADDRESS_ALL, method=RequestMethod.GET)
|
30 |
@RequestMapping(value = ProfitMandiConstants.URL_ADDRESS_ALL, method=RequestMethod.GET)
|
| 33 |
public ResponseEntity<?> getAll(HttpServletRequest request){
|
31 |
public ResponseEntity<?> getAll(HttpServletRequest request){
|
| 34 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
32 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 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);
|
33 |
return responseSender.ok(addressRepository.selectAll());
|
| 37 |
}
|
34 |
}
|
| 38 |
|
35 |
|
| 39 |
@RequestMapping(value = ProfitMandiConstants.URL_ADDRESS_ID, method=RequestMethod.GET)
|
36 |
@RequestMapping(value = ProfitMandiConstants.URL_ADDRESS_ID, method=RequestMethod.GET)
|
| 40 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
37 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id){
|
| 41 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
38 |
LOGGER.info("requested url : "+request.getRequestURL().toString());
|
| 42 |
try {
|
39 |
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);
|
40 |
return responseSender.ok(addressRepository.selectById(id));
|
| 45 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
41 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 46 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
42 |
LOGGER.error("ProfitMandi error: ", profitMandiBusinessException);
|
| 47 |
final Response response=new Response(profitMandiBusinessException.getRejectedType(), profitMandiBusinessException.getRejectedValue(),profitMandiBusinessException.getCode(), profitMandiBusinessException.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);
|
43 |
return responseSender.badRequest(profitMandiBusinessException);
|
| 50 |
}
|
44 |
}
|
| 51 |
}
|
45 |
}
|
| 52 |
|
46 |
|
| 53 |
|
47 |
|
| 54 |
}
|
48 |
}
|