Rev 21390 | Rev 21431 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.controller;import java.time.LocalDateTime;import javax.servlet.http.HttpServletRequest;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.http.HttpStatus;import org.springframework.http.ResponseEntity;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.common.model.ProfitMandiConstants;import com.spice.profitmandi.dao.repository.AddressRepository;import com.spice.profitmandi.web.model.ProfitMandiResponse;import com.spice.profitmandi.web.model.Response;import com.spice.profitmandi.web.model.ResponseStatus;@Controllerpublic class AddressController {private static final Logger LOGGER=LoggerFactory.getLogger(AddressController.class);@AutowiredAddressRepository addressRepository;@RequestMapping(value = ProfitMandiConstants.URL_ADDRESS_ALL, method=RequestMethod.GET)public ResponseEntity<?> getAll(HttpServletRequest request){LOGGER.info("requested url : "+request.getRequestURL().toString());final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, addressRepository.selectAll());return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);}@RequestMapping(value = ProfitMandiConstants.URL_ADDRESS_ID, method=RequestMethod.GET)public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") long id){LOGGER.info("requested url : "+request.getRequestURL().toString());try {final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, addressRepository.selectById(id));return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);}catch (ProfitMandiBusinessException pmbe) {LOGGER.error("ProfitMandi error: ", pmbe);final Response response=new Response(pmbe.getRejectedType(), pmbe.getRejectedValue(),pmbe.getCode(), pmbe.getMessage());final ProfitMandiResponse<Response> chatOnResponse=new ProfitMandiResponse<Response>(LocalDateTime.now(), request.getRequestURL().toString(), HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.FAILURE, response);return new ResponseEntity<>(chatOnResponse,HttpStatus.BAD_REQUEST);}}}