From e878dca3d74e1b8644d56e4f717b0a8e0362e888 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 17 Nov 2019 22:53:11 -0800 Subject: Add API parameter to filter entries by category --- api/entry.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'api/entry.go') diff --git a/api/entry.go b/api/entry.go index 3b948f6..f0a0f99 100644 --- a/api/entry.go +++ b/api/entry.go @@ -164,7 +164,7 @@ func (h *handler) getEntries(w http.ResponseWriter, r *http.Request) { func (h *handler) setEntryStatus(w http.ResponseWriter, r *http.Request) { entryIDs, status, err := decodeEntryStatusPayload(r.Body) if err != nil { - json.BadRequest(w , r, errors.New("Invalid JSON payload")) + json.BadRequest(w, r, errors.New("Invalid JSON payload")) return } @@ -193,25 +193,30 @@ func (h *handler) toggleBookmark(w http.ResponseWriter, r *http.Request) { func configureFilters(builder *storage.EntryQueryBuilder, r *http.Request) { beforeEntryID := request.QueryInt64Param(r, "before_entry_id", 0) - if beforeEntryID != 0 { + if beforeEntryID > 0 { builder.BeforeEntryID(beforeEntryID) } afterEntryID := request.QueryInt64Param(r, "after_entry_id", 0) - if afterEntryID != 0 { + if afterEntryID > 0 { builder.AfterEntryID(afterEntryID) } beforeTimestamp := request.QueryInt64Param(r, "before", 0) - if beforeTimestamp != 0 { + if beforeTimestamp > 0 { builder.BeforeDate(time.Unix(beforeTimestamp, 0)) } afterTimestamp := request.QueryInt64Param(r, "after", 0) - if afterTimestamp != 0 { + if afterTimestamp > 0 { builder.AfterDate(time.Unix(afterTimestamp, 0)) } + categoryID := request.QueryInt64Param(r, "category_id", 0) + if categoryID > 0 { + builder.WithCategoryID(categoryID) + } + if request.HasQueryParam(r, "starred") { builder.WithStarred() } -- cgit v1.2.3