bugfixes with get/set images

This commit is contained in:
Bart Akeley 2018-04-08 10:57:15 -05:00
parent 95b9c77734
commit c5abfd1203
4 changed files with 106 additions and 82 deletions

View file

@ -32,68 +32,68 @@ DROP VIEW IF EXISTS latest_quantities;
CREATE VIEW latest_quantities AS SELECT food_item_id, quantity, date from quantities q1 where date = (
SELECT max(date) FROM quantities q2 WHERE q1.food_item_id=q2.food_item_id
);
INSERT INTO food_items (id, name, place_id, category, loc)
VALUES (
uuid_generate_v4(),
'Big John Cookies',
'ChIJf5QJFBK1RIYRjjfxZz9Z0O0',
'desserts',
ST_GeogFromText('SRID=4326;POINT(-97.7532464 30.270667599999996)')
);
INSERT INTO food_items (id, name, place_id, category, loc)
VALUES (
uuid_generate_v4(),
'Jelly Filled Donuts',
'ChIJ72if-Qe1RIYRCzMucGEEdBA',
'desserts',
ST_GeogFromText('SRID=4326;POINT(-97.742308 30.263963300000004)')
);
INSERT INTO food_items (id, name, place_id, category, loc)
VALUES (
uuid_generate_v4(),
'Spelt Brownies',
'ChIJG44vBQi1RIYRvWGHdYUolZY',
'desserts',
ST_GeogFromText('SRID=4326;POINT(-97.7419085 30.265019100000004)')
);
INSERT INTO food_items (id, name, place_id, category, loc)
VALUES (
uuid_generate_v4(),
'Oatmeal Raisin Cookies',
'ChIJf5QJFBK1RIYRjjfxZz9Z0O0',
'desserts',
ST_GeogFromText('SRID=4326;POINT(-97.7532464 30.270667599999996)')
);
INSERT INTO food_items (id, name, place_id, category, loc)
VALUES (
uuid_generate_v4(),
'Donuts with Sprinkles',
'ChIJ72if-Qe1RIYRCzMucGEEdBA',
'desserts',
ST_GeogFromText('SRID=4326;POINT(-97.742308 30.263963300000004)')
);
INSERT INTO food_items (id, name, place_id, category, loc)
VALUES (
uuid_generate_v4(),
'Powdered Donuts',
'ChIJ72if-Qe1RIYRCzMucGEEdBA',
'desserts',
ST_GeogFromText('SRID=4326;POINT(-97.742308 30.263963300000004)')
);
INSERT INTO food_items (id, name, place_id, category, loc)
VALUES (
uuid_generate_v4(),
'Snickerdoodles',
'ChIJr3szW6a1RIYRkM7LRpnBIO0',
'desserts',
ST_GeogFromText('SRID=4326;POINT(-97.73798459999999 30.266898599999998)')
);
INSERT INTO food_items (id, name, place_id, category, loc)
VALUES (
uuid_generate_v4(),
'Pizza',
'ChIJr3szW6a1RIYRkM7LRpnBIO0',
'desserts',
ST_GeogFromText('SRID=4326;POINT(-97.73798459999999 30.266898599999998)')
);
INSERT INTO quantities SELECT id, current_timestamp, 'many' FROM food_items;
--INSERT INTO food_items (id, name, place_id, category, loc)
-- VALUES (
-- uuid_generate_v4(),
-- 'Big John Cookies',
-- 'ChIJf5QJFBK1RIYRjjfxZz9Z0O0',
-- 'desserts',
-- ST_GeogFromText('SRID=4326;POINT(-97.7532464 30.270667599999996)')
-- );
--INSERT INTO food_items (id, name, place_id, category, loc)
-- VALUES (
-- uuid_generate_v4(),
-- 'Jelly Filled Donuts',
-- 'ChIJ72if-Qe1RIYRCzMucGEEdBA',
-- 'desserts',
-- ST_GeogFromText('SRID=4326;POINT(-97.742308 30.263963300000004)')
-- );
--INSERT INTO food_items (id, name, place_id, category, loc)
-- VALUES (
-- uuid_generate_v4(),
-- 'Spelt Brownies',
-- 'ChIJG44vBQi1RIYRvWGHdYUolZY',
-- 'desserts',
-- ST_GeogFromText('SRID=4326;POINT(-97.7419085 30.265019100000004)')
-- );
--INSERT INTO food_items (id, name, place_id, category, loc)
-- VALUES (
-- uuid_generate_v4(),
-- 'Oatmeal Raisin Cookies',
-- 'ChIJf5QJFBK1RIYRjjfxZz9Z0O0',
-- 'desserts',
-- ST_GeogFromText('SRID=4326;POINT(-97.7532464 30.270667599999996)')
-- );
--INSERT INTO food_items (id, name, place_id, category, loc)
-- VALUES (
-- uuid_generate_v4(),
-- 'Donuts with Sprinkles',
-- 'ChIJ72if-Qe1RIYRCzMucGEEdBA',
-- 'desserts',
-- ST_GeogFromText('SRID=4326;POINT(-97.742308 30.263963300000004)')
-- );
--INSERT INTO food_items (id, name, place_id, category, loc)
-- VALUES (
-- uuid_generate_v4(),
-- 'Powdered Donuts',
-- 'ChIJ72if-Qe1RIYRCzMucGEEdBA',
-- 'desserts',
-- ST_GeogFromText('SRID=4326;POINT(-97.742308 30.263963300000004)')
-- );
--INSERT INTO food_items (id, name, place_id, category, loc)
-- VALUES (
-- uuid_generate_v4(),
-- 'Snickerdoodles',
-- 'ChIJr3szW6a1RIYRkM7LRpnBIO0',
-- 'desserts',
-- ST_GeogFromText('SRID=4326;POINT(-97.73798459999999 30.266898599999998)')
-- );
--INSERT INTO food_items (id, name, place_id, category, loc)
-- VALUES (
-- uuid_generate_v4(),
-- 'Pizza',
-- 'ChIJr3szW6a1RIYRkM7LRpnBIO0',
-- 'desserts',
-- ST_GeogFromText('SRID=4326;POINT(-97.73798459999999 30.266898599999998)')
-- );
--INSERT INTO quantities SELECT id, current_timestamp, 'many' FROM food_items;

View file

@ -84,7 +84,7 @@
(defn get-images
"query database for a list of images for a food item id"
[foodItemId]
(select-images @pooled-db {:id foodItemId}))
(select-images @pooled-db {:foodItemId foodItemId}))
(defn add-image
"update the list of images for given food item id"

View file

@ -27,16 +27,24 @@
{:status 400 :body (safe-json body)})
;(defn image-filename-to-url
(defn update-key-to-s3
"return a map with key updated to point to s3"
([key]
(fn [map]
(update map key build-s3-url)))
([key map]
(update map key build-s3-url)))
;(defn update-image-url-to-s3
; "convert image filename key to url key"
; [image]
; (assoc image :url (build-s3-url (get image :filename))))
(defn thumbimage-s3-url
"convert all the images of a food item to fully qualified s3 URLs"
[food-item]
(update food-item :thumbimage build-s3-url))
; (update image :url build-s3-url))
;
;
;(defn update-thumbimage-to-s3
; "convert all the images of a food item to fully qualified s3 URLs"
; [food-item]
; (update food-item :thumbimage build-s3-url))
(defn food-items-handler
@ -50,7 +58,7 @@
:fooditems (->>
(query-food-items body)
(map parse-location)
(map thumbimage-s3-url))))))
(map (update-key-to-s3 :thumbimage)))))))
(defn quantity-handler
@ -90,7 +98,10 @@
"return all images for a given foodItemId"
[req]
(let [foodItemId (get-in req [:params :foodItemId])]
(get-images foodItemId)))
(->>
(get-images foodItemId)
(map #(update % :url build-s3-url))
safe-json)))
(defn add-image-handler
@ -103,7 +114,10 @@
img-name (str foodItemId "/" (UUID/randomUUID) ".png")]
(println "/addimage ---->" img-name)
(put-s3 img-name image)
(->>
(add-image {:food_item_id foodItemId
:filename img-name
:username username})
(build-s3-url img-name)))
first
(update-key-to-s3 :url)
safe-json)))

View file

@ -62,7 +62,13 @@ RETURNING
ST_Distance(loc, ST_SetSRID(ST_Point(:longitude, :latitude), 4326)::geography) / 1609 AS distance
-- :name select-images
SELECT * FROM images WHERE food_item-id=:v:food_item_id:uuid
SELECT
filename as url,
date,
username,
food_item_id
FROM images
WHERE food_item_id=:v:foodItemId::uuid
-- :name insert-image
INSERT INTO images (filename, username, date, food_item_id)
@ -72,4 +78,8 @@ INSERT INTO images (filename, username, date, food_item_id)
current_timestamp,
:v:food_item_id::uuid
)
RETURNING *
RETURNING
filename as url,
date,
username,
food_item_id