diff --git a/fever/handler.go b/fever/handler.go index 0f9de921834b1080f0550b3e138e6c097b8272d3..f0638ef08e79d98e369e921340aed00c4d428ea4 100644 --- a/fever/handler.go +++ b/fever/handler.go @@ -246,27 +246,33 @@ func (h *handler) handleItems(w http.ResponseWriter, r *http.Request) { builder.WithOrder("id") builder.WithDirection(model.DefaultSortingDirection) - sinceID := request.QueryIntParam(r, "since_id", 0) - if sinceID > 0 { - builder.AfterEntryID(int64(sinceID)) - } - - maxID := request.QueryIntParam(r, "max_id", 0) - if maxID > 0 { - builder.WithOffset(maxID) - } - - csvItemIDs := request.QueryStringParam(r, "with_ids", "") - if csvItemIDs != "" { - var itemIDs []int64 - - for _, strItemID := range strings.Split(csvItemIDs, ",") { - strItemID = strings.TrimSpace(strItemID) - itemID, _ := strconv.Atoi(strItemID) - itemIDs = append(itemIDs, int64(itemID)) + switch { + case request.HasQueryParam(r, "since_id"): + sinceID := request.QueryInt64Param(r, "since_id", 0) + if sinceID > 0 { + builder.AfterEntryID(sinceID) + } + case request.HasQueryParam(r, "max_id"): + maxID := request.QueryInt64Param(r, "max_id", 0) + if maxID == 0 { + builder.WithDirection("desc") + } else if maxID > 0 { + builder.BeforeEntryID(maxID) + builder.WithDirection("desc") + } + case request.HasQueryParam(r, "with_ids"): + csvItemIDs := request.QueryStringParam(r, "with_ids", "") + if csvItemIDs != "" { + var itemIDs []int64 + + for _, strItemID := range strings.Split(csvItemIDs, ",") { + strItemID = strings.TrimSpace(strItemID) + itemID, _ := strconv.ParseInt(strItemID, 10, 64) + itemIDs = append(itemIDs, itemID) + } + + builder.WithEntryIDs(itemIDs) } - - builder.WithEntryIDs(itemIDs) } entries, err := builder.GetEntries()