Skip to content

Commit

Permalink
feat: PPT-1326 Add endpoint to provide a list of booking ids
Browse files Browse the repository at this point in the history
  • Loading branch information
naqvis committed Jun 28, 2024
1 parent a34170d commit 4d2b7aa
Show file tree
Hide file tree
Showing 3 changed files with 395 additions and 4 deletions.
302 changes: 302 additions & 0 deletions OPENAPI_DOC.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ paths:
schema:
type: integer
format: Int32
- name: permission
in: query
description: 'filters bookings based on the permission level. Options: PRIVATE,
OPEN, PUBLIC'
example: PUBLIC
required: false
schema:
type: string
nullable: true
responses:
200:
description: OK
Expand Down Expand Up @@ -405,6 +414,287 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Bookings__BookingError'
/api/staff/v1/bookings/booked:
get:
summary: lists bookings IDs based on the parameters provided
description: 'lists bookings IDs based on the parameters provided
booking_type is required unless event_id or ical_uid is present'
tags:
- Bookings
operationId: Bookings#booked
parameters:
- name: period_start
in: query
description: booking period start as a unix epoch
example: "1661725146"
required: false
schema:
type: integer
format: Int64
- name: period_end
in: query
description: booking period end as a unix epoch
example: "1661743123"
required: false
schema:
type: integer
format: Int64
- name: type
in: query
description: the generic name of the asset whose bookings you wish to view
example: desk
required: false
schema:
type: string
nullable: true
- name: deleted
in: query
description: when true, it returns deleted bookings
example: "true"
required: false
schema:
type: boolean
- name: include_checked_out
in: query
description: when true, returns all bookings including checked out ones
example: "true"
required: false
schema:
type: boolean
- name: checked_out
in: query
description: when true, only returns checked out bookings, unless `include_checked_out=true`
example: "true"
required: false
schema:
type: boolean
- name: zones
in: query
description: this filters only bookings in the zones provided, multiple zones
can be provided comma seperated
example: zone-123,zone-456
required: false
schema:
type: string
nullable: true
- name: email
in: query
description: filters bookings owned by this user email
example: user@org.com
required: false
schema:
type: string
nullable: true
- name: user
in: query
description: filters bookings owned by this user id
example: user-1234
required: false
schema:
type: string
nullable: true
- name: include_booked_by
in: query
description: if `email` or `user` parameters are set, this includes bookings
that user booked on behalf of others
example: "true"
required: false
schema:
type: boolean
nullable: true
- name: checked_in
in: query
description: filters bookings that have been checked in or not
example: "true"
required: false
schema:
type: boolean
nullable: true
- name: created_before
in: query
description: filters bookings that were created before the unix epoch specified
example: "1661743123"
required: false
schema:
type: integer
format: Int64
nullable: true
- name: created_after
in: query
description: filters bookings that were created after the unix epoch specified
example: "1661743123"
required: false
schema:
type: integer
format: Int64
nullable: true
- name: approved
in: query
description: filters bookings that are approved or not
example: "true"
required: false
schema:
type: boolean
nullable: true
- name: rejected
in: query
description: filters bookings that are rejected or not
example: "true"
required: false
schema:
type: boolean
nullable: true
- name: extension_data
in: query
description: filters bookings with matching extension data entries
example: '{"entry1":"value to match","entry2":1234}'
required: false
schema:
type: string
nullable: true
- name: state
in: query
description: filters on the booking process state, a user defined value
example: pending-approval
required: false
schema:
type: string
nullable: true
- name: department
in: query
description: filters bookings owned by a department, a user defined value
example: accounting
required: false
schema:
type: string
nullable: true
- name: event_id
in: query
description: filters bookings associated with an event, such as an Office365
Calendar event id
example: AAMkAGVmMDEzMTM4LTZmYWUtNDdkNC1hMDZe
required: false
schema:
type: string
nullable: true
- name: ical_uid
in: query
description: filters bookings associated with an event, such as an Office365
Calendar event ical_uid
example: 19rh93h5t893h5v@calendar.iCloud.com
required: false
schema:
type: string
nullable: true
- name: limit
in: query
description: the maximum number of results to return
example: "10000"
required: false
schema:
type: integer
format: Int32
- name: offset
in: query
description: the starting offset of the result set. Used to implement pagination
required: false
schema:
type: integer
format: Int32
- name: permission
in: query
description: 'filters bookings based on the permission level. Options: PRIVATE,
OPEN, PUBLIC'
example: PUBLIC
required: false
schema:
type: string
nullable: true
responses:
200:
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Int64'
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'
409:
description: Conflict
content:
application/json:
schema:
$ref: '#/components/schemas/Bookings__BookingError'
410:
description: Gone
content:
application/json:
schema:
$ref: '#/components/schemas/Bookings__BookingError'
/api/staff/v1/bookings/{id}:
get:
summary: returns the booking requested
Expand Down Expand Up @@ -8294,6 +8584,9 @@ components:
type: integer
format: Int64
nullable: true
Int64:
type: integer
format: Int64
PlaceOS__Model__Guest:
type: object
properties:
Expand Down Expand Up @@ -9600,8 +9893,14 @@ components:
nullable: true
email:
type: string
phone:
type: string
nullable: true
username:
type: string
suspended:
type: boolean
nullable: true
required:
- id
- email
Expand Down Expand Up @@ -9646,6 +9945,9 @@ components:
office_location:
type: string
nullable: true
suspended:
type: boolean
nullable: true
PlaceOS__Model__Survey:
type: object
properties:
Expand Down
27 changes: 27 additions & 0 deletions spec/controllers/bookings_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,33 @@ describe Bookings do
body.size.should eq(1)
end

it "should return a list of bookings ids" do
tenant = get_tenant

booking1 = BookingsHelper.create_booking(tenant.id.not_nil!)
booking2 = BookingsHelper.create_booking(tenant.id.not_nil!)

starting = 5.minutes.from_now.to_unix
ending = 90.minutes.from_now.to_unix
route = "#{BOOKINGS_BASE}/booked?period_start=#{starting}&period_end=#{ending}&user=#{booking1.user_email}&type=desk"
body = JSON.parse(client.get(route, headers: headers).body).as_a

body.first.should eq(booking1.id)

# filter by zones
zones1 = booking1.zones.not_nil!
zones_string = "#{zones1.first},#{booking2.zones.not_nil!.last}"
route = "#{BOOKINGS_BASE}/booked?period_start=#{starting}&period_end=#{ending}&type=desk&zones=#{zones_string}"

body = JSON.parse(client.get(route, headers: headers).body).as_a
body.map(&.as_i).sort!.should eq [booking1.id, booking2.id]

# More filters by zones
route = "#{BOOKINGS_BASE}/booked?period_start=#{starting}&period_end=#{ending}&type=desk&zones=#{zones1.first}"
body = JSON.parse(client.get(route, headers: headers).body).as_a
body.first.in?([booking1.id, booking2.id]).should be_true
end

it "should supports pagination on list of bookings request" do
tenant = get_tenant

Expand Down
Loading

0 comments on commit 4d2b7aa

Please sign in to comment.