Browse Source

Add changed_after and changed_before options to /v1/entries endpoint

Frédéric Guillot 2 years ago
parent
commit
fccc25f7a3
5 changed files with 88 additions and 44 deletions
  1. 20 4
      client/client.go
  2. 18 14
      client/model.go
  3. 24 14
      internal/api/entry.go
  4. 8 8
      internal/googlereader/handler.go
  5. 18 4
      internal/storage/entry_query_builder.go

+ 20 - 4
client/client.go

@@ -540,14 +540,30 @@ func buildFilterQueryString(path string, filter *Filter) string {
 			values.Set("after", strconv.FormatInt(filter.After, 10))
 		}
 
-		if filter.AfterEntryID > 0 {
-			values.Set("after_entry_id", strconv.FormatInt(filter.AfterEntryID, 10))
-		}
-
 		if filter.Before > 0 {
 			values.Set("before", strconv.FormatInt(filter.Before, 10))
 		}
 
+		if filter.PublishedAfter > 0 {
+			values.Set("published_after", strconv.FormatInt(filter.PublishedAfter, 10))
+		}
+
+		if filter.PublishedBefore > 0 {
+			values.Set("published_before", strconv.FormatInt(filter.PublishedBefore, 10))
+		}
+
+		if filter.ChangedAfter > 0 {
+			values.Set("changed_after", strconv.FormatInt(filter.ChangedAfter, 10))
+		}
+
+		if filter.ChangedBefore > 0 {
+			values.Set("changed_before", strconv.FormatInt(filter.ChangedBefore, 10))
+		}
+
+		if filter.AfterEntryID > 0 {
+			values.Set("after_entry_id", strconv.FormatInt(filter.AfterEntryID, 10))
+		}
+
 		if filter.BeforeEntryID > 0 {
 			values.Set("before_entry_id", strconv.FormatInt(filter.BeforeEntryID, 10))
 		}

+ 18 - 14
client/model.go

@@ -245,20 +245,24 @@ const (
 
 // Filter is used to filter entries.
 type Filter struct {
-	Status        string
-	Offset        int
-	Limit         int
-	Order         string
-	Direction     string
-	Starred       string
-	Before        int64
-	After         int64
-	BeforeEntryID int64
-	AfterEntryID  int64
-	Search        string
-	CategoryID    int64
-	FeedID        int64
-	Statuses      []string
+	Status          string
+	Offset          int
+	Limit           int
+	Order           string
+	Direction       string
+	Starred         string
+	Before          int64
+	After           int64
+	PublishedBefore int64
+	PublishedAfter  int64
+	ChangedBefore   int64
+	ChangedAfter    int64
+	BeforeEntryID   int64
+	AfterEntryID    int64
+	Search          string
+	CategoryID      int64
+	FeedID          int64
+	Statuses        []string
 }
 
 // EntryResultSet represents the response when fetching entries.

+ 24 - 14
internal/api/entry.go

@@ -283,28 +283,39 @@ func (h *handler) fetchContent(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 := request.QueryInt64Param(r, "before_entry_id", 0); beforeEntryID > 0 {
 		builder.BeforeEntryID(beforeEntryID)
 	}
 
-	afterEntryID := request.QueryInt64Param(r, "after_entry_id", 0)
-	if afterEntryID > 0 {
+	if afterEntryID := request.QueryInt64Param(r, "after_entry_id", 0); afterEntryID > 0 {
 		builder.AfterEntryID(afterEntryID)
 	}
 
-	beforeTimestamp := request.QueryInt64Param(r, "before", 0)
-	if beforeTimestamp > 0 {
-		builder.BeforeDate(time.Unix(beforeTimestamp, 0))
+	if beforePublishedTimestamp := request.QueryInt64Param(r, "before", 0); beforePublishedTimestamp > 0 {
+		builder.BeforePublishedDate(time.Unix(beforePublishedTimestamp, 0))
 	}
 
-	afterTimestamp := request.QueryInt64Param(r, "after", 0)
-	if afterTimestamp > 0 {
-		builder.AfterDate(time.Unix(afterTimestamp, 0))
+	if afterPublishedTimestamp := request.QueryInt64Param(r, "after", 0); afterPublishedTimestamp > 0 {
+		builder.AfterPublishedDate(time.Unix(afterPublishedTimestamp, 0))
 	}
 
-	categoryID := request.QueryInt64Param(r, "category_id", 0)
-	if categoryID > 0 {
+	if beforePublishedTimestamp := request.QueryInt64Param(r, "published_before", 0); beforePublishedTimestamp > 0 {
+		builder.BeforePublishedDate(time.Unix(beforePublishedTimestamp, 0))
+	}
+
+	if afterPublishedTimestamp := request.QueryInt64Param(r, "published_after", 0); afterPublishedTimestamp > 0 {
+		builder.AfterPublishedDate(time.Unix(afterPublishedTimestamp, 0))
+	}
+
+	if beforeChangedTimestamp := request.QueryInt64Param(r, "changed_before", 0); beforeChangedTimestamp > 0 {
+		builder.BeforeChangedDate(time.Unix(beforeChangedTimestamp, 0))
+	}
+
+	if afterChangedTimestamp := request.QueryInt64Param(r, "changed_after", 0); afterChangedTimestamp > 0 {
+		builder.AfterChangedDate(time.Unix(afterChangedTimestamp, 0))
+	}
+
+	if categoryID := request.QueryInt64Param(r, "category_id", 0); categoryID > 0 {
 		builder.WithCategoryID(categoryID)
 	}
 
@@ -315,8 +326,7 @@ func configureFilters(builder *storage.EntryQueryBuilder, r *http.Request) {
 		}
 	}
 
-	searchQuery := request.QueryStringParam(r, "search", "")
-	if searchQuery != "" {
+	if searchQuery := request.QueryStringParam(r, "search", ""); searchQuery != "" {
 		builder.WithSearchQuery(searchQuery)
 	}
 }

+ 8 - 8
internal/googlereader/handler.go

@@ -1329,10 +1329,10 @@ func (h *handler) handleReadingListStreamHandler(w http.ResponseWriter, r *http.
 	builder.WithOffset(rm.Offset)
 	builder.WithSorting(model.DefaultSortingOrder, rm.SortDirection)
 	if rm.StartTime > 0 {
-		builder.AfterDate(time.Unix(rm.StartTime, 0))
+		builder.AfterPublishedDate(time.Unix(rm.StartTime, 0))
 	}
 	if rm.StopTime > 0 {
-		builder.BeforeDate(time.Unix(rm.StopTime, 0))
+		builder.BeforePublishedDate(time.Unix(rm.StopTime, 0))
 	}
 
 	rawEntryIDs, err := builder.GetEntryIDs()
@@ -1367,10 +1367,10 @@ func (h *handler) handleStarredStreamHandler(w http.ResponseWriter, r *http.Requ
 	builder.WithOffset(rm.Offset)
 	builder.WithSorting(model.DefaultSortingOrder, rm.SortDirection)
 	if rm.StartTime > 0 {
-		builder.AfterDate(time.Unix(rm.StartTime, 0))
+		builder.AfterPublishedDate(time.Unix(rm.StartTime, 0))
 	}
 	if rm.StopTime > 0 {
-		builder.BeforeDate(time.Unix(rm.StopTime, 0))
+		builder.BeforePublishedDate(time.Unix(rm.StopTime, 0))
 	}
 
 	rawEntryIDs, err := builder.GetEntryIDs()
@@ -1405,10 +1405,10 @@ func (h *handler) handleReadStreamHandler(w http.ResponseWriter, r *http.Request
 	builder.WithOffset(rm.Offset)
 	builder.WithSorting(model.DefaultSortingOrder, rm.SortDirection)
 	if rm.StartTime > 0 {
-		builder.AfterDate(time.Unix(rm.StartTime, 0))
+		builder.AfterPublishedDate(time.Unix(rm.StartTime, 0))
 	}
 	if rm.StopTime > 0 {
-		builder.BeforeDate(time.Unix(rm.StopTime, 0))
+		builder.BeforePublishedDate(time.Unix(rm.StopTime, 0))
 	}
 
 	rawEntryIDs, err := builder.GetEntryIDs()
@@ -1449,10 +1449,10 @@ func (h *handler) handleFeedStreamHandler(w http.ResponseWriter, r *http.Request
 	builder.WithOffset(rm.Offset)
 	builder.WithSorting(model.DefaultSortingOrder, rm.SortDirection)
 	if rm.StartTime > 0 {
-		builder.AfterDate(time.Unix(rm.StartTime, 0))
+		builder.AfterPublishedDate(time.Unix(rm.StartTime, 0))
 	}
 	if rm.StopTime > 0 {
-		builder.BeforeDate(time.Unix(rm.StopTime, 0))
+		builder.BeforePublishedDate(time.Unix(rm.StopTime, 0))
 	}
 
 	rawEntryIDs, err := builder.GetEntryIDs()

+ 18 - 4
internal/storage/entry_query_builder.go

@@ -51,15 +51,29 @@ func (e *EntryQueryBuilder) WithStarred(starred bool) *EntryQueryBuilder {
 	return e
 }
 
-// BeforeDate adds a condition < published_at
-func (e *EntryQueryBuilder) BeforeDate(date time.Time) *EntryQueryBuilder {
+// BeforeChangedDate adds a condition < changed_at
+func (e *EntryQueryBuilder) BeforeChangedDate(date time.Time) *EntryQueryBuilder {
+	e.conditions = append(e.conditions, fmt.Sprintf("e.changed_at < $%d", len(e.args)+1))
+	e.args = append(e.args, date)
+	return e
+}
+
+// AfterChangedDate adds a condition > changed_at
+func (e *EntryQueryBuilder) AfterChangedDate(date time.Time) *EntryQueryBuilder {
+	e.conditions = append(e.conditions, fmt.Sprintf("e.changed_at > $%d", len(e.args)+1))
+	e.args = append(e.args, date)
+	return e
+}
+
+// BeforePublishedDate adds a condition < published_at
+func (e *EntryQueryBuilder) BeforePublishedDate(date time.Time) *EntryQueryBuilder {
 	e.conditions = append(e.conditions, fmt.Sprintf("e.published_at < $%d", len(e.args)+1))
 	e.args = append(e.args, date)
 	return e
 }
 
-// AfterDate adds a condition > published_at
-func (e *EntryQueryBuilder) AfterDate(date time.Time) *EntryQueryBuilder {
+// AfterPublishedDate adds a condition > published_at
+func (e *EntryQueryBuilder) AfterPublishedDate(date time.Time) *EntryQueryBuilder {
 	e.conditions = append(e.conditions, fmt.Sprintf("e.published_at > $%d", len(e.args)+1))
 	e.args = append(e.args, date)
 	return e