category_entries.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. "miniflux.app/model"
  11. "miniflux.app/ui/session"
  12. "miniflux.app/ui/view"
  13. )
  14. // CategoryEntries shows all entries for the given category.
  15. func (c *Controller) CategoryEntries(w http.ResponseWriter, r *http.Request) {
  16. user, err := c.store.UserByID(request.UserID(r))
  17. if err != nil {
  18. html.ServerError(w, r, err)
  19. return
  20. }
  21. categoryID := request.RouteInt64Param(r, "categoryID")
  22. category, err := c.store.Category(request.UserID(r), categoryID)
  23. if err != nil {
  24. html.ServerError(w, r, err)
  25. return
  26. }
  27. if category == nil {
  28. html.NotFound(w, r)
  29. return
  30. }
  31. offset := request.QueryIntParam(r, "offset", 0)
  32. builder := c.store.NewEntryQueryBuilder(user.ID)
  33. builder.WithCategoryID(category.ID)
  34. builder.WithOrder(model.DefaultSortingOrder)
  35. builder.WithDirection(user.EntryDirection)
  36. builder.WithoutStatus(model.EntryStatusRemoved)
  37. builder.WithOffset(offset)
  38. builder.WithLimit(nbItemsPerPage)
  39. entries, err := builder.GetEntries()
  40. if err != nil {
  41. html.ServerError(w, r, err)
  42. return
  43. }
  44. count, err := builder.CountEntries()
  45. if err != nil {
  46. html.ServerError(w, r, err)
  47. return
  48. }
  49. sess := session.New(c.store, request.SessionID(r))
  50. view := view.New(c.tpl, r, sess)
  51. view.Set("category", category)
  52. view.Set("total", count)
  53. view.Set("entries", entries)
  54. view.Set("pagination", c.getPagination(route.Path(c.router, "categoryEntries", "categoryID", category.ID), count, offset))
  55. view.Set("menu", "categories")
  56. view.Set("user", user)
  57. view.Set("countUnread", c.store.CountUnreadEntries(user.ID))
  58. view.Set("countErrorFeeds", c.store.CountErrorFeeds(user.ID))
  59. view.Set("hasSaveEntry", c.store.HasSaveEntry(user.ID))
  60. html.OK(w, r, view.Render("category_entries"))
  61. }