|
|
@@ -17,15 +17,8 @@ import (
|
|
|
"miniflux.app/validator"
|
|
|
)
|
|
|
|
|
|
-func (h *handler) getFeedEntry(w http.ResponseWriter, r *http.Request) {
|
|
|
- feedID := request.RouteInt64Param(r, "feedID")
|
|
|
- entryID := request.RouteInt64Param(r, "entryID")
|
|
|
-
|
|
|
- builder := h.store.NewEntryQueryBuilder(request.UserID(r))
|
|
|
- builder.WithFeedID(feedID)
|
|
|
- builder.WithEntryID(entryID)
|
|
|
-
|
|
|
- entry, err := builder.GetEntry()
|
|
|
+func getEntryFromBuilder(w http.ResponseWriter, r *http.Request, b *storage.EntryQueryBuilder) {
|
|
|
+ entry, err := b.GetEntry()
|
|
|
if err != nil {
|
|
|
json.ServerError(w, r, err)
|
|
|
return
|
|
|
@@ -39,35 +32,51 @@ func (h *handler) getFeedEntry(w http.ResponseWriter, r *http.Request) {
|
|
|
json.OK(w, r, entry)
|
|
|
}
|
|
|
|
|
|
-func (h *handler) getEntry(w http.ResponseWriter, r *http.Request) {
|
|
|
+func (h *handler) getFeedEntry(w http.ResponseWriter, r *http.Request) {
|
|
|
+ feedID := request.RouteInt64Param(r, "feedID")
|
|
|
entryID := request.RouteInt64Param(r, "entryID")
|
|
|
+
|
|
|
builder := h.store.NewEntryQueryBuilder(request.UserID(r))
|
|
|
+ builder.WithFeedID(feedID)
|
|
|
builder.WithEntryID(entryID)
|
|
|
|
|
|
- entry, err := builder.GetEntry()
|
|
|
- if err != nil {
|
|
|
- json.ServerError(w, r, err)
|
|
|
- return
|
|
|
- }
|
|
|
+ getEntryFromBuilder(w, r, builder)
|
|
|
+}
|
|
|
|
|
|
- if entry == nil {
|
|
|
- json.NotFound(w, r)
|
|
|
- return
|
|
|
- }
|
|
|
+func (h *handler) getCategoryEntry(w http.ResponseWriter, r *http.Request) {
|
|
|
+ categoryID := request.RouteInt64Param(r, "categoryID")
|
|
|
+ entryID := request.RouteInt64Param(r, "entryID")
|
|
|
|
|
|
- json.OK(w, r, entry)
|
|
|
+ builder := h.store.NewEntryQueryBuilder(request.UserID(r))
|
|
|
+ builder.WithCategoryID(categoryID)
|
|
|
+ builder.WithEntryID(entryID)
|
|
|
+
|
|
|
+ getEntryFromBuilder(w, r, builder)
|
|
|
+}
|
|
|
+
|
|
|
+func (h *handler) getEntry(w http.ResponseWriter, r *http.Request) {
|
|
|
+ entryID := request.RouteInt64Param(r, "entryID")
|
|
|
+ builder := h.store.NewEntryQueryBuilder(request.UserID(r))
|
|
|
+ builder.WithEntryID(entryID)
|
|
|
+
|
|
|
+ getEntryFromBuilder(w, r, builder)
|
|
|
}
|
|
|
|
|
|
func (h *handler) getFeedEntries(w http.ResponseWriter, r *http.Request) {
|
|
|
feedID := request.RouteInt64Param(r, "feedID")
|
|
|
- h.findEntries(w, r, feedID)
|
|
|
+ h.findEntries(w, r, feedID, 0)
|
|
|
+}
|
|
|
+
|
|
|
+func (h *handler) getCategoryEntries(w http.ResponseWriter, r *http.Request) {
|
|
|
+ categoryID := request.RouteInt64Param(r, "categoryID")
|
|
|
+ h.findEntries(w, r, 0, categoryID)
|
|
|
}
|
|
|
|
|
|
func (h *handler) getEntries(w http.ResponseWriter, r *http.Request) {
|
|
|
- h.findEntries(w, r, 0)
|
|
|
+ h.findEntries(w, r, 0, 0)
|
|
|
}
|
|
|
|
|
|
-func (h *handler) findEntries(w http.ResponseWriter, r *http.Request, feedID int64) {
|
|
|
+func (h *handler) findEntries(w http.ResponseWriter, r *http.Request, feedID int64, categoryID int64) {
|
|
|
statuses := request.QueryStringParamList(r, "status")
|
|
|
for _, status := range statuses {
|
|
|
if err := validator.ValidateEntryStatus(status); err != nil {
|
|
|
@@ -96,7 +105,7 @@ func (h *handler) findEntries(w http.ResponseWriter, r *http.Request, feedID int
|
|
|
}
|
|
|
|
|
|
userID := request.UserID(r)
|
|
|
- categoryID := request.QueryInt64Param(r, "category_id", 0)
|
|
|
+ categoryID = request.QueryInt64Param(r, "category_id", categoryID)
|
|
|
if categoryID > 0 && !h.store.CategoryIDExists(userID, categoryID) {
|
|
|
json.BadRequest(w, r, errors.New("Invalid category ID"))
|
|
|
return
|