Skip to content

Commit

Permalink
feat: PPT-642 Added place controller
Browse files Browse the repository at this point in the history
  • Loading branch information
naqvis committed Sep 5, 2024
1 parent 97d946b commit aa5c89f
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 2 deletions.
4 changes: 2 additions & 2 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ shards:

office365:
git: https://github.com/placeos/office365.git
version: 1.25.3
version: 1.25.4

openssl_ext:
git: https://github.com/spider-gazelle/openssl_ext.git
Expand Down Expand Up @@ -159,7 +159,7 @@ shards:

placeos:
git: https://github.com/placeos/crystal-client.git
version: 2.11.0
version: 2.11.6

placeos-log-backend:
git: https://github.com/place-labs/log-backend.git
Expand Down
21 changes: 21 additions & 0 deletions spec/controllers/place_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "../spec_helper"

describe Place do
client = AC::SpecHelper.client
headers = Mock::Headers.office365_guest

describe "#index" do
it "should return a list of rooms" do
WebMock.stub(:post, "https://login.microsoftonline.com/bb89674a-238b-4b7d-91ec-6bebad83553a/oauth2/v2.0/token")
.to_return(body: File.read("./spec/fixtures/tokens/o365_token.json"))
WebMock.stub(:get, "https://graph.microsoft.com/v1.0/places/microsoft.graph.room")
.to_return(body: File.read("./spec/fixtures/place/index.json"))

rooms = Office365::PlaceList.from_json(client.get(PLACE_BASE, headers: headers).body)
rooms.value.size.should eq(2)
rooms.value.first.is_a?(Office365::Room).should be_true
end
end
end

PLACE_BASE = Place.base_route
68 changes: 68 additions & 0 deletions spec/fixtures/place/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#places/microsoft.graph.room",
"value": [
{
"id": "3162F1E1-C4C0-604B-51D8-91DA78989EB1",
"emailAddress": "cf100@contoso.com",
"displayName": "Conf Room 100",
"address": {
"street": "4567 Main Street",
"city": "Buffalo",
"state": "NY",
"postalCode": "98052",
"countryOrRegion": "USA"
},
"geoCoordinates": {
"latitude": 47.640568390488626,
"longitude": -122.1293731033803
},
"phone": "000-000-0000",
"nickname": "Conf Room",
"label": "100",
"capacity": 50,
"building": "1",
"floorNumber": 1,
"isManaged": true,
"isWheelChairAccessible": false,
"bookingType": "standard",
"tags": [
"bean bags"
],
"audioDeviceName": null,
"videoDeviceName": null,
"displayDevice": "surface hub"
},
{
"id": "3162F1E1-C4C0-604B-51D8-91DA78970B97",
"emailAddress": "cf200@contoso.com",
"displayName": "Conf Room 200",
"address": {
"street": "4567 Main Street",
"city": "Buffalo",
"state": "NY",
"postalCode": "98052",
"countryOrRegion": "USA"
},
"geoCoordinates": {
"latitude": 47.640568390488625,
"longitude": -122.1293731033802
},
"phone": "000-000-0000",
"nickname": "Conf Room",
"label": "200",
"capacity": 40,
"building": "2",
"floorNumber": 2,
"isManaged": true,
"isWheelChairAccessible": false,
"bookingType": "standard",
"tags": [
"benches",
"nice view"
],
"audioDeviceName": null,
"videoDeviceName": null,
"displayDevice": "surface hub"
}
]
}
26 changes: 26 additions & 0 deletions src/controllers/place.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Place < Application
base "/api/staff/v1/place"

# Retrieves a list of rooms from the tenant place object
# This function supports advanced filtering using Azure AD filter syntax.
# For more information on Azure AD filter syntax, visit:
# https://learn.microsoft.com/en-us/graph/filter-query-parameter?tabs=http
@[AC::Route::GET("/")]
def index(
@[AC::Param::Info(name: "match", description: "An optional query parameter to return a subset of properties for a resource. With match, you can specify a subset or a superset of the default properties.", example: "id,displayName")]
match : String? = nil,
@[AC::Param::Info(name: "filter", description: "An optional advanced search filter using Azure AD filter syntax to query parameter to retrieve a subset of a collection..", example: "startsWith(givenName,'ben') or startsWith(surname,'ben')")]
filter : String? = nil,
@[AC::Param::Info(description: "Optional: Use the top query parameter to specify the number of items to be included in the result. Default value is 100", example: "100")]
top : Int32? = nil,
@[AC::Param::Info(description: "Optional: Use skip query parameter to set the number of items to skip at the start of a collection.", example: "21 to retrieve search results from 21st record")]
skip : Int32? = nil
) : Office365::PlaceList
case client.client_id
when :office365
client.calendar.as(PlaceCalendar::Office365).client.list_rooms(match: match, filter: filter, top: top, skip: skip)
else
raise Error::NotImplemented.new("place query is not available for #{client.client_id}")
end
end
end

0 comments on commit aa5c89f

Please sign in to comment.