add playlist deletion from web ui

This commit is contained in:
sentriz
2020-08-16 01:00:13 +01:00
parent 6c46057f85
commit d02c65cb09
3 changed files with 22 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"mime/multipart"
"net/http"
"strconv"
"strings"
"github.com/jinzhu/gorm"
@@ -117,3 +118,20 @@ func (c *Controller) ServeUploadPlaylistDo(r *http.Request) *Response {
flashW: errors,
}
}
func (c *Controller) ServeDeletePlaylistDo(r *http.Request) *Response {
user := r.Context().Value(CtxUser).(*db.User)
id, err := strconv.Atoi(r.URL.Query().Get("id"))
if err != nil {
return &Response{
err: "please provide a valid id",
code: 400,
}
}
c.DB.
Where("user_id=? AND id=?", user.ID, id).
Delete(db.Playlist{})
return &Response{
redirect: "/admin/home",
}
}