aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2019-04-22 10:10:12 +0200
committerPřemysl Janouch <p@janouch.name>2019-04-22 10:14:28 +0200
commit04e66d7888f4567e004e4a6cf76765e8451c6a2d (patch)
tree19b7a35e5f999454c66ec533a12e1202937272ca
parent7d2ca09d1b0c4696cf04023a80dc8f3dfa33bbb9 (diff)
downloadsklad-04e66d7888f4567e004e4a6cf76765e8451c6a2d.tar.gz
sklad-04e66d7888f4567e004e4a6cf76765e8451c6a2d.tar.xz
sklad-04e66d7888f4567e004e4a6cf76765e8451c6a2d.zip
sklad: redirect to GET on successful DB changes
-rw-r--r--cmd/sklad/main.go20
1 files changed, 13 insertions, 7 deletions
diff --git a/cmd/sklad/main.go b/cmd/sklad/main.go
index 8a7e939..58aa8ef 100644
--- a/cmd/sklad/main.go
+++ b/cmd/sklad/main.go
@@ -115,12 +115,15 @@ func handleContainer(w http.ResponseWriter, r *http.Request) {
var err error
if r.Method == http.MethodPost {
- err = handleContainerPost(r)
- // FIXME: This is rather ugly. When removing, we want to keep
- // the context id, in addition to the id being changed.
- // TODO: If there were no errors, redirect the user to GET,
- // which is related to the previous comment.
- // TODO: If there were errors, use the last data as a prefill.
+ if err = handleContainerPost(r); err == nil {
+ redirect := "container"
+ if shownId != "" {
+ redirect += "?id=" + url.QueryEscape(shownId)
+ }
+ http.Redirect(w, r, redirect, http.StatusSeeOther)
+ return
+ }
+ // TODO: Use the last data as a prefill.
} else if r.Method != http.MethodGet {
w.WriteHeader(http.StatusMethodNotAllowed)
return
@@ -194,7 +197,10 @@ func handleSeriesPost(r *http.Request) error {
func handleSeries(w http.ResponseWriter, r *http.Request) {
var err error
if r.Method == http.MethodPost {
- err = handleSeriesPost(r)
+ if err = handleSeriesPost(r); err == nil {
+ http.Redirect(w, r, "series", http.StatusSeeOther)
+ return
+ }
// XXX: This is rather ugly.
r.Form = url.Values{}
} else if r.Method != http.MethodGet {