Task D: Displaying Pictures

We now have all the pieces in place to start displaying the pictures in our gallery. We simply have to load all the thumbnails associated with the user and show them on the page. When clicked, a thumbnail will display the full-size picture.

Since we store references to uploaded images in the database, we can easily write a function to query all images with the given user ID in our db namespace.

picture-gallery-d/src/picture_gallery/models/db.clj
 
(​defn​ images-by-user [userid]
 
(with-db
 
sql/with-query-results
 
res [​"select * from images where userid = ?"​ userid] (​doall​ res)))

Let’s test that the function does what we intended by running it against a user we registered earlier and see if we get a list of ...

Get Web Development with Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.