category_mark_as_read.go 854 B

123456789101112131415161718192021222324252627282930313233343536
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package ui // import "miniflux.app/v2/internal/ui"
  4. import (
  5. "net/http"
  6. "time"
  7. "miniflux.app/v2/internal/http/request"
  8. "miniflux.app/v2/internal/http/response/html"
  9. "miniflux.app/v2/internal/http/route"
  10. )
  11. func (h *handler) markCategoryAsRead(w http.ResponseWriter, r *http.Request) {
  12. userID := request.UserID(r)
  13. categoryID := request.RouteInt64Param(r, "categoryID")
  14. category, err := h.store.Category(userID, categoryID)
  15. if err != nil {
  16. html.ServerError(w, r, err)
  17. return
  18. }
  19. if category == nil {
  20. html.NotFound(w, r)
  21. return
  22. }
  23. if err = h.store.MarkCategoryAsRead(userID, categoryID, time.Now()); err != nil {
  24. html.ServerError(w, r, err)
  25. return
  26. }
  27. html.Redirect(w, r, route.Path(h.router, "categories"))
  28. }