entities

package
v0.0.7-alpha Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns a boolean indicating whether the error is a not found error.

Types

type Comment

type Comment struct {
	ID          int        `json:"id,omitempty"`
	CreatedAt   *time.Time `json:"created_at,omitempty"`
	UpdatedAt   *time.Time `json:"updated_at,omitempty"`
	DeletedAt   *time.Time `json:"deleted_at,omitempty"`
	Content     string     `json:"content,omitempty" validate:"required"`
	ContentHTML string     `json:"content_html,omitempty" validate:"required"`
	Votes       int64      `json:"votes,omitempty"`
	PostID      int        `json:"post_id,omitempty"`
	UserID      int        `json:"user_id,omitempty"`
	ParentID    int        `json:"parent_id,omitempty"`
	Parent      *Comment
	Post        *Post
	User        *User
}

type CommentFilter

type CommentFilter struct {
	*Filter
	PostIDs   []int `form:"post_ids" json:"post_ids"`
	UserIDs   []int `form:"user_ids" json:"user_ids"`
	ParentIDs []int `form:"parent_ids" json:"parent_ids"`
}

func (*CommentFilter) Base

func (p *CommentFilter) Base() string

type CommentMutation

type CommentMutation struct {
	PostID   int    `json:"post_id" form:"post_id" validate:"required"`
	ParentID int    `json:"parent_id" form:"parent_id"`
	Content  string `json:"content" form:"content" validate:"required"`
}

type Entity

type Entity interface {
	Comment | File | Permission | Post | Page | Role | Setting | Topic | User
}

type File

type File struct {
	ID        int        `json:"id,omitempty"`
	Disk      string     `json:"disk,omitempty"`
	Path      string     `json:"path,omitempty"`
	Type      string     `json:"type,omitempty"`
	Size      int        `json:"size,omitempty"`
	UserID    int        `json:"user_id,omitempty"`
	User      *User      `json:"user,omitempty"`
	Posts     []*Post    `json:"post,omitempty"`
	CreatedAt *time.Time `json:"created_at,omitempty"`
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
	DeletedAt *time.Time `json:"deleted_at,omitempty"`
}

func (*File) Delete

func (f *File) Delete(ctx context.Context) error

func (*File) Url

func (f *File) Url() string

type FileFilter

type FileFilter struct {
	*Filter
	UserIDs []int `form:"user_ids" json:"user_ids"`
}

func (*FileFilter) Base

func (p *FileFilter) Base() string

type Filter

type Filter struct {
	BaseUrl         string   `json:"base_url"`
	Search          string   `form:"search" json:"search"`
	Page            int      `form:"page" json:"page"`
	Limit           int      `form:"limit" json:"limit"`
	Sorts           []*Sort  `form:"orders" json:"orders"`
	IgnoreUrlParams []string `form:"ignore_url_params" json:"ignore_url_params"`
	ExcludeIDs      []int    `form:"exclude_ids" json:"exclude_ids"`
}

func (*Filter) Base

func (p *Filter) Base() string

func (*Filter) FilterBaseUrl

func (p *Filter) FilterBaseUrl() string

func (*Filter) GetExcludeIDs

func (f *Filter) GetExcludeIDs() []int

func (*Filter) GetIgnoreUrlParams

func (f *Filter) GetIgnoreUrlParams() []string

func (*Filter) GetLimit

func (f *Filter) GetLimit() int

func (*Filter) GetPage

func (f *Filter) GetPage() int

func (*Filter) GetSearch

func (f *Filter) GetSearch() string

func (*Filter) GetSorts

func (f *Filter) GetSorts() []*Sort

type GetPostFn

type GetPostFn func(ctx context.Context, id int) (*Post, error)

type GetPostsFn

type GetPostsFn func(ctx context.Context, limit, offset int) ([]*Post, error)

type Map

type Map map[string]interface{}

type Message

type Message struct {
	Type    string `json:"type"`
	Message string `json:"message"`
}

type Messages

type Messages []*Message

func (*Messages) Append

func (ms *Messages) Append(m *Message)

func (*Messages) AppendError

func (ms *Messages) AppendError(m string)

func (*Messages) Get

func (ms *Messages) Get() []*Message

func (*Messages) HasError

func (ms *Messages) HasError() bool

func (*Messages) Length

func (ms *Messages) Length() int

type Meta

type Meta struct {
	Title       string
	Description string
	Query       string
	Type        string
	Image       string
	Canonical   string
	User        *User
	Messages    *Messages
}

func (*Meta) GetTitle

func (m *Meta) GetTitle() string

type NotFoundError

type NotFoundError struct {
	Message string
}

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

Error implements the error interface.

type Page

type Page struct {
	ID              int        `json:"id,omitempty"`
	Name            string     `json:"name,omitempty" validate:"max=255"`
	Slug            string     `json:"slug,omitempty" validate:"max=255"`
	Content         string     `json:"content,omitempty" validate:"required"`
	ContentHTML     string     `json:"content_html,omitempty"`
	Draft           bool       `json:"draft,omitempty"`
	FeaturedImageID int        `json:"featured_image_id,omitempty"`
	FeaturedImage   *File      `json:"featured_image,omitempty"`
	CreatedAt       *time.Time `json:"created_at,omitempty"`
	UpdatedAt       *time.Time `json:"updated_at,omitempty"`
	DeletedAt       *time.Time `json:"deleted_at,omitempty"`
}

Page is the model entity for the Page schema.

func (*Page) Url

func (p *Page) Url() string

type PageFilter

type PageFilter struct {
	*Filter
	Publish string `form:"publish_type" json:"publish_type"` // publish_type = all, published, draft
}

func (*PageFilter) Base

func (p *PageFilter) Base() string

type Paginate

type Paginate[E Entity] struct {
	BaseUrl     string `json:"base_url"`
	QueryString string `json:"query_string"`
	Total       int    `json:"total"`
	PageSize    int    `json:"page_size"`
	PageCurrent int    `json:"page_current"`
	Data        []*E   `json:"data"`
}
func (pp *Paginate[E]) Links() []*PaginateLink
type PaginateLink struct {
	Link  string
	Label string
	Class string
}

type PermType

type PermType string
const (
	PERM_ALL  PermType = "all"
	PERM_OWN  PermType = "own"
	PERM_NONE PermType = "none"
)

func GetPermTypeValue

func GetPermTypeValue(value string) PermType

func (PermType) String

func (s PermType) String() string

type Permission

type Permission struct {
	ID        int        `json:"id,omitempty"`
	CreatedAt *time.Time `json:"created_at,omitempty"`
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
	DeletedAt *time.Time `json:"Deleted_at,omitempty"`
	RoleID    int        `json:"role_id,omitempty"`
	Action    string     `json:"action,omitempty" validate:"max=255"`
	Value     string     `json:"value,omitempty"`
	Role      *Role      `json:"role,omitempty"`
}

Permission is the model entity for the Permission schema.

type PermissionFilter

type PermissionFilter struct {
	*Filter
	RoleIDs []int `form:"role_ids" json:"role_ids"`
}

func (*PermissionFilter) Base

func (p *PermissionFilter) Base() string

type PermissionValue

type PermissionValue struct {
	Action string   `json:"action,omitempty" validate:"max=255"`
	Value  PermType `json:"value,omitempty"`
}

type Post

type Post struct {
	ID              int        `json:"id,omitempty"`
	CreatedAt       *time.Time `json:"created_at,omitempty"`
	UpdatedAt       *time.Time `json:"updated_at,omitempty"`
	DeletedAt       *time.Time `json:"deleted_at,omitempty"`
	Name            string     `json:"name,omitempty" validate:"max=255"`
	Slug            string     `json:"slug,omitempty" validate:"max=255"`
	Description     string     `json:"description,omitempty" validate:"max=255"`
	Content         string     `json:"content,omitempty" validate:"required"`
	ContentHTML     string     `json:"content_html,omitempty"`
	ViewCount       int64      `json:"view_count,omitempty"`
	CommentCount    int64      `json:"comment_count,omitempty"`
	RatingCount     int64      `json:"rating_count,omitempty"`
	RatingTotal     int64      `json:"rating_total,omitempty"`
	Draft           bool       `json:"draft,omitempty"`
	Approved        bool       `json:"approved,omitempty"`
	FeaturedImageID int        `json:"featured_image_id,omitempty"`
	UserID          int        `json:"user_id,omitempty"`
	User            *User      `json:"user,omitempty"`
	FeaturedImage   *File      `json:"featured_image,omitempty"`
	Topics          []*Topic   `json:"topics,omitempty"`
	TopicIDs        []int      `json:"topic_ids,omitempty"`
}

Post is the model entity for the Post schema.

func (*Post) Url

func (p *Post) Url() string

type PostFilter

type PostFilter struct {
	*Filter
	Approve  string `form:"approve" json:"approve"`           // approve = all, approved, pending
	Publish  string `form:"publish_type" json:"publish_type"` // publish_type = all, published, draft
	UserIDs  []int  `form:"user_ids" json:"user_ids"`
	TopicIDs []int  `form:"topic_ids" json:"topic_ids"`
}

func (*PostFilter) Base

func (p *PostFilter) Base() string

type PostMutation

type PostMutation struct {
	Name            string `form:"name" json:"name"`
	Slug            string `form:"name" json:"slug"`
	Description     string `form:"description" json:"description"`
	Content         string `form:"content" json:"content"`
	ContentHTML     string `form:"content_html" json:"content_html"`
	TopicIDs        []int  `form:"topic_ids" json:"topic_ids"`
	Draft           bool   `form:"draft" json:"draft"`
	FeaturedImageID int    `form:"featured_image_id" json:"featured_image_id"`
}

type PostPaginateFn

type PostPaginateFn func(ctx context.Context, filters ...*PostFilter) (*Paginate[Post], error)

type Role

type Role struct {
	ID          int           `json:"id,omitempty"`
	CreatedAt   *time.Time    `json:"created_at,omitempty"`
	UpdatedAt   *time.Time    `json:"updated_at,omitempty"`
	DeletedAt   *time.Time    `json:"deleted_at,omitempty"`
	Name        string        `json:"name,omitempty" validate:"max=255"`
	Description string        `json:"description,omitempty" validate:"max=255"`
	Root        bool          `json:"root,omitempty"`
	Users       []*User       `json:"users,omitempty"`
	Permissions []*Permission `json:"permissions,omitempty"`
}

Role is the model entity for the Role schema.

type RoleFilter

type RoleFilter struct {
	*Filter
}

func (*RoleFilter) Base

func (p *RoleFilter) Base() string

type RoleMutation

type RoleMutation struct {
	Name        string             `form:"name" json:"name"`
	Description string             `form:"description" json:"description"`
	Root        bool               `form:"root" json:"root"`
	Permissions []*PermissionValue `form:"permissions" json:"permissions"`
}

type RolePermissions

type RolePermissions struct {
	RoleID      int                `json:"role_id,omitempty"`
	Permissions []*PermissionValue `json:"permissions,omitempty"`
}

type Setting

type Setting struct {
	ID        int        `json:"id,omitempty"`
	CreatedAt *time.Time `json:"created_at,omitempty"`
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
	DeletedAt *time.Time `json:"deleted_at,omitempty"`
	Name      string     `json:"name,omitempty"`
	Value     string     `json:"value,omitempty"`
	Type      string     `json:"type,omitempty"`
}

type SettingMutation

type SettingMutation struct {
	Username      string `json:"username,omitempty" form:"username"`
	DisplayName   string `json:"display_name,omitempty" form:"display_name"`
	URL           string `json:"url,omitempty" form:"url"`
	Email         string `json:"email,omitempty" form:"email"`
	Password      string `json:"password,omitempty" form:"password"`
	Bio           string `json:"bio,omitempty" form:"bio"`
	BioHTML       string `json:"bio_html,omitempty" form:"bio_html"`
	AvatarImageID int    `json:"avatar_image_id,omitempty" form:"avatar_image_id"`
}

type Sort

type Sort struct {
	Field string
	Order string
}

type Topic

type Topic struct {
	ID          int        `json:"id,omitempty"`
	CreatedAt   *time.Time `json:"created_at,omitempty"`
	UpdatedAt   *time.Time `json:"updated_at,omitempty"`
	DeletedAt   *time.Time `json:"deleted_at,omitempty"`
	Name        string     `json:"name,omitempty" validate:"max=255"`
	Slug        string     `json:"slug,omitempty" validate:"max=255"`
	Description string     `json:"description,omitempty" validate:"max=255"`
	Content     string     `json:"content,omitempty" validate:"required"`
	ContentHTML string     `json:"content_html,omitempty" validate:"required"`
	ParentID    int        `json:"parent_id,omitempty"`
	Parent      *Topic     `json:"parent,omitempty"`
	Children    []*Topic   `json:"children,omitempty"`
	Posts       []*Post    `json:"posts,omitempty"`
}

Topic is the model entity for the Topic schema.

func GetTopicsTree

func GetTopicsTree(topics []*Topic, rootTopic, level int, ignore []int) []*Topic

func PrintTopicsTree

func PrintTopicsTree(topics []*Topic, ignore []int) []*Topic

func (*Topic) FeedUrl

func (t *Topic) FeedUrl() string

func (*Topic) Url

func (t *Topic) Url() string

type TopicFilter

type TopicFilter struct {
	*Filter
}

func (*TopicFilter) Base

func (p *TopicFilter) Base() string

type TopicMutation

type TopicMutation struct {
	ID          int    `form:"id" json:"id"`
	Name        string `form:"name" json:"name"`
	Content     string `form:"content" json:"content"`
	ContentHTML string `json:"content_html,omitempty" validate:"required"`
	ParentID    int    `form:"parent_id" json:"parent_id"`
}

type User

type User struct {
	ID               int        `json:"id,omitempty" form:"id"`
	CreatedAt        *time.Time `json:"created_at,omitempty" form:"created_at"`
	UpdatedAt        *time.Time `json:"updated_at,omitempty" form:"updated_at"`
	DeletedAt        *time.Time `json:"deleted_at,omitempty" form:"deleted_at"`
	Username         string     `json:"username,omitempty" form:"username"`
	DisplayName      string     `json:"display_name,omitempty" form:"display_name"`
	URL              string     `json:"url,omitempty" form:"url"`
	Provider         string     `json:"provider,omitempty" form:"provider"`
	ProviderID       string     `json:"provider_id,omitempty" form:"provider_id"`
	ProviderUsername string     `json:"provider_username,omitempty" form:"provider_username"`
	ProviderAvatar   string     `json:"provider_avatar,omitempty" form:"provider_avatar"`
	Email            string     `json:"email,omitempty" form:"email"`
	Password         string     `json:"password,omitempty" form:"password"`
	Bio              string     `json:"bio,omitempty" form:"bio"`
	BioHTML          string     `json:"bio_html,omitempty" form:"bio_html"`
	RoleIDs          []int      `json:"role_ids,omitempty" form:"role_ids"`
	Roles            []*Role    `json:"roles,omitempty" form:"roles"`
	Active           bool       `json:"active,omitempty" form:"active"`
	AvatarImage      *File      `json:"avatar_image,omitempty" form:"avatar_image"`
	AvatarImageID    int        `json:"avatar_image_id,omitempty" form:"avatar_image_id"`
	AvatarImageUrl   string     `json:"avatar_image_url,omitempty" form:"avatar_image_url"`
}

User is the model entity for the User schema.

func (*User) Avatar

func (u *User) Avatar() string

func (*User) AvatarElm

func (u *User) AvatarElm(width, height string, disableLink bool) string

func (*User) IsRoot

func (u *User) IsRoot() bool

func (*User) JwtClaim

func (u *User) JwtClaim(exp time.Time, jwtHeaders ...map[string]interface{}) (string, error)

func (*User) Name

func (u *User) Name() string

func (*User) Url

func (u *User) Url() string

type UserFilter

type UserFilter struct {
	*Filter
}

func (*UserFilter) Base

func (p *UserFilter) Base() string

type UserJwtClaims

type UserJwtClaims struct {
	jwt.RegisteredClaims
	User User `json:"user"`
}

type UserMutation

type UserMutation struct {
	Username         string `json:"username,omitempty" form:"username"`
	DisplayName      string `json:"display_name,omitempty" form:"display_name"`
	URL              string `json:"url,omitempty" form:"url"`
	Provider         string `json:"provider,omitempty" form:"provider"`
	ProviderID       string `json:"provider_id,omitempty" form:"provider_id"`
	ProviderUsername string `json:"provider_username,omitempty" form:"provider_username"`
	ProviderAvatar   string `json:"provider_avatar,omitempty" form:"provider_avatar"`
	Email            string `json:"email,omitempty" form:"email"`
	Password         string `json:"password,omitempty" form:"password"`
	Bio              string `json:"bio,omitempty" form:"bio"`
	RoleIDs          []int  `json:"role_ids,omitempty" form:"role_ids"`
	Active           bool   `json:"active,omitempty" form:"active"`
}

Jump to

Keyboard shortcuts

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