mirror of
https://gitlab.com/wheres-the-tp/server.git
synced 2026-01-25 06:04:56 -06:00
update quantity during item creation
This commit is contained in:
parent
34f019dd01
commit
2cd680b46c
3 changed files with 17 additions and 9 deletions
|
|
@ -68,5 +68,13 @@
|
|||
(defn select-latest-quantity [{:keys [:foodItemId]}]
|
||||
(select-latest-quantity-query @pooled-db {:food_item_id (wrap-in-quotes foodItemId)}))
|
||||
|
||||
(defn create-food-item [{:keys [:name :placeId :category :latitude :longitude]}]
|
||||
(insert-food-item @pooled-db {:name name :placeId placeId :category category :longitude longitude :latitude latitude}))
|
||||
(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}))
|
||||
quantity (first (insert-quantity {:foodItemId (:id food-item) :quantity quantity}))]
|
||||
(merge food-item (select-keys quantity [:quantity :date]))))
|
||||
|
|
|
|||
|
|
@ -48,5 +48,5 @@
|
|||
(bad-request {"missingkeys" missing-keys})
|
||||
(as->
|
||||
(create-food-item food-item) %
|
||||
(map parse-location %)
|
||||
(parse-location %)
|
||||
(safe-json %)))))
|
||||
|
|
|
|||
|
|
@ -11,14 +11,14 @@
|
|||
:else value))
|
||||
|
||||
(defn get-coords [item]
|
||||
(->
|
||||
(:location item)
|
||||
json/read-str
|
||||
(get "coordinates")))
|
||||
(if-let [location (:location item)]
|
||||
(get (json/read-str location) "coordinates" [])
|
||||
[]))
|
||||
|
||||
(defn build-latlng [item]
|
||||
(let [[longitude latitude] (get-coords item)]
|
||||
(hash-map :longitude longitude :latitude latitude)))
|
||||
(if-let [[longitude latitude] (get-coords item)]
|
||||
(hash-map :longitude longitude :latitude latitude)
|
||||
{}))
|
||||
|
||||
(defn parse-location [food-item]
|
||||
(->
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue