RATE & CALENDAR API

Update Calendar Prices API

Technical documentation for the method that updates room prices by date for a selected room and rate plan.

Description

This endpoint is used to update calendar prices for a specific room and rate plan. It receives the room ID, the rate plan ID, and a list of daily prices. For each date received, the method updates the existing RoomAvailability and RateRoomAvailability records or creates new ones if they do not already exist.

After saving the prices, the method also triggers derived price recalculation for rate plans linked to the selected rate plan.

Endpoint

POST /updateCalendarPrices

Parameters Received

This method receives two request parameters and one request body.

  • roomId (RequestParam, Long): identifies the room whose calendar prices must be updated.
  • ratePlanId (RequestParam, Long): identifies the rate plan inside the selected room that must be updated.
  • priceDataList (RequestBody, List<PriceData>): list of price entries to update, one entry per date.
Fields Used from PriceData

Based on the method body, the following PriceData fields are accessed directly:

  • date: converted to LocalDate and used to find or create RoomAvailability.
  • price: saved into RateRoomAvailability.price.
  • propertyName: used only when the room is not found, for the notification email method.
Request Example
POST /updateCalendarPrices?roomId=12&ratePlanId=4

[
  {
    "date": "2026-03-10T00:00:00.000+00:00",
    "price": 120.0,
    "propertyName": "Hotel Example"
  },
  {
    "date": "2026-03-11T00:00:00.000+00:00",
    "price": 135.0,
    "propertyName": "Hotel Example"
  }
]

Process

  • The method first checks whether priceDataList is null or empty.
  • If the list is empty, it sends an internal email notification and returns an error text message.
  • The room is searched in the database using roomRepository.findById(roomId).
  • If the room does not exist, a notification email is sent and the method returns an error text message.
  • The rate plan is searched inside room.getRatePlans() using the provided ratePlanId.
  • If the rate plan is not found, the method throws a RuntimeException with the message "Rate plan not found".
  • All dates from priceDataList are converted from Date to LocalDate.
  • Existing RoomAvailability records for the room and those dates are loaded in one query.
  • The existing availabilities are mapped by date for faster lookup.
  • For each PriceData item, the method checks whether a RoomAvailability already exists for that date.
  • If the availability exists, the method searches for a matching RateRoomAvailability for the selected rate plan.
  • If the rate entry exists and the price is different, the price is updated.
  • If the rate entry does not exist, a new RateRoomAvailability is created.
  • If the room availability for the date does not exist, a new RoomAvailability is created with default values and a new RateRoomAvailability is attached to it.
  • Updated and new RoomAvailability entities are saved with saveAll(...).
  • Updated and new RateRoomAvailability entities are saved with saveAll(...).
  • The method calls derivedPriceService.processRatePlanChange(ratePlanId, false) to cascade the price change to derived rate plans.
  • The method returns a success text message.

Request

Request parameters: roomId and ratePlanId. Content-Type: application/json

Authorization: Bearer <token>

Field Type Description
roomId Long Room identifier
ratePlanId Long Rate plan identifier
date Date Date to update
price Number Price value for that date
propertyName String Property name supplied in the payload
Request Body Example
POST /updateCalendarPrices?roomId=12&ratePlanId=4
[
{"date": "2026-03-10T00:00:00.000+00:00", "price": 120.0, "propertyName": "Hotel Example"},
{"date": "2026-03-11T00:00:00.000+00:00", "price": 135.0, "propertyName": "Hotel Example"}
]

Response Returned

This endpoint returns plain text (String), not a JSON object. The returned value depends on the execution path.

Possible Responses
Success response:
"Price is successfully updated"
Response when the request body is empty or null:
"price is received as empty list " + roomId
Response when the room does not exist:
"Room with ID: " + roomId + " not exist in db, check room id " + roomId + " in allbookers"
Response when the rate plan is missing:
RuntimeException: "Rate plan not found"

Example Response

Price is successfully updated

Notes

  • The operation is executed within a single transactional context, ensuring that all updates are processed together.
  • The method relies on the presence of at least one element in the provided price data when handling cases where the room is not found. This is considered safe only because an earlier validation ensures the list is not empty.
  • Price comparisons may be sensitive to differences in numeric formats, which could affect accuracy if values are not handled consistently.
  • When new availability records are created, they are initialized with zero values for both total and occupied rooms. This behavior should align with the intended business logic.
  • The endpoint returns plain text messages rather than structured responses, which limits the ability to convey detailed HTTP status information.
  • As a result, API consumers should expect a simple text response and not a structured JSON format.