Removed DeleteUnusedCategories(). Impl. NewCategory().
This commit is contained in:
parent
770273bd57
commit
714d4fdb73
@ -3,7 +3,6 @@ package http
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"image/jpeg"
|
"image/jpeg"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -250,10 +249,6 @@ func (h *MindflowApiHandlers) New(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := h.db.DeleteUnusedCategories(); err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
|
|
||||||
http.Redirect(w, r, "/mindflow/admin", http.StatusMovedPermanently)
|
http.Redirect(w, r, "/mindflow/admin", http.StatusMovedPermanently)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,10 +292,6 @@ func (h *MindflowApiHandlers) Edit(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := h.db.DeleteUnusedCategories(); err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MindflowApiHandlers) Delete(w http.ResponseWriter, r *http.Request) {
|
func (h *MindflowApiHandlers) Delete(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -309,8 +300,51 @@ func (h *MindflowApiHandlers) Delete(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := h.db.DeleteUnusedCategories(); err != nil {
|
func (h *MindflowApiHandlers) NewCategory(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var category *mindflow.Category
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") {
|
||||||
|
r.ParseForm()
|
||||||
|
|
||||||
|
category.ID, err = h.db.NewCategory(r.FormValue("name"))
|
||||||
|
if err != nil {
|
||||||
|
InternalError(err.Error(), "Title: "+r.FormValue("title")+" | Body: "+r.FormValue("body"), w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Redirect(w, r, "/mindflow/admin", http.StatusMovedPermanently)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *MindflowApiHandlers) EditCategory(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var category *mindflow.Category
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") {
|
||||||
|
r.ParseForm()
|
||||||
|
|
||||||
|
if r.FormValue("category") != "" {
|
||||||
|
category.ID, _ = strconv.ParseInt(r.FormValue("category"), 10, 64)
|
||||||
|
|
||||||
|
if category.ID == 0 {
|
||||||
|
category.ID, err = h.db.NewCategory(r.FormValue("new-category"))
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
http.Error(w, "wrong category id passed", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
category.Name = r.FormValue("name")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = h.db.EditCategory(category); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -322,11 +356,3 @@ func (h *MindflowApiHandlers) DeleteCategory(w http.ResponseWriter, r *http.Requ
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MindflowApiHandlers) DeleteUnusedCategories(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if err := h.db.DeleteUnusedCategories(); err != nil {
|
|
||||||
log.Println("Cannot delete unused categories:", err)
|
|
||||||
http.Error(w, "Cannot delete unused categories: "+err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user