subscription.go 886 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2017 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 api // import "miniflux.app/api"
  5. import (
  6. "fmt"
  7. "net/http"
  8. "miniflux.app/http/response/json"
  9. "miniflux.app/reader/subscription"
  10. )
  11. // GetSubscriptions is the API handler to find subscriptions.
  12. func (c *Controller) GetSubscriptions(w http.ResponseWriter, r *http.Request) {
  13. subscriptionInfo, err := decodeURLPayload(r.Body)
  14. if err != nil {
  15. json.BadRequest(w, err)
  16. return
  17. }
  18. subscriptions, err := subscription.FindSubscriptions(
  19. subscriptionInfo.URL,
  20. subscriptionInfo.Username,
  21. subscriptionInfo.Password,
  22. )
  23. if err != nil {
  24. json.ServerError(w, err)
  25. return
  26. }
  27. if subscriptions == nil {
  28. json.NotFound(w, fmt.Errorf("No subscription found"))
  29. return
  30. }
  31. json.OK(w, r, subscriptions)
  32. }