Allow removing statuses
This commit is contained in:
parent
a5b7f045d6
commit
c0922e3fb9
4 changed files with 50 additions and 0 deletions
|
|
@ -75,6 +75,7 @@ func New(cfg *config.Config, sess *session.Session, data *storage.Storage) (http
|
|||
router.HandleFunc("/statuses/save", h.saveStatus).Methods(http.MethodPost)
|
||||
router.HandleFunc("/statuses/{id}/edit", h.showEditStatusView).Methods(http.MethodGet)
|
||||
router.HandleFunc("/statuses/{id}/update", h.updateStatus).Methods(http.MethodPost)
|
||||
router.HandleFunc("/statuses/{id}/remove", h.handleRemoveStatus)
|
||||
|
||||
return router, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,13 @@
|
|||
package handler
|
||||
|
||||
var TplMap = map[string]string{
|
||||
"confirm_remove_status": `{{ define "content" }}
|
||||
Are you sure you you want to delete the following status?
|
||||
<p>{{ .status.Content }}</p>
|
||||
<form action="/statuses/{{ .status.Id }}/remove" method="post">
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
{{ end }}`,
|
||||
"create_status": `{{ define "content" }}
|
||||
<h1>New status</h1>
|
||||
{{ if .form.Error }}
|
||||
|
|
|
|||
7
web/handler/html/confirm_remove_status.html
Normal file
7
web/handler/html/confirm_remove_status.html
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{{ define "content" }}
|
||||
Are you sure you you want to delete the following status?
|
||||
<p>{{ .status.Content }}</p>
|
||||
<form action="/statuses/{{ .status.Id }}/remove" method="post">
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
{{ end }}
|
||||
35
web/handler/status_remove.go
Normal file
35
web/handler/status_remove.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (h *Handler) handleRemoveStatus(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := h.getUser(r)
|
||||
if err != nil {
|
||||
unauthorized(w)
|
||||
return
|
||||
}
|
||||
status, err := h.storage.StatusById(RouteInt64Param(r, "id"))
|
||||
if err != nil {
|
||||
serverError(w, err)
|
||||
return
|
||||
}
|
||||
if user != status.User {
|
||||
unauthorized(w)
|
||||
return
|
||||
}
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
h.renderLayout(w, "confirm_remove_status", map[string]interface{}{
|
||||
"status": status,
|
||||
}, user)
|
||||
case "POST":
|
||||
err = h.storage.DeleteStatus(status.Id, user)
|
||||
if err != nil {
|
||||
serverError(w, err)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue