spree_cm_commissioner 2.4.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f63b4eb2a25d5dff782d61eb3df12b639c261a418213940ed12d8b9b483b9a1
4
- data.tar.gz: 6682f9d70eb92effa0345aee38da3d483c8bf555a74da8c88fc52ddb7553a2e5
3
+ metadata.gz: 4e32e4116a234b679abcfe3a9d7005bd61890d80936839c32330ecf2b421dadf
4
+ data.tar.gz: a7759f377e09d49281150257a496e44af61e4cabb67a8bec0bacb20a73ea439d
5
5
  SHA512:
6
- metadata.gz: 7abea09634def1e05f839d075bb5fcd1cdfac7bc13ed0392ac6c5aa60e5f9aef3a54600d69afa63778aca0ddf62e09ffc1f5c0200dd88f728b7a1bcd0272faea
7
- data.tar.gz: f102b65bf2526916e47c728b0e50eebe7ce188b96bc0f206d92be0434499a734fe0c434f5d364554c20d5bcf0cec20f4b2bdb945d321c213ddb03c1678d9f135
6
+ metadata.gz: 5119cedb570e77e3417bf723ea84926231e4d72000686312a194c1cfb4764061b5df9801923a5db629d8b8adccfd8a70378a238a0c099af46abe8f5c6a2da1d0
7
+ data.tar.gz: adeee4909603c0294be64345ea3de5b310e2dcaa174669137794b56dd23b800ddd9a1f429da636df23953d80154a3b96835cb19a81274fc0908edaae1ebd13d9
data/Gemfile.lock CHANGED
@@ -34,7 +34,7 @@ GIT
34
34
  PATH
35
35
  remote: .
36
36
  specs:
37
- spree_cm_commissioner (2.4.0)
37
+ spree_cm_commissioner (2.4.1)
38
38
  activerecord-multi-tenant
39
39
  activerecord_json_validator (~> 2.1, >= 2.1.3)
40
40
  aws-sdk-cloudfront
@@ -1,24 +1,42 @@
1
- # API endpoint for searching places that are used in routes by keyword.
1
+ # API endpoint for searching places connected to a specific place via routes.
2
2
  #
3
3
  # GET /api/v2/storefront/route_places
4
4
  #
5
- # Searches for places (origins or destinations) that are used in existing routes,
6
- # filtered by keyword search on place names.
5
+ # Finds places (origins or destinations) that are connected to a given place through existing routes.
6
+ # Optionally filters results by keyword. Supports two modes:
7
+ #
8
+ # Usage 1: Connected places (requires place_id)
9
+ # - Finds places connected to a specific place via routes
10
+ # - Returns origins/destinations that have routes with the specified place
11
+ #
12
+ # Usage 2: Keyword search (requires query, place_id optional)
13
+ # - Searches all route places by keyword
14
+ # - Returns all origins/destinations matching the keyword
7
15
  #
8
16
  # Query Parameters:
9
- # - query: [String] Required. Keyword to search in place names (case-insensitive)
10
17
  # - place_type: [String] Required. Type of route place: 'origin' or 'destination'
18
+ # * 'origin': returns origins that have routes TO the specified place (if place_id provided)
19
+ # * 'destination': returns destinations that have routes FROM the specified place (if place_id provided)
20
+ # - place_id: [Integer] Optional. The place ID to find connected places for
21
+ # - query: [String] Optional. Keyword to filter place names (case-insensitive)
11
22
  # - include: Optional comma-separated list (e.g., 'vendors,nearby_places')
12
23
  #
13
24
  # Response: Collection of places serialized with PlaceSerializer
14
25
  #
15
26
  # Behavior:
16
- # - Returns empty collection if query is blank or place_type is invalid
17
- # - UI should only call this endpoint when user has input a search term
18
- # - For initial/empty state, use GET /api/v2/storefront/popular_route_places instead
27
+ # - Returns empty collection if place_type is invalid
28
+ # - If place_id provided: returns places connected to that place
29
+ # - If place_id blank: returns all origins/destinations
30
+ # - Filters results by keyword if provided
31
+ #
32
+ # @example Mode 1: Find destinations connected to origin place ID 123
33
+ # GET /api/v2/storefront/route_places?place_id=123&place_type=destination
34
+ #
35
+ # @example Mode 2: Search all destination places by keyword
36
+ # GET /api/v2/storefront/route_places?place_type=destination&query=Phnom
19
37
  #
20
- # @example
21
- # GET /api/v2/storefront/route_places?query=Phnom&place_type=origin
38
+ # @example Combined: Find origins connected to place 456, filtered by keyword
39
+ # GET /api/v2/storefront/route_places?place_id=456&place_type=origin&query=Siem
22
40
  module Spree
23
41
  module Api
24
42
  module V2
@@ -28,7 +46,11 @@ module Spree
28
46
 
29
47
  # override
30
48
  def collection
31
- @collection ||= collection_finder.new(keyword: params[:query], place_type: params[:place_type]).execute
49
+ @collection ||= collection_finder.new(
50
+ place_type: params[:place_type],
51
+ place_id: params[:place_id],
52
+ keyword: params[:query]
53
+ ).execute
32
54
  end
33
55
 
34
56
  # override
@@ -1,42 +1,49 @@
1
- # Finds places that are used in routes (as origin or destination) by keyword search.
1
+ # Finds places connected via routes with optional filtering.
2
2
  #
3
- # @param keyword [String] Search term to match against place names (case-insensitive)
4
- # @param place_type [String] Type of route place: 'origin' or 'destination'
3
+ # @param place_type [String] Required. 'origin' or 'destination'
4
+ # @param place_id [Integer] Optional. Filter by connected place ID
5
+ # @param keyword [String] Optional. Filter by place name (case-insensitive)
5
6
  #
6
- # @return [ActiveRecord::Relation<SpreeCmCommissioner::Place>] Places matching the keyword
7
- # that are used as origins or destinations in existing routes. Returns empty relation if
8
- # keyword is blank or place_type is invalid.
7
+ # @return [ActiveRecord::Relation<SpreeCmCommissioner::Place>]
9
8
  #
10
- # @note For default/empty state display, use SpreeCmCommissioner::Routes::FindPopular instead
11
- # to show popular routes to users before they enter a search term.
9
+ # Modes:
10
+ # - place_id only: returns connected places (origins TO or destinations FROM given place)
11
+ # - keyword only: filters by name
12
+ # - both: connected places filtered by name
13
+ # - neither: all origins/destinations in routes
12
14
  #
13
- # @example
14
- # finder = SpreeCmCommissioner::Places::FindWithRoute.new(keyword: 'Phnom', place_type: 'origin')
15
- # finder.execute # => Returns places with "Phnom" in name that are used as route origins
15
+ # @example Origins with routes to place 123
16
+ # FindWithRoute.new(place_type: 'origin', place_id: 123).execute
17
+ #
18
+ # @example Destinations filtered by keyword
19
+ # FindWithRoute.new(place_type: 'destination', keyword: 'Phnom').execute
16
20
  module SpreeCmCommissioner
17
21
  module Places
18
22
  class FindWithRoute
19
- attr_reader :keyword, :place_type
23
+ attr_reader :place_type, :place_id, :keyword
20
24
 
21
- def initialize(keyword:, place_type:)
22
- @keyword = keyword
25
+ def initialize(place_type:, place_id: nil, keyword: nil)
23
26
  @place_type = place_type
27
+ @place_id = place_id
28
+ @keyword = keyword
24
29
  end
25
30
 
26
31
  def execute
27
- return SpreeCmCommissioner::Place.none if keyword.blank? || place_type.blank?
32
+ return SpreeCmCommissioner::Place.none if place_type.blank?
28
33
 
29
- scope.where('cm_places.name ILIKE ?', "%#{keyword}%")
30
- end
34
+ result = if place_type == 'origin'
35
+ scope = SpreeCmCommissioner::Place.with_routes_as_origin
36
+ place_id.present? ? scope.where(cm_routes: { destination_place_id: place_id }) : scope
37
+ else
38
+ scope = SpreeCmCommissioner::Place.with_routes_as_destination
39
+ place_id.present? ? scope.where(cm_routes: { origin_place_id: place_id }) : scope
40
+ end
31
41
 
32
- private
42
+ return SpreeCmCommissioner::Place.none if place_id.present? && !SpreeCmCommissioner::Place.exists?(place_id)
33
43
 
34
- def scope
35
- if place_type == 'origin'
36
- SpreeCmCommissioner::Place.with_routes_as_origin
37
- else
38
- SpreeCmCommissioner::Place.with_routes_as_destination
39
- end
44
+ # Apply keyword filter if provided
45
+ result = result.where('cm_places.name ILIKE ?', "%#{keyword}%") if keyword.present?
46
+ result
40
47
  end
41
48
  end
42
49
  end
@@ -2,7 +2,8 @@ module SpreeCmCommissioner
2
2
  class RoutePlacesRequestSchema < ApplicationRequestSchema
3
3
  params do
4
4
  required(:place_type).filled(:string)
5
- required(:query).filled(:string)
5
+ optional(:query).maybe(:string)
6
+ optional(:place_id).maybe(:integer)
6
7
  end
7
8
 
8
9
  rule(:place_type) do
@@ -1,5 +1,5 @@
1
1
  module SpreeCmCommissioner
2
- VERSION = '2.4.0'.freeze
2
+ VERSION = '2.4.1'.freeze
3
3
 
4
4
  module_function
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_cm_commissioner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - You