fever item endpoint max_id parameter

This commit is contained in:
Nazar Kanaev 2020-11-01 15:27:20 +00:00
parent b0364087ad
commit 0226c8da23
2 changed files with 13 additions and 1 deletions

View File

@ -218,6 +218,13 @@ func FeverItemsHandler(rw http.ResponseWriter, req *http.Request) {
}
}
if _, ok := query["max_id"]; ok {
idstr := query.Get("max_id")
if idnum, err := strconv.ParseInt(idstr, 10, 64); err == nil {
filter.MaxID = &idnum
}
}
items := db(req).ListItems(filter, 0, 50, true)
feverItems := make([]FeverItem, len(items))

View File

@ -65,6 +65,7 @@ type ItemFilter struct {
IDs *[]int64
SinceID *int64
MaxID *int64
}
type MarkFilter struct {
@ -164,6 +165,10 @@ func listQueryPredicate(filter ItemFilter) (string, []interface{}) {
cond = append(cond, "i.id > ?")
args = append(args, filter.SinceID)
}
if filter.MaxID != nil {
cond = append(cond, "i.id < ?")
args = append(args, filter.MaxID)
}
predicate := "1"
if len(cond) > 0 {
@ -182,7 +187,7 @@ func (s *Storage) ListItems(filter ItemFilter, offset, limit int, newestFirst bo
order = "date asc"
}
if filter.IDs != nil || filter.SinceID != nil {
if filter.IDs != nil || filter.SinceID != nil || filter.MaxID != nil {
order = "i.id asc"
}