post

package
v0.0.0-...-1ad4281 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrContentLength = errtools.InvalidLen(0, 65500)

ErrContentLength max 65500

View Source
var (
	ErrNoPost = errors.New("post/post: Error No Post Found OR Insufficient permission to view this post")
)

Viewing post errors

Functions

func CanView

func CanView(postID int64, u *session.Session, postCache ...*Post) error

func GetPostsTotal

func GetPostsTotal(u *session.Session) (total int64, err error)

GetPostsTotal TODO: Cache!!!

func GetUserId

func GetUserId(postID int64) (int64, error)

func GetUserPostsTotal

func GetUserPostsTotal(userID int64) (total int64, err error)

GetUserPostsTotal TODO: Cache!!!

func Published

func Published(postID int64) (bool, error)

func UpdateContent

func UpdateContent(postID int64, content string) error

func ValidateContent

func ValidateContent(content string) error

ValidateContent is content valid

Types

type List

type List struct {
	Posts ListPosts       `json:"posts"`
	Order map[int64]int64 `json:"order"`
}

func GetPosts

func GetPosts(startNum, perPage int64, u *session.Session) (*List, error)

GetPublicPosts TODO: Cache

func GetUserPosts

func GetUserPosts(userID, startNum, perPage int64) (*List, error)

func NewList

func NewList() *List

type ListPosts

type ListPosts map[int64]*Post

type Post

type Post struct {
	ID        int64          `msg:"id" json:"id"`
	UserID    int64          `msg:"userId" json:"userId"`
	Created   int64          `msg:"created" json:"created,omitempty"`
	Published int64          `msg:"published" json:"published"`
	Updated   int64          `msg:"updated" json:"updated"`
	Content   string         `msg:"content" json:"content"`
	Media     bool           `msg:"media" json:"media"`
	MediaList []*media.Media `msg:"mediaList" json:"mediaList,omitempty"`
}

Post struct

func Get

func Get(postID int64) (*Post, error)

Get Post TODO: Cache

func GetForUser

func GetForUser(postID int64, u *session.Session) (*Post, error)

GetForUser returns post if user can view it

func New

func New(userID int64, content string, publish bool) *Post

New Post

func (*Post) ContentValid

func (p *Post) ContentValid() error

ContentValid is html escaped content valid

func (*Post) DecodeMsg

func (z *Post) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Post) EncodeMsg

func (z *Post) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Post) Insert

func (p *Post) Insert() error

Insert into database

func (*Post) IsPoster

func (p *Post) IsPoster(userID int64) bool

func (*Post) IsPublished

func (p *Post) IsPublished() bool

IsPublished is post draft

func (*Post) MDtoHTMLContent

func (p *Post) MDtoHTMLContent()

MDtoHTMLContent convert markdown to html and sanitize

func (*Post) MarshalMsg

func (z *Post) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Post) Msgsize

func (z *Post) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Post) Publish

func (p *Post) Publish() error

Publish post if not already

func (*Post) UnmarshalMsg

func (z *Post) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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