comments_get

package
v0.0.0-...-b5db161 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

This package's main job is to build the `where` conditions of SQL. Call `GetQueryScopes` to create a LiteDB instance. This can be converted into a `gorm.DB` instance filled with `where` conditions. Call the functions in `expose.go` to get the whole query result, not just the `where` conditions (via Gorm).

This file contains the exposed methods for `comments_get` package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommentsWithinPage

func CommentsWithinPage(pageKey string) func(liteDB) liteDB

func CommentsWithinSite

func CommentsWithinSite(siteName string) func(liteDB) liteDB

func CommentsWithinSomeUsers

func CommentsWithinSomeUsers(allAdminIDs []uint) func(liteDB) liteDB

func CommonScope

func CommonScope(user entity.User) func(liteDB) liteDB

Basic scope for all queries

It will ignore pending comments for non-admin users

func ConvertGormScopes

func ConvertGormScopes(funcs ...func(liteDB) liteDB) []func(*gorm.DB) *gorm.DB

func FindComments

func FindComments(dao *dao.Dao, opts QueryOptions, pg FindOptions) ([]entity.CookedComment, int64, int64)

Find comments by options

func GetQueryScopes

func GetQueryScopes(dao *dao.Dao, opts QueryOptions) func(liteDB) liteDB

Get query scope by params

Please be aware that only `WHERE` conditions are permissible in this function.
For `ORDER BY`, `LIMIT`, and `OFFSET`, please utilize separate functions, as this
function is invoked in both `Find` and `Count`. `ORDER BY`, `LIMIT`, and `OFFSET` cannot
be employed within `Count`.

Updated: The `*gorm.DB` had been refactored to `liteDB`, which is a subset of `*gorm.DB`.
(only contains `WHERE` conditions)

func GetSortSQL

func GetSortSQL(scope Scope, sortBy SortRule) string

Get sort rule

func NoPending

func NoPending(allowUserID ...uint) func(db liteDB) liteDB

func OnlyRoot

func OnlyRoot() func(db *gorm.DB) *gorm.DB

Filter root comments

func PageScopeQuery

func PageScopeQuery(payload PageScopePayload, opts PageScopeOpts) func(liteDB) liteDB

Page Scope

func SearchScope

func SearchScope(dao *dao.Dao, keywords string) func(d liteDB) liteDB

Filter by search keywords

func SiteScopeQuery

func SiteScopeQuery(payload SitePayload, user entity.User) func(liteDB) liteDB

Site Scope (for message center & admin)

func UserScopeQuery

func UserScopeQuery(payload UserScopePayload, opts UserScopeOpts) func(liteDB) liteDB

User Scope (for message center)

Types

type FindOptions

type FindOptions struct {
	Offset int
	Limit  int
	Nested bool
}

type PageScopeOpts

type PageScopeOpts struct {
	AdminUserIDs []uint
}

type PageScopePayload

type PageScopePayload struct {
	Tags     []PageScopeTag
	SiteName string
	PageKey  string
}

type PageScopeTag

type PageScopeTag string
const (
	AdminOnly PageScopeTag = "admin_only"
)

type QueryOptions

type QueryOptions struct {
	User entity.User

	Scope Scope

	PagePayload PageScopePayload
	UserPayload UserScopePayload
	SitePayload SitePayload

	SortBy SortRule

	Search string
}

type Scope

type Scope string
const (
	ScopePage Scope = "page"
	ScopeUser Scope = "user"
	ScopeSite Scope = "site"
)

type SitePayload

type SitePayload struct {
	Type     SiteScopeType
	SiteName string
}

type SiteScopeType

type SiteScopeType string

Site Scope Query Tag

const (
	SiteAll     SiteScopeType = "all"
	SitePending SiteScopeType = "pending"
)

type SortRule

type SortRule string
const (
	SortByDateDesc SortRule = "date_desc"
	SortByDateAsc  SortRule = "date_asc"
	SortByVote     SortRule = "vote"
)

type UserScopeOpts

type UserScopeOpts struct {
	User            entity.User
	GetUserComments func(userID uint) []uint
}

type UserScopePayload

type UserScopePayload struct {
	Type UserScopeType
}

type UserScopeType

type UserScopeType string

User Scope Query Tag

const (
	UserAll      UserScopeType = "all"
	UserMentions UserScopeType = "mentions"
	UserMine     UserScopeType = "mine"
	UserPending  UserScopeType = "pending"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL