예제 #1
0
  /**
   * This controller is used to book a spot
   *
   * @param spotBookedRequestDTO
   * @return SpotBookedResponseDTO
   * @throws Exception
   */
  @ApiOperation(value = "Book spot", notes = "Book a particular spot", httpMethod = "POST")
  @ApiResponses(
      value = {
        @ApiResponse(code = 500, message = "Internal Server error"),
        @ApiResponse(code = 403, message = "Forbidden"),
        @ApiResponse(code = 404, message = "Not Found"),
        @ApiResponse(code = 400, message = "Bad Request"),
        @ApiResponse(code = 201, message = "Created")
      })
  @RequestMapping(
      value = "/createPGW",
      method = RequestMethod.POST,
      consumes = "application/json",
      produces = "application/json")
  public ResponseEntity<SpotBookedResponseDTO> bookingPGW(
      @ApiParam @RequestBody SpotBookedRequestDTO spotBookedRequestDTO) throws BookingException {

    logger.debug(
        this.getClass().getSimpleName(),
        "CreateBooking",
        "Book a spot " + spotBookedRequestDTO.getSpotId());

    LocalDateTime datetime = spotBookedRequestDTO.getStartTime();

    assertNotBlank(spotBookedRequestDTO.getSpotId(), ErrorMessages.NULLSPOTID);
    assertNotBlank(spotBookedRequestDTO.getLotId(), ErrorMessages.NULLLOTID);
    assertNotBlank(spotBookedRequestDTO.getDongName(), "dongName cannot be null");
    assertNotBlank(spotBookedRequestDTO.getUserName(), "userName cannot be null");
    assertNotBlank(spotBookedRequestDTO.getVehicleNumber(), "vehicleNumber cannot be null");
    assertNotBlank(spotBookedRequestDTO.getPhoneNumber(), "PhoneNumber cannot be null");
    assertNotBlank(spotBookedRequestDTO.getUserId(), ErrorMessages.NULLUSERID);

    if (datetime.isBefore(LocalDateTime.now().minusMinutes(2))) {
      throw new BookingException(
          HttpConstants.BAD_REQUEST, ErrorMessages.INVALIDSTARTTIME, HttpStatus.BAD_REQUEST);
    } else if (spotBookedRequestDTO.getDuration() < 60) {
      logger.error(getClass().getSimpleName(), "Booking create", ErrorMessages.INVALIDDURATION);
      throw new BookingException(
          HttpConstants.BAD_REQUEST,
          "Duration cannot be less than 60 Minutes",
          HttpStatus.BAD_REQUEST);
    } else if (spotBookedRequestDTO.getDuration() % 10 > 0) {
      logger.error(getClass().getSimpleName(), "Booking create", ErrorMessages.INVALIDDURATION);
      throw new BookingException(
          HttpConstants.BAD_REQUEST, ErrorMessages.INVALIDDURATION, HttpStatus.BAD_REQUEST);
    }

    logger.debug("Request for Booking a Spot" + "\n" + spotBookedRequestDTO.toString());

    SpotBookedResponseDTO response = reservationService.bookingPGW(spotBookedRequestDTO);

    logger.debug("response to create API is " + "\n" + response.toString());
    return new ResponseEntity<>(response, HttpStatus.OK);
  }
예제 #2
0
  /**
   * This API creates a new entry for extend booking
   *
   * @requestBody SpotBookedRequestDTO
   * @return SpotBookedResponseDTO
   * @throws Exception
   */
  @ApiOperation(
      value = "Create Extend Booking",
      notes = "Creates entry for extend booking for a spot",
      httpMethod = "POST")
  @ApiResponses(
      value = {
        @ApiResponse(code = 500, message = "Internal Server error"),
        @ApiResponse(code = 403, message = "Forbidden"),
        @ApiResponse(code = 404, message = "Not Found"),
        @ApiResponse(code = 400, message = "Bad Request"),
        @ApiResponse(code = 201, message = "Created")
      })
  @RequestMapping(
      value = "/createExtendPGW",
      method = RequestMethod.POST,
      consumes = "application/json",
      produces = "application/json")
  @ResponseBody
  public ResponseEntity<SpotBookedResponseDTO> extendReservationPGW(
      @ApiParam @RequestBody SpotBookedRequestDTO spotbookedDTO) throws BookingException {

    logger.debug(
        this.getClass().getSimpleName(),
        "createExtendPGW",
        "Creates a new reservation for extending a spot" + spotbookedDTO.getSpotId());

    assertNotBlank(spotbookedDTO.getSpotId(), ErrorMessages.NULLSPOTID);
    assertNotBlank(spotbookedDTO.getLotId(), ErrorMessages.NULLLOTID);
    assertNotBlank(spotbookedDTO.getDongName(), "dongName cannot be null");
    assertNotBlank(spotbookedDTO.getUserName(), "userName cannot be null");
    assertNotBlank(spotbookedDTO.getVehicleNumber(), "vehicleNumber cannot be null");
    assertNotBlank(spotbookedDTO.getPhoneNumber(), "PhoneNumber cannot be null");
    assertNotBlank(spotbookedDTO.getUserId(), ErrorMessages.NULLUSERID);
    assertNotBlank(spotbookedDTO.getReservationId(), ErrorMessages.NULLRESERVATIONID);

    logger.debug(
        "/createExtend API request body for "
            + spotbookedDTO.getReservationId()
            + " is "
            + "\n"
            + spotbookedDTO.toString());
    SpotBookedResponseDTO response = reservationService.createExtendBookingPGW(spotbookedDTO);

    logger.debug(
        "/createExtend API response body for "
            + spotbookedDTO.getReservationId()
            + " is "
            + "\n"
            + response.toString());
    return new ResponseEntity<>(response, HttpStatus.OK);
  }