From 72daff0509a71a67b3fbec925ad37dab65e9625e Mon Sep 17 00:00:00 2001 From: jlangch Date: Tue, 26 Mar 2024 16:51:39 +0100 Subject: [PATCH] reafctoring REST example --- doc/examples/scripts/webapp/rest-webapp.venice | 10 +++++----- .../resources/com/github/jlangch/venice/tomcat.venice | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/examples/scripts/webapp/rest-webapp.venice b/doc/examples/scripts/webapp/rest-webapp.venice index 423928aac..abc0ffcc9 100644 --- a/doc/examples/scripts/webapp/rest-webapp.venice +++ b/doc/examples/scripts/webapp/rest-webapp.venice @@ -70,7 +70,7 @@ (defn create-employee [request] (let [json? (ring/json-request? request) body (if json? (json/slurp (:body request) :key-fn keyword) nil) - employee (if body {:name (:name body), :role (:role body)})] + employee (if body {:name (:name body), :role (:role body)} nil)] (cond (not json?) { :status 400 :headers { "Content-Type" "text/plain; charset=utf-8" } @@ -85,14 +85,14 @@ employee (find-employee-by-id id) json? (ring/json-request? request) body (if json? (json/slurp (:body request) :key-fn keyword) nil) - employee* (if body {:id id, :name (:name body), :role (:role body)})] + employee* (if body {:id id, :name (:name body), :role (:role body)} nil)] (cond - (nil? employee) { :status 404 - :headers { "Content-Type" "text/plain; charset=utf-8" } - :body "Employee with the id ~{id} not found!" } (not json?) { :status 400 :headers { "Content-Type" "text/plain; charset=utf-8" } :body "Not a json request!" } + (nil? employee) { :status 404 + :headers { "Content-Type" "text/plain; charset=utf-8" } + :body "Employee with the id ~{id} not found!" } :else { :status 200 :headers { "Content-Type" "application/json; charset=utf-8" } :body (json/write-str (add-employee employee*)) } ))) diff --git a/src/main/resources/com/github/jlangch/venice/tomcat.venice b/src/main/resources/com/github/jlangch/venice/tomcat.venice index 784017c23..9b1f1c4ba 100644 --- a/src/main/resources/com/github/jlangch/venice/tomcat.venice +++ b/src/main/resources/com/github/jlangch/venice/tomcat.venice @@ -451,7 +451,7 @@ (send-html res 404 (html-box-page "Not Found (404)" msg))) (defn send-internal-error [res msg] - (send-html res 500 (html-box-page "Internal Error (501)" msg))) + (send-html res 500 (html-box-page "Internal Error (500)" msg))) (defn send-not-implemented [res msg] (send-html res 501 (html-box-page "Not Implemented (501)" msg)))