Skip to content

Commit

Permalink
fix(bookings): /booked route to return more results
Browse files Browse the repository at this point in the history
by default, also returns the correct link header for the next set of results
  • Loading branch information
stakach committed Dec 4, 2024
1 parent 52d7308 commit e7141cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ shards:

opentelemetry-instrumentation:
git: https://github.com/wyhaines/opentelemetry-instrumentation.cr.git
version: 0.5.4+git.commit.9b26aabef208b9eb0bf4612788362fa41768790b
version: 0.5.5+git.commit.83eace832dad20a71231e71a42258538b05fb193

opentelemetry-sdk:
git: https://github.com/wyhaines/opentelemetry-sdk.cr.git
Expand Down
13 changes: 7 additions & 6 deletions src/controllers/bookings.cr
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ class Bookings < Application
@[AC::Param::Info(description: "the recurring bookings index of the result set. Used to implement pagination with recurring bookings")]
recurrence : Int32 = 0,
@[AC::Param::Info(description: "filters bookings based on the permission level. Options: PRIVATE, OPEN, PUBLIC", example: "PUBLIC")]
permission : String? = nil
permission : String? = nil,
link_ext : String? = nil
) : Array(Booking)
query = Booking.by_tenant(tenant.id)

Expand Down Expand Up @@ -265,7 +266,7 @@ class Bookings < Application
params["offset"] = range_end.to_s
params["limit"] = limit.to_s
params["recurrence"] = details.next_idx.to_s
response.headers["Link"] = %(<#{base_route}?#{params}>; rel="next")
response.headers["Link"] = %(<#{base_route}/#{link_ext}?#{params}>; rel="next")
end
else
range_end = result.size + offset
Expand All @@ -276,7 +277,7 @@ class Bookings < Application
if range_end < total
params["offset"] = range_end.to_s
params["limit"] = limit.to_s
response.headers["Link"] = %(<#{base_route}?#{params}>; rel="next")
response.headers["Link"] = %(<#{base_route}/#{link_ext}?#{params}>; rel="next")
end
end

Expand Down Expand Up @@ -322,8 +323,8 @@ class Bookings < Application
event_id : String? = nil,
@[AC::Param::Info(description: "filters bookings associated with an event, such as an Office365 Calendar event ical_uid", example: "[email protected]")]
ical_uid : String? = nil,
@[AC::Param::Info(description: "the maximum number of results to return", example: "10000")]
limit : Int32 = 100,
@[AC::Param::Info(description: "the maximum number of results to return", example: "100000")]
limit : Int32 = 100000,
@[AC::Param::Info(description: "the starting offset of the result set. Used to implement pagination")]
offset : Int32 = 0,
@[AC::Param::Info(description: "filters bookings based on the permission level. Options: PRIVATE, OPEN, PUBLIC", example: "PUBLIC")]
Expand All @@ -332,7 +333,7 @@ class Bookings < Application
result = index(starting: starting, ending: ending, booking_type: booking_type, deleted_flag: false, include_checked_out: false,
checked_out_flag: false, zones: zones, user_email: user_email, user_id: user_id, include_booked_by: include_booked_by, checked_in: checked_in,
created_before: created_before, created_after: created_after, approved: approved, rejected: false, extension_data: extension_data, state: state,
department: department, event_id: event_id, ical_uid: ical_uid, limit: limit, offset: offset, permission: permission)
department: department, event_id: event_id, ical_uid: ical_uid, limit: limit, offset: offset, permission: permission, link_ext: "booked")
asset_ids = [] of String
result.each { |b| asset_ids.concat(b.asset_ids) unless b.checked_in_at || b.deleted }
asset_ids.uniq!
Expand Down

0 comments on commit e7141cd

Please sign in to comment.