diff options
author | Emile <hanemile@protonmail.com> | 2019-10-20 12:24:39 +0200 |
---|---|---|
committer | Emile <hanemile@protonmail.com> | 2019-10-20 12:24:39 +0200 |
commit | f28288dd3208aa99381c22c6bb9713a6e7714b5e (patch) | |
tree | 53e51d88edd51dc61ef109bda7c573c8ff20207b | |
parent | befddbcbcabe60a04db59d1f64f962c85ec7f2dc (diff) |
fixed the edit function + error handling
-rw-r--r-- | hosted/edit_uuid.html | 2 | ||||
-rw-r--r-- | src/db.go | 5 | ||||
-rw-r--r-- | src/http.go | 8 |
3 files changed, 12 insertions, 3 deletions
diff --git a/hosted/edit_uuid.html b/hosted/edit_uuid.html index f42f3ea..aedf033 100644 --- a/hosted/edit_uuid.html +++ b/hosted/edit_uuid.html @@ -99,7 +99,7 @@ <div class="form-group row"> <div class="col-sm-12"> <button type="submit" class="btn btn-primary btn-lg btn-block"> - <a href="/editSelect" style="color:inherit"> Save changes </a> + Save changes </button> </div> </div> diff --git a/src/db.go b/src/db.go index 0c2e04b..e9b127c 100644 --- a/src/db.go +++ b/src/db.go @@ -100,7 +100,10 @@ func dbNewChallenge(challenge Challenge) (string, error) { func dbEditChallengeUUID(uuid string, updatedChallenge Challenge) error { query := fmt.Sprintf("UPDATE challenges SET name = '%s', description = '%s', flag = '%s', container = '%s', category = '%s', points = %d, static = %t WHERE uuid::text = '%s'", updatedChallenge.Name, updatedChallenge.Description, updatedChallenge.Flag, updatedChallenge.Container, updatedChallenge.Category, updatedChallenge.Points, updatedChallenge.Static, updatedChallenge.UUID) - _, _ = db.Exec(query) + _, err := db.Exec(query) + if err != nil { + return err + } return nil } diff --git a/src/http.go b/src/http.go index 443b6a3..e7e874d 100644 --- a/src/http.go +++ b/src/http.go @@ -150,6 +150,7 @@ func editGetHandler(w http.ResponseWriter, r *http.Request) { if r.URL.Query()["uuid"] == nil { log.Println("editnoparam") + http.Redirect(w, r, "/editSelect", http.StatusSeeOther) return } uuid = r.URL.Query()["uuid"][0] @@ -214,7 +215,12 @@ func editPostHandler(w http.ResponseWriter, r *http.Request) { } // update the challenge in the database - dbEditChallengeUUID(r.Form.Get("challengeUUID"), editedChallenge) + EditError := dbEditChallengeUUID(r.Form.Get("challengeUUID"), editedChallenge) + if EditError != nil { + log.Println("Could not edit:") + log.Println(EditError) + } + log.Println("done editing challenge!") http.Redirect(w, r, "/edit", http.StatusSeeOther) |