|
|
@@ -25,72 +25,88 @@ type entryPaginationBuilder struct {
|
|
|
}
|
|
|
|
|
|
// WithSearchQuery adds full-text search query to the condition.
|
|
|
-func (e *entryPaginationBuilder) WithSearchQuery(query string) {
|
|
|
+func (e *entryPaginationBuilder) WithSearchQuery(query string) *entryPaginationBuilder {
|
|
|
if query != "" {
|
|
|
e.conditions = append(e.conditions, fmt.Sprintf("e.document_vectors @@ plainto_tsquery($%d)", len(e.args)+1))
|
|
|
e.args = append(e.args, query)
|
|
|
}
|
|
|
+
|
|
|
+ return e
|
|
|
}
|
|
|
|
|
|
// WithStarred adds starred to the condition.
|
|
|
-func (e *entryPaginationBuilder) WithStarred() {
|
|
|
+func (e *entryPaginationBuilder) WithStarred() *entryPaginationBuilder {
|
|
|
e.conditions = append(e.conditions, "e.starred is true")
|
|
|
+
|
|
|
+ return e
|
|
|
}
|
|
|
|
|
|
// WithFeedID adds feed_id to the condition.
|
|
|
-func (e *entryPaginationBuilder) WithFeedID(feedID int64) {
|
|
|
+func (e *entryPaginationBuilder) WithFeedID(feedID int64) *entryPaginationBuilder {
|
|
|
if feedID != 0 {
|
|
|
e.conditions = append(e.conditions, "e.feed_id = $"+strconv.Itoa(len(e.args)+1))
|
|
|
e.args = append(e.args, feedID)
|
|
|
}
|
|
|
+
|
|
|
+ return e
|
|
|
}
|
|
|
|
|
|
// WithCategoryID adds category_id to the condition.
|
|
|
-func (e *entryPaginationBuilder) WithCategoryID(categoryID int64) {
|
|
|
+func (e *entryPaginationBuilder) WithCategoryID(categoryID int64) *entryPaginationBuilder {
|
|
|
if categoryID != 0 {
|
|
|
e.conditions = append(e.conditions, "f.category_id = $"+strconv.Itoa(len(e.args)+1))
|
|
|
e.args = append(e.args, categoryID)
|
|
|
}
|
|
|
+
|
|
|
+ return e
|
|
|
}
|
|
|
|
|
|
// WithStatus adds status to the condition.
|
|
|
-func (e *entryPaginationBuilder) WithStatus(status string) {
|
|
|
+func (e *entryPaginationBuilder) WithStatus(status string) *entryPaginationBuilder {
|
|
|
if status != "" {
|
|
|
e.conditions = append(e.conditions, "e.status = $"+strconv.Itoa(len(e.args)+1))
|
|
|
e.args = append(e.args, status)
|
|
|
}
|
|
|
+
|
|
|
+ return e
|
|
|
}
|
|
|
|
|
|
// WithStatusOrEntryID adds a status condition that always includes a specific entry ID.
|
|
|
-func (e *entryPaginationBuilder) WithStatusOrEntryID(status string, entryID int64) {
|
|
|
+func (e *entryPaginationBuilder) WithStatusOrEntryID(status string, entryID int64) *entryPaginationBuilder {
|
|
|
if status == "" {
|
|
|
- return
|
|
|
+ return e
|
|
|
}
|
|
|
|
|
|
if entryID == 0 {
|
|
|
e.WithStatus(status)
|
|
|
- return
|
|
|
+ return e
|
|
|
}
|
|
|
|
|
|
statusArg := len(e.args) + 1
|
|
|
entryArg := len(e.args) + 2
|
|
|
e.conditions = append(e.conditions, fmt.Sprintf("(e.status = $%d OR e.id = $%d)", statusArg, entryArg))
|
|
|
e.args = append(e.args, status, entryID)
|
|
|
+
|
|
|
+ return e
|
|
|
}
|
|
|
|
|
|
-func (e *entryPaginationBuilder) WithTags(tags []string) {
|
|
|
+func (e *entryPaginationBuilder) WithTags(tags []string) *entryPaginationBuilder {
|
|
|
if len(tags) > 0 {
|
|
|
for _, tag := range tags {
|
|
|
e.conditions = append(e.conditions, fmt.Sprintf("LOWER($%d) = ANY(LOWER(e.tags::text)::text[])", len(e.args)+1))
|
|
|
e.args = append(e.args, tag)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ return e
|
|
|
}
|
|
|
|
|
|
// WithGloballyVisible adds global visibility to the condition.
|
|
|
-func (e *entryPaginationBuilder) WithGloballyVisible() {
|
|
|
+func (e *entryPaginationBuilder) WithGloballyVisible() *entryPaginationBuilder {
|
|
|
e.conditions = append(e.conditions, "not c.hide_globally")
|
|
|
e.conditions = append(e.conditions, "not f.hide_globally")
|
|
|
+
|
|
|
+ return e
|
|
|
}
|
|
|
|
|
|
// Entries returns previous and next entries.
|