store

package
v0.0.0-...-56ba187 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPost

func AddPost(user *User, post *Post) error

func AddUser

func AddUser(user *User) error

func DeletePost

func DeletePost(post *Post) error

func FetchUserPosts

func FetchUserPosts(user *User) error

func GenerateSalt

func GenerateSalt() ([]byte, error)

func GetDBConnection

func GetDBConnection() *pg.DB

func SetDBConnection

func SetDBConnection(dbOpts *pg.Options)

func UpdatePost

func UpdatePost(post *Post) error

Types

type Post

type Post struct {
	ID         int
	Title      string `binding:"required,min=3,max=50"`
	Content    string `binding:"required,min=5,max=5000"`
	CreatedAt  time.Time
	ModifiedAt time.Time
	UserID     int `json:"-"`
}

func FetchPost

func FetchPost(id int) (*Post, error)

type User

type User struct {
	ID             int
	Username       string `binding:"required,min=3,max=30"`
	Password       string `pg:"-" binding:"required,min=5,max=32"`
	HashedPassword []byte `json:"-"`
	Salt           []byte `json:"-"`
	CreatedAt      time.Time
	ModifiedAt     time.Time
	Posts          []*Post `json:"-" pg:"fk:user_id,rel:has-many,on_delete:CASCADE"`
}

func Authenticate

func Authenticate(username, password string) (*User, error)

func FetchUser

func FetchUser(id int) (*User, error)

func (*User) AfterSelect

func (user *User) AfterSelect(ctx context.Context) error

Jump to

Keyboard shortcuts

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