mirror of
https://gitlab.com/wheres-the-tp/server.git
synced 2026-01-25 04:24:56 -06:00
use the first images as a thumbnail
This commit is contained in:
parent
8da28e8406
commit
95b9c77734
5 changed files with 26 additions and 19 deletions
|
|
@ -11,7 +11,6 @@ CREATE TABLE food_items (
|
|||
place_id VARCHAR(50),
|
||||
category CATEGORY,
|
||||
images VARCHAR,
|
||||
thumbImage VARCHAR,
|
||||
loc geography(POINT,4326)
|
||||
);
|
||||
DROP TABLE IF EXISTS images CASCADE;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
(ns aretherecookies.app
|
||||
(:gen-class)
|
||||
(:require [aretherecookies.handler :refer [food-items-handler quantity-handler add-food-item-handler add-image-handler]]
|
||||
(:require [aretherecookies.handler :refer [food-items-handler
|
||||
quantity-handler
|
||||
add-food-item-handler
|
||||
add-image-handler
|
||||
get-images-handler]]
|
||||
[aretherecookies.auth :refer [auth-backend]]
|
||||
[environ.core :refer [env]]
|
||||
[compojure.handler :refer [api]]
|
||||
|
|
@ -19,7 +23,8 @@
|
|||
(POST "/fooditems" [] food-items-handler)
|
||||
(POST "/quantity" [] quantity-handler)
|
||||
(POST "/addfooditem" [] add-food-item-handler)
|
||||
(POST "/addimage/:foodItemId" [] add-image-handler))
|
||||
(POST "/images/:foodItemId" [] add-image-handler)
|
||||
(GET "/images/:foodItemId" [] get-images-handler))
|
||||
|
||||
(def app-config (assoc-in api-defaults [:security :anti-forgery] false))
|
||||
|
||||
|
|
|
|||
|
|
@ -14,4 +14,4 @@
|
|||
(defn build-s3-url
|
||||
"given an image name return fully qualified URL"
|
||||
[filename]
|
||||
(str "https://s3-us-west-2.amazonaws.com/aretherecookies/" filename))
|
||||
(if filename (str "https://s3-us-west-2.amazonaws.com/aretherecookies/" filename)))
|
||||
|
|
|
|||
|
|
@ -27,18 +27,16 @@
|
|||
{:status 400 :body (safe-json body)})
|
||||
|
||||
|
||||
(defn image-filename-to-url
|
||||
"convert image filename key to url key"
|
||||
[image]
|
||||
(assoc image :url (build-s3-url (get image :filename))))
|
||||
;(defn image-filename-to-url
|
||||
; "convert image filename key to url key"
|
||||
; [image]
|
||||
; (assoc image :url (build-s3-url (get image :filename))))
|
||||
|
||||
|
||||
(defn images-to-s3-urls
|
||||
(defn thumbimage-s3-url
|
||||
"convert all the images of a food item to fully qualified s3 URLs"
|
||||
[food-item]
|
||||
(if (get :images food-item)
|
||||
(update food-item :images (map build-s3-url))
|
||||
food-item))
|
||||
(update food-item :thumbimage build-s3-url))
|
||||
|
||||
|
||||
(defn food-items-handler
|
||||
|
|
@ -52,7 +50,7 @@
|
|||
:fooditems (->>
|
||||
(query-food-items body)
|
||||
(map parse-location)
|
||||
(map images-to-s3-urls))))))
|
||||
(map thumbimage-s3-url))))))
|
||||
|
||||
|
||||
(defn quantity-handler
|
||||
|
|
@ -88,6 +86,13 @@
|
|||
(safe-json %)))))
|
||||
|
||||
|
||||
(defn get-images-handler
|
||||
"return all images for a given foodItemId"
|
||||
[req]
|
||||
(let [foodItemId (get-in req [:params :foodItemId])]
|
||||
(get-images foodItemId)))
|
||||
|
||||
|
||||
(defn add-image-handler
|
||||
"given foodItemId from route and photo from multipart form post uploads image into s3 and adds URL into food item record"
|
||||
[req]
|
||||
|
|
|
|||
|
|
@ -2,14 +2,13 @@
|
|||
SELECT
|
||||
f.id AS id,
|
||||
f.name AS name,
|
||||
f.place_id AS place_id,
|
||||
f.place_id AS placeid,
|
||||
f.category AS category,
|
||||
f.thumbImage AS thumbImage,
|
||||
ST_AsGeoJSON(f.loc) AS location,
|
||||
ST_Distance(f.loc, ST_SetSRID(ST_Point(:lng, :lat), 4326)::geography) / 1609 AS distance,
|
||||
q.quantity AS quantity,
|
||||
q.date AS lastUpdated,
|
||||
(select filename from images where food_item_id = f.id) as images
|
||||
q.date AS lastupdated,
|
||||
(select filename from images i where f.id = i.food_item_id order by date asc limit 1) as thumbimage
|
||||
FROM food_items f
|
||||
LEFT OUTER JOIN latest_quantities q
|
||||
ON f.id = q.food_item_id
|
||||
|
|
@ -57,9 +56,8 @@ INSERT INTO food_items (id, name, place_id, category, loc)
|
|||
RETURNING
|
||||
id AS id,
|
||||
name AS name,
|
||||
place_id AS place_id,
|
||||
place_id AS placeid,
|
||||
category AS category,
|
||||
thumbImage AS thumbImage,
|
||||
ST_AsGeoJSON(loc) AS location,
|
||||
ST_Distance(loc, ST_SetSRID(ST_Point(:longitude, :latitude), 4326)::geography) / 1609 AS distance
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue