Skip to content

Commit

Permalink
feat: PPT-642 Added place controller (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
naqvis authored Sep 9, 2024
1 parent 97d946b commit b0394e6
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 3 deletions.
226 changes: 226 additions & 0 deletions OPENAPI_DOC.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6691,6 +6691,130 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/HealthCheck__BuildInfo'
/api/staff/v1/place:
get:
summary: Retrieves a list of rooms from the tenant place object
description: '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'
tags:
- Place
operationId: Place_index
parameters:
- name: match
in: query
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
required: false
schema:
type: string
nullable: true
- name: filter
in: query
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')
required: false
schema:
type: string
nullable: true
- name: top
in: query
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"
required: false
schema:
type: integer
format: Int32
nullable: true
- name: skip
in: query
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
required: false
schema:
type: integer
format: Int32
nullable: true
responses:
200:
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Office365__Room'
429:
description: Too Many Requests
content:
application/json:
schema:
$ref: '#/components/schemas/Application__CommonError'
400:
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/Application__CommonError'
401:
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/Application__CommonError'
403:
description: Forbidden
404:
description: Not Found
content:
application/json:
schema:
$ref: '#/components/schemas/Application__CommonError'
511:
description: Network Authentication Required
content:
application/json:
schema:
$ref: '#/components/schemas/Application__CommonError'
406:
description: Not Acceptable
content:
application/json:
schema:
$ref: '#/components/schemas/Application__ContentError'
415:
description: Unsupported Media Type
content:
application/json:
schema:
$ref: '#/components/schemas/Application__ContentError'
422:
description: Unprocessable Entity
content:
application/json:
schema:
$ref: '#/components/schemas/Application__ValidationError'
500:
description: Internal Server Error
content:
application/json:
schema:
$ref: '#/components/schemas/Application__CommonError'
405:
description: Method Not Allowed
content:
application/json:
schema:
$ref: '#/components/schemas/Application__CommonError'
/api/staff/v1/people:
get:
summary: Retrieves a list of users from the organization directory
Expand Down Expand Up @@ -11824,6 +11948,108 @@ components:
required:
- commit
- build_time
Office365__Room:
type: object
properties:
address:
type: object
properties:
city:
type: string
nullable: true
state:
type: string
nullable: true
street:
type: string
nullable: true
countryOrRegion:
type: string
nullable: true
postalCode:
type: string
nullable: true
nullable: true
displayName:
type: string
geoCoordinates:
type: object
properties:
altitudeAccuracy:
type: number
format: Float64
nullable: true
accuracy:
type: number
format: Float64
nullable: true
altitude:
type: number
format: Float64
nullable: true
latitude:
type: number
format: Float64
nullable: true
longitude:
type: number
format: Float64
nullable: true
nullable: true
id:
type: string
phone:
type: string
nullable: true
audioDeviceName:
type: string
nullable: true
bookingType:
type: string
enum:
- reserved
- standard
nullable: true
building:
type: string
nullable: true
capacity:
type: integer
format: Int32
nullable: true
displayDeviceName:
type: string
nullable: true
emailAddress:
type: string
nullable: true
floorLabel:
type: string
nullable: true
floorNumber:
type: integer
format: Int32
nullable: true
isWheelChairAccessible:
type: boolean
nullable: true
label:
type: string
nullable: true
nickname:
type: string
nullable: true
tags:
type: array
items:
type: string
nullable: true
videoDeviceName:
type: string
nullable: true
required:
- displayName
- id
PlaceCalendar__User:
type: object
properties:
Expand Down
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
20 changes: 20 additions & 0 deletions spec/controllers/place_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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 = Array(Office365::Room).from_json(client.get(PLACE_BASE, headers: headers).body)
rooms.size.should eq(2)
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"
}
]
}
2 changes: 1 addition & 1 deletion src/controllers/events.cr
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Events < Application
private def confirm_access_for_add_attendee(
event : PlaceCalendar::Event,
metadata : EventMetadata,
system : PlaceOS::Client::API::Models::System? = nil,
system : PlaceOS::Client::API::Models::System? = nil
)
return if metadata.permission.public?
return if is_support?
Expand Down
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
) : Array(Office365::Room)
case client.client_id
when :office365
client.calendar.as(PlaceCalendar::Office365).client.list_rooms(match: match, filter: filter, top: top, skip: skip).as(Office365::Rooms).value
else
raise Error::NotImplemented.new("place query is not available for #{client.client_id}")
end
end
end

0 comments on commit b0394e6

Please sign in to comment.