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 +4 -4
- data/Gemfile.lock +1 -1
- data/app/controllers/spree/api/v2/storefront/route_places_controller.rb +32 -10
- data/app/finders/spree_cm_commissioner/places/find_with_route.rb +31 -24
- data/app/request_schemas/spree_cm_commissioner/route_places_request_schema.rb +2 -1
- data/lib/spree_cm_commissioner/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4e32e4116a234b679abcfe3a9d7005bd61890d80936839c32330ecf2b421dadf
|
|
4
|
+
data.tar.gz: a7759f377e09d49281150257a496e44af61e4cabb67a8bec0bacb20a73ea439d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5119cedb570e77e3417bf723ea84926231e4d72000686312a194c1cfb4764061b5df9801923a5db629d8b8adccfd8a70378a238a0c099af46abe8f5c6a2da1d0
|
|
7
|
+
data.tar.gz: adeee4909603c0294be64345ea3de5b310e2dcaa174669137794b56dd23b800ddd9a1f429da636df23953d80154a3b96835cb19a81274fc0908edaae1ebd13d9
|
data/Gemfile.lock
CHANGED
|
@@ -1,24 +1,42 @@
|
|
|
1
|
-
# API endpoint for searching places
|
|
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
|
-
#
|
|
6
|
-
#
|
|
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
|
|
17
|
-
# -
|
|
18
|
-
# -
|
|
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?
|
|
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(
|
|
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
|
|
1
|
+
# Finds places connected via routes with optional filtering.
|
|
2
2
|
#
|
|
3
|
-
# @param
|
|
4
|
-
# @param
|
|
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>]
|
|
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
|
-
#
|
|
11
|
-
#
|
|
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
|
-
#
|
|
15
|
-
#
|
|
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 :
|
|
23
|
+
attr_reader :place_type, :place_id, :keyword
|
|
20
24
|
|
|
21
|
-
def initialize(
|
|
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
|
|
32
|
+
return SpreeCmCommissioner::Place.none if place_type.blank?
|
|
28
33
|
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
42
|
+
return SpreeCmCommissioner::Place.none if place_id.present? && !SpreeCmCommissioner::Place.exists?(place_id)
|
|
33
43
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
5
|
+
optional(:query).maybe(:string)
|
|
6
|
+
optional(:place_id).maybe(:integer)
|
|
6
7
|
end
|
|
7
8
|
|
|
8
9
|
rule(:place_type) do
|