diff --git a/src/yohoho/core.clj b/src/yohoho/core.clj index 8e573bd..1b50c89 100644 --- a/src/yohoho/core.clj +++ b/src/yohoho/core.clj @@ -64,6 +64,14 @@ {:status 200 :body "Ahoy mate, the ship be sailin' alright"}) +(defn get-item-handler + [request] + (let [id (get-in request [:path-params :id]) + item (db-get-item id)] + (cond + (nil? item) {:status 404 :body {:error "Not Found"}} + :else {:status 200 :body item}))) + (defn get-items-handler [_] {:status 200 @@ -100,10 +108,11 @@ (def app (ring/ring-handler (ring/router - [["/ahoy" {:get ahoy-handler}] - ["/items" {:get get-items-handler - :post {:handler create-item-handler - :parameters {:body Item}}}]] + [["/ahoy" {:get ahoy-handler}] + ["/item/:id" {:get get-item-handler}] + ["/items" {:get get-items-handler + :post {:handler create-item-handler + :parameters {:body Item}}}]] ;; Middlewares: ;; - wrap-content-type-json: ensure POST routes are sent JSON payload ;; - muuntaja middleware to automatically decode JSON