From 7b91a667a10ca69c170d48afdbd4e23ab5ac1b3f Mon Sep 17 00:00:00 2001 From: James Hillyerd Date: Fri, 11 Oct 2013 17:16:23 -0700 Subject: [PATCH] Reorganize URI routes to be more RESTful --- bin/mailbox-list.sh | 2 +- bin/message-delete.sh | 1 + bin/{mailbox-source.sh => message-source.sh} | 2 +- themes/integral/templates/mailbox/index.html | 12 ++++++------ web/mailbox_controller.go | 17 +++++++++++------ web/server.go | 10 +++++----- 6 files changed, 25 insertions(+), 19 deletions(-) create mode 100755 bin/message-delete.sh rename bin/{mailbox-source.sh => message-source.sh} (63%) diff --git a/bin/mailbox-list.sh b/bin/mailbox-list.sh index 384560f..da5ca4c 100755 --- a/bin/mailbox-list.sh +++ b/bin/mailbox-list.sh @@ -1 +1 @@ -curl -i -H "Accept: application/json" --noproxy localhost http://localhost:9000/mailbox/list/$1 +curl -i -H "Accept: application/json" --noproxy localhost http://localhost:9000/mailbox/$1 diff --git a/bin/message-delete.sh b/bin/message-delete.sh new file mode 100755 index 0000000..c3c8b86 --- /dev/null +++ b/bin/message-delete.sh @@ -0,0 +1 @@ +curl -i -H "Accept: application/json" --noproxy localhost -X DELETE http://localhost:9000/mailbox/$1/$2 diff --git a/bin/mailbox-source.sh b/bin/message-source.sh similarity index 63% rename from bin/mailbox-source.sh rename to bin/message-source.sh index cbff7e6..21714cc 100755 --- a/bin/mailbox-source.sh +++ b/bin/message-source.sh @@ -1 +1 @@ -curl -i -H "Accept: application/json" --noproxy localhost http://localhost:9000/mailbox/source/$1/$2 +curl -i -H "Accept: application/json" --noproxy localhost http://localhost:9000/mailbox/$1/$2/source diff --git a/themes/integral/templates/mailbox/index.html b/themes/integral/templates/mailbox/index.html index 66e078e..6581e18 100644 --- a/themes/integral/templates/mailbox/index.html +++ b/themes/integral/templates/mailbox/index.html @@ -15,14 +15,14 @@ function() { $('.listEntry').removeClass("listEntrySelected") $(this).addClass("listEntrySelected") - $('#emailContent').load('/mailbox/show/{{.name}}/' + this.id) + $('#emailContent').load('/mailbox/{{.name}}/' + this.id) } ) $("#messageList").slideDown() } function loadList() { - $('#messageList').load("/mailbox/list/{{.name}}", listLoaded) + $('#messageList').load("/mailbox/{{.name}}", listLoaded) } function reloadList() { @@ -38,20 +38,20 @@ function deleteMessage(id) { $('#emailContent').empty() $.ajax({ - type: 'POST', - url: '/mailbox/delete/{{.name}}/' + id, + type: 'DELETE', + url: '/mailbox/{{.name}}/' + id, success: reloadList }) } function htmlView(id) { - window.open('/mailbox/html/{{.name}}/' + id, '_blank', + window.open('/mailbox/{{.name}}/' + id + "/html", '_blank', 'width=800,height=600,' + 'menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes') } function messageSource(id) { - window.open('/mailbox/source/{{.name}}/' + id, '_blank', + window.open('/mailbox/{{.name}}/' + id + "/source", '_blank', 'width=800,height=600,' + 'menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no') } diff --git a/web/mailbox_controller.go b/web/mailbox_controller.go index ecff8ae..1d4711b 100644 --- a/web/mailbox_controller.go +++ b/web/mailbox_controller.go @@ -55,13 +55,13 @@ func MailboxList(w http.ResponseWriter, req *http.Request, ctx *Context) (err er } } return RenderJson(w, jmessages) - } else { - return RenderPartial("mailbox/_list.html", w, map[string]interface{}{ - "ctx": ctx, - "name": name, - "messages": messages, - }) } + + return RenderPartial("mailbox/_list.html", w, map[string]interface{}{ + "ctx": ctx, + "name": name, + "messages": messages, + }) } func MailboxShow(w http.ResponseWriter, req *http.Request, ctx *Context) (err error) { @@ -234,6 +234,11 @@ func MailboxDelete(w http.ResponseWriter, req *http.Request, ctx *Context) (err if err != nil { return err } + + if ctx.IsJson { + return RenderJson(w, "OK") + } + w.Header().Set("Content-Type", "text/plain") io.WriteString(w, "OK") return nil diff --git a/web/server.go b/web/server.go index 120a9cd..fcffdce 100644 --- a/web/server.go +++ b/web/server.go @@ -35,11 +35,11 @@ func setupRoutes(cfg config.WebConfig) { r.Path("/").Handler(handler(RootIndex)).Name("RootIndex").Methods("GET") r.Path("/status").Handler(handler(RootStatus)).Name("RootStatus").Methods("GET") r.Path("/mailbox").Handler(handler(MailboxIndex)).Name("MailboxIndex").Methods("GET") - r.Path("/mailbox/list/{name}").Handler(handler(MailboxList)).Name("MailboxList").Methods("GET") - r.Path("/mailbox/show/{name}/{id}").Handler(handler(MailboxShow)).Name("MailboxShow").Methods("GET") - r.Path("/mailbox/html/{name}/{id}").Handler(handler(MailboxHtml)).Name("MailboxHtml").Methods("GET") - r.Path("/mailbox/source/{name}/{id}").Handler(handler(MailboxSource)).Name("MailboxSource").Methods("GET") - r.Path("/mailbox/delete/{name}/{id}").Handler(handler(MailboxDelete)).Name("MailboxDelete").Methods("POST") + r.Path("/mailbox/{name}").Handler(handler(MailboxList)).Name("MailboxList").Methods("GET") + r.Path("/mailbox/{name}/{id}").Handler(handler(MailboxShow)).Name("MailboxShow").Methods("GET") + r.Path("/mailbox/{name}/{id}/html").Handler(handler(MailboxHtml)).Name("MailboxHtml").Methods("GET") + r.Path("/mailbox/{name}/{id}/source").Handler(handler(MailboxSource)).Name("MailboxSource").Methods("GET") + r.Path("/mailbox/{name}/{id}").Handler(handler(MailboxDelete)).Name("MailboxDelete").Methods("DELETE") r.Path("/mailbox/dattach/{name}/{id}/{num}/{file}").Handler(handler(MailboxDownloadAttach)).Name("MailboxDownloadAttach").Methods("GET") r.Path("/mailbox/vattach/{name}/{id}/{num}/{file}").Handler(handler(MailboxViewAttach)).Name("MailboxViewAttach").Methods("GET")