Diarkis Room - How To Handle Room Properties

How To Get Room Property

property := room.GetProperty(roomID, "RoomName")
if property == nil {
    // property RoomName does not exist
}

How To Get Room Properties

properties := room.GetProperties(roomID)

How To Update Room Properties

Callback function is expected to return true if you update the room properties and return false if you do not update the properties.

_ := room.UpdatePropertis(roomID, func(properties map[string]interface{}) bool {
    if _, ok := properties["counter"]; !ok {
        properties["counter"] = 0
        return true
    }
    counter := properties["counter"].(int)
    properties["counter"] = counter + 1
    return true
})

Example of Room property update with failure

_ := room.UpdatePropertis(roomID, func(properties map[string]interface{}) bool {
    if _, ok := properties["booked"]; !ok {
        properties["booked"] = true
        return true
      }
      // The room has already been booked
      return false
})