Skip to content

Commit

Permalink
Add get_buildings
Browse files Browse the repository at this point in the history
  • Loading branch information
btb committed Jul 12, 2024
1 parent fc4c7ff commit 3d77667
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 12 additions & 1 deletion uw_mazevo/api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
from uw_mazevo import get_resource, post_resource
from uw_mazevo.models import Booking, Room, Status
from uw_mazevo.models import Booking, Building, Room, Status


class PublicConfiguration(object):
URL = "/api/PublicConfiguration/{}"

def get_buildings(self):
"""
Gets a list of Rooms. building_id of 0 returns all rooms.
"""
url = self.URL.format("Buildings")

buildings = []
for data in get_resource(url):
buildings.append(Building.from_json(data))
return buildings

def get_rooms(self, building_id=0):
"""
Gets a list of Rooms. building_id of 0 returns all rooms.
Expand Down
8 changes: 8 additions & 0 deletions uw_mazevo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ class Building(models.Model):
def __str__(self):
return self.description

@staticmethod
def from_json(data):
building = Building()
building.id = data["buildingId"]
building.description = data["description"]
building.time_zone = data["timeZone"]
return building


class Room(models.Model):
id = models.PositiveIntegerField(primary_key=True)
Expand Down

0 comments on commit 3d77667

Please sign in to comment.