category_remove.go 919 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package ui // import "miniflux.app/ui"
  5. import (
  6. "net/http"
  7. "miniflux.app/http/request"
  8. "miniflux.app/http/response/html"
  9. "miniflux.app/http/route"
  10. )
  11. func (h *handler) removeCategory(w http.ResponseWriter, r *http.Request) {
  12. user, err := h.store.UserByID(request.UserID(r))
  13. if err != nil {
  14. html.ServerError(w, r, err)
  15. return
  16. }
  17. categoryID := request.RouteInt64Param(r, "categoryID")
  18. category, err := h.store.Category(request.UserID(r), categoryID)
  19. if err != nil {
  20. html.ServerError(w, r, err)
  21. return
  22. }
  23. if category == nil {
  24. html.NotFound(w, r)
  25. return
  26. }
  27. if err := h.store.RemoveCategory(user.ID, category.ID); err != nil {
  28. html.ServerError(w, r, err)
  29. return
  30. }
  31. html.Redirect(w, r, route.Path(h.router, "categories"))
  32. }