Skip to content

Commit

Permalink
feat: PPT-54 updated guests endpoint to use full text search capabili…
Browse files Browse the repository at this point in the history
…ties (#338)
  • Loading branch information
naqvis authored Jan 9, 2025
1 parent 949da77 commit ee2da65
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 20 deletions.
8 changes: 4 additions & 4 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ shards:

action-controller:
git: https://github.com/spider-gazelle/action-controller.git
version: 7.5.0
version: 7.5.1

active-model:
git: https://github.com/spider-gazelle/active-model.git
Expand Down Expand Up @@ -127,7 +127,7 @@ shards:

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

opentelemetry-sdk:
git: https://github.com/wyhaines/opentelemetry-sdk.cr.git
Expand All @@ -151,7 +151,7 @@ shards:

pg-orm:
git: https://github.com/spider-gazelle/pg-orm.git
version: 1.1.2+git.commit.9b340ee269cd4a10ed6c5b51235cbaf45fc380e1
version: 1.1.2+git.commit.7714bb4d3e57fadcfded9d2e17247b5d3506e379

place_calendar:
git: https://github.com/placeos/calendar.git
Expand All @@ -167,7 +167,7 @@ shards:

placeos-models:
git: https://github.com/placeos/models.git
version: 9.60.1
version: 9.61.0

pool:
git: https://github.com/ysbaddaden/pool.git
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/bookings_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe Bookings do

zones1 = booking1.zones.not_nil!
zones_string = "#{zones1.first},#{booking2.zones.not_nil!.last},,#{booking3.zones.not_nil!.last}"
route = "#{BOOKINGS_BASE}?period_start=#{starting}&period_end=#{ending}&type=desk&zones=#{zones_string}&limit=2"
route = "#{BOOKINGS_BASE}/?period_start=#{starting}&period_end=#{ending}&type=desk&zones=#{zones_string}&limit=2"
result = client.get(route, headers: headers)

result.success?.should be_true
Expand Down
1 change: 0 additions & 1 deletion spec/controllers/events_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ describe Events do
guests.compact_map(&.organisation).should eq(["Google inc"])
guests.compact_map(&.notes).should eq(["some notes"])
guests.compact_map(&.photo).should eq(["http://example.com/first.jpg"])
guests.compact_map(&.searchable).should eq(["[email protected] john jon google inc 012334446", "[email protected] [email protected] "])
guests.compact_map(&.extension_data).should eq([{"fizz" => "buzz"}, {} of String => String?])
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/recurring_bookings_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe Bookings do
# make initial request
zones1 = booking1.zones.not_nil!
zones_string = "#{zones1.first},#{booking2.zones.not_nil!.last},,#{booking3.zones.not_nil!.last}"
route = "#{BOOKINGS_BASE}?period_start=#{starting}&period_end=#{ending}&type=desk&zones=#{zones_string}&limit=2"
route = "#{BOOKINGS_BASE}/?period_start=#{starting}&period_end=#{ending}&type=desk&zones=#{zones_string}&limit=2"
result = client.get(route, headers: headers)

result.success?.should be_true
Expand Down
19 changes: 6 additions & 13 deletions src/controllers/guests.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "csv"

class Guests < Application
base "/api/staff/v1/guests"

Expand Down Expand Up @@ -203,17 +201,12 @@ class Guests < Application
.limit(1500).to_a
else
# Return guests based on the filter query
csv = CSV.new(search_query, strip: true, separator: ' ')
csv.next
parts = csv.row.to_a

sql_query = Guest.by_tenant(tenant.id)
parts.each do |part|
next if part.empty?
sql_query = sql_query.where("searchable LIKE ?", "%#{part}%")
end

sql_query.order(:name).limit(1500).to_a
tsquery = search_query.split(/\s+/).map { |part| "#{part}:*" }.join(" & ")
Guest
.by_tenant(tenant.id.not_nil!)
.where("tsv_search @@ to_tsquery(?)", tsquery)
.order(:name)
.limit(1500).to_a
end
end

Expand Down

0 comments on commit ee2da65

Please sign in to comment.