mirror of
https://gitlab.com/wheres-the-tp/server.git
synced 2026-01-25 04:24:56 -06:00
search term in filter for food items
This commit is contained in:
parent
e1e98a297a
commit
422aacbe34
4 changed files with 23 additions and 12 deletions
|
|
@ -1,5 +1,6 @@
|
|||
CREATE EXTENSION IF NOT EXISTS "postgis";
|
||||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
CREATE EXTENSION IF NOT EXISTS "fuzzystrmatch";
|
||||
DROP TYPE IF EXISTS QUANTITY CASCADE;
|
||||
CREATE TYPE QUANTITY AS ENUM ('lots', 'many', 'few', 'none');
|
||||
DROP TYPE IF EXISTS CATEGORY CASCADE;
|
||||
|
|
|
|||
|
|
@ -49,12 +49,16 @@
|
|||
(defn wrap-in-quotes [token]
|
||||
(str/replace token #"(^|$)" "'"))
|
||||
|
||||
(defn wildcard
|
||||
[term]
|
||||
(str "%" (str/join (interpose "%" term)) "%"))
|
||||
|
||||
(defn get-where [{:keys [:lat :lng :filter]}]
|
||||
(let [radius (or (:radius filter) 10)
|
||||
categories (:categories filter)]
|
||||
(cond
|
||||
categories (has-category {:categories (map wrap-in-quotes categories) :lat lat :lng lng :dist radius})
|
||||
:else (within-radius {:lat lat :lng lng :dist radius}))))
|
||||
(food-items-where-clause {:lat lat
|
||||
:lng lng
|
||||
:dist (:radius filter)
|
||||
:categories (map wrap-in-quotes (:categories filter))
|
||||
:search (wildcard (:search filter))}))
|
||||
|
||||
(defn query-food-items [{lat :lat lng :lng filter :filter}]
|
||||
(select-food-items
|
||||
|
|
@ -72,12 +76,12 @@
|
|||
|
||||
(defn create-food-item [{:keys [:name :placeId :category :quantity :latitude :longitude]}]
|
||||
(let [food-item (first (insert-food-item
|
||||
@pooled-db
|
||||
{:name name
|
||||
:placeId placeId
|
||||
:category category
|
||||
:longitude longitude
|
||||
:latitude latitude}))
|
||||
@pooled-db
|
||||
{:name name
|
||||
:placeId placeId
|
||||
:category category
|
||||
:longitude longitude
|
||||
:latitude latitude}))
|
||||
quantity (first (insert-quantity {:foodItemId (:id food-item) :quantity quantity}))]
|
||||
(merge food-item (select-keys quantity [:quantity :date]))))
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
(fn [map]
|
||||
(update map key build-s3-url)))
|
||||
([key map]
|
||||
(update map key build-s3-url)))
|
||||
(update map key build-s3-url)))
|
||||
|
||||
|
||||
(defn food-items-handler
|
||||
|
|
|
|||
|
|
@ -24,6 +24,12 @@ category IN (:i*:categories)
|
|||
-- :snip within-radius
|
||||
WHERE ST_DWithin(loc, ST_SetSRID(ST_Point(:lng, :lat), 4326)::geography, :dist * 1609)
|
||||
|
||||
-- :snip food-items-where-clause
|
||||
WHERE
|
||||
ST_DWithin(loc, ST_SetSRID(ST_Point(:lng, :lat), 4326)::geography, :dist * 1609)
|
||||
--~ (when (seq (:categories params)) "AND category IN (:i*:categories)")
|
||||
--~ (when (not-empty (:search params)) "AND name like :v:search")
|
||||
|
||||
-- :snip by-distance
|
||||
ORDER BY distance ASC
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue