sql

package
v0.0.0-...-23be0e1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserNotFound         = errors.New("user not found")
	ErrUserNotVerifiedEmail = errors.New("user not verified email")
	ErrorCannotBlockAdmin   = errors.New("cannot block admin")
	ErrorCannotDeleteAdmin  = errors.New("cannot delete admin")
)
View Source
var (
	ErrCommentNotFound = errors.New("comment not found")
)
View Source
var (
	ErrPostNotFound = errors.New("post not found")
)

Functions

func BuildCommentTree

func BuildCommentTree(comments []*models.Comment) []*models.Comment

func NewID

func NewID() string

Types

type Comment

type Comment struct {
	ID        int32
	AuthorID  int32
	ParentID  int32
	Slug      string
	Body      string
	CreatedAt pgtype.Timestamptz
	UpdatedAt pgtype.Timestamptz
	IsHidden  bool
}

type CommentService

type CommentService struct {
	// contains filtered or unexported fields
}

func NewCommentService

func NewCommentService(db *DB) *CommentService

func (*CommentService) Create

func (s *CommentService) Create(ctx context.Context, comment *models.Comment) error

func (*CommentService) Delete

func (s *CommentService) Delete(ctx context.Context, id int) error

func (*CommentService) DeleteBySlug

func (s *CommentService) DeleteBySlug(ctx context.Context, slug string) error

func (*CommentService) DeleteByUserID

func (s *CommentService) DeleteByUserID(ctx context.Context, userId int) error

func (*CommentService) FindByID

func (s *CommentService) FindByID(ctx context.Context, id int) (*models.Comment, error)

func (*CommentService) FindBySlug

func (s *CommentService) FindBySlug(ctx context.Context, slug string) ([]*models.Comment, int, error)

func (*CommentService) FindComments

func (s *CommentService) FindComments(ctx context.Context, filter models.CommentFilter) ([]*models.Comment, int, error)

func (*CommentService) Hide

func (s *CommentService) Hide(ctx context.Context, id int) error

type CreateUserParams

type CreateUserParams struct {
	Username string
	Email    string
}

type DB

type DB struct {
	Conn *pgx.Conn

	Datasource string
	// contains filtered or unexported fields
}

func NewDB

func NewDB(cfg *config.Config) *DB

func (*DB) Close

func (db *DB) Close() error

func (*DB) Open

func (db *DB) Open() (err error)

func (*DB) Run

func (db *DB) Run(file string) error

Run execute content of sql file into database

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
}

type ListUserParams

type ListUserParams struct {
	Skip int32
	Max  int32
}

type ListUserRow

type ListUserRow struct {
	ID                  int32
	Username            string
	Email               string
	Password            string
	Roles               []string
	EmailToken          string
	CreatedAt           pgtype.Timestamptz
	UpdatedAt           pgtype.Timestamptz
	SendVerifiedEmailAt pgtype.Timestamptz
	ResetPwdToken       string
	RptExpiredAt        pgtype.Timestamptz
	IsBlocked           bool
	Total               int64
}

type Migration

type Migration struct {
	Name string
}

type Post

type Post struct {
	ID             int32
	Title          string
	Slug           string
	Poster         string
	Tags           []string
	Short          string
	Body           string
	AuthorID       int32
	PublishedAt    pgtype.Timestamptz
	CreatedAt      pgtype.Timestamptz
	UpdatedAt      pgtype.Timestamptz
	AuthorUsername string
	IsEditorsPick  bool
}

type PostService

type PostService struct {
	// contains filtered or unexported fields
}

func NewPostService

func NewPostService(db *DB) *PostService

func (*PostService) Create

func (s *PostService) Create(ctx context.Context, post *models.Post) error

func (*PostService) Delete

func (s *PostService) Delete(ctx context.Context, id int) (string, error)

func (*PostService) FindByID

func (s *PostService) FindByID(ctx context.Context, id int) (*models.Post, error)

func (*PostService) FindBySlug

func (s *PostService) FindBySlug(ctx context.Context, slug string) (*models.Post, error)

func (*PostService) FindPosts

func (s *PostService) FindPosts(ctx context.Context, filter models.PostFilter) ([]*models.Post, int, error)

func (*PostService) Update

func (s *PostService) Update(ctx context.Context, post *models.Post) error

type Queries

type Queries struct {
	// contains filtered or unexported fields
}

func New

func New(db DBTX) *Queries

func (*Queries) CreateUser

func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (int32, error)

func (*Queries) GetUser

func (q *Queries) GetUser(ctx context.Context, id int32) (User, error)

func (*Queries) ListUser

func (q *Queries) ListUser(ctx context.Context, arg ListUserParams) ([]ListUserRow, error)

func (*Queries) UpdateUser

func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error)

func (*Queries) WithTx

func (q *Queries) WithTx(tx pgx.Tx) *Queries

type Scanner

type Scanner interface {
	Scan(dest ...interface{}) error
}

type UpdateUserParams

type UpdateUserParams struct {
	EmailDoUpdate    bool
	Email            string
	UsernameDoUpdate bool
	Username         string
	ID               int32
}

type User

type User struct {
	ID                  int32
	Username            string
	Email               string
	Password            string
	Roles               []string
	EmailToken          string
	CreatedAt           pgtype.Timestamptz
	UpdatedAt           pgtype.Timestamptz
	SendVerifiedEmailAt pgtype.Timestamptz
	ResetPwdToken       string
	RptExpiredAt        pgtype.Timestamptz
	IsBlocked           bool
}

type UserService

type UserService struct {
	// contains filtered or unexported fields
}

func NewUserService

func NewUserService(db *DB) *UserService

func (*UserService) AddRole

func (s *UserService) AddRole(ctx context.Context, user *models.User, role string) error

func (*UserService) Auth

func (s *UserService) Auth(ctx context.Context, user *models.User) (*models.User, error)

func (*UserService) Block

func (s *UserService) Block(ctx context.Context, id int) error

func (*UserService) CompareHashAndPassword

func (s *UserService) CompareHashAndPassword(hashed string, password string) error

func (*UserService) Create

func (s *UserService) Create(ctx context.Context, user *models.User) (*models.User, error)

func (*UserService) Delete

func (s *UserService) Delete(ctx context.Context, id int) error

func (*UserService) FindByEmailToken

func (s *UserService) FindByEmailToken(ctx context.Context, token string) (*models.User, error)

func (*UserService) FindByID

func (s *UserService) FindByID(ctx context.Context, id int) (*models.User, error)

func (*UserService) FindByRPT

func (s *UserService) FindByRPT(ctx context.Context, token string) (*models.User, error)

func (*UserService) FindUsers

func (s *UserService) FindUsers(ctx context.Context, filter models.UserFilter) ([]*models.User, int, error)

func (*UserService) HasRole

func (s *UserService) HasRole(ctx context.Context, id int, role string) (bool, error)

func (*UserService) HashPassword

func (s *UserService) HashPassword(str string) (string, error)

func (*UserService) LogSendResetPassword

func (s *UserService) LogSendResetPassword(ctx context.Context, email string) (*models.User, error)

func (*UserService) LogSendVerifyEmail

func (s *UserService) LogSendVerifyEmail(ctx context.Context, user *models.User) error

func (*UserService) UpdatePassword

func (s *UserService) UpdatePassword(ctx context.Context, user *models.User) error

Jump to

Keyboard shortcuts

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