user

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHandlers

func RegisterHandlers(g *echo.Group, service Service,
	requireLogin echo.MiddlewareFunc, optionalLogin echo.MiddlewareFunc,
	logger log.Logger, mailer Mailer)

Types

type CreateUserRequest

type CreateUserRequest struct {
	Email    string `json:"email" validate:"required,email"`
	Username string `json:"username" validate:"required,alphanum,min=1,max=20"`
	Password string `json:"password" validate:"required,alphanum,min=8,max=30"`
}

CreateUserRequest represents a user creation request.

type Mailer

type Mailer interface {
	Send(body, subject, from, to string) error
}

Mailer represents the mailer interface/

type Repository

type Repository interface {
	// Get returns the user with the specified user ID.
	Get(ctx context.Context, id string) (entity.User, error)
	// Count returns the number of users.
	Count(ctx context.Context) (int, error)
	// Query returns the list of users with the given offset and limit.
	Query(ctx context.Context, offset, limit int) ([]entity.User, error)
	// Create saves a new user in the storage.
	Create(ctx context.Context, User entity.User) error
	// Update updates the user with given ID in the storage.
	Update(ctx context.Context, User entity.User) error
	// Patch patches a sub entry in the user with given ID in the storage.
	Patch(ctx context.Context, key, path string, val interface{}) error
	// Delete removes the user with given ID from the storage.
	Delete(ctx context.Context, id string) error
	EmailExists(ctx context.Context, email string) (bool, error)
	Likes(ctx context.Context, id string, offset, limit int) (
		[]interface{}, error)
	Followers(ctx context.Context, id string, offset, limit int) (
		[]interface{}, error)
	Following(ctx context.Context, id string, offset, limit int) (
		[]interface{}, error)
	Submissions(ctx context.Context, id string, offset, limit int) (
		[]interface{}, error)
	Comments(ctx context.Context, id string, offset, limit int) (
		[]interface{}, error)
	Activities(ctx context.Context, id string, offset, limit int) ([]interface{}, error)
	CountActivities(ctx context.Context) (int, error)
	DeleteActivity(ctx context.Context, kind, username, target string) error
}

Repository encapsulates the logic to access users from the data source.

func NewRepository

func NewRepository(db *dbcontext.DB, logger log.Logger) Repository

NewRepository creates a new user repository.

type Securer

type Securer interface {
	HashPW(string) string
}

Securer represents security interface.

type Service

type Service interface {
	Get(ctx context.Context, id string) (User, error)
	Query(ctx context.Context, offset, limit int) ([]User, error)
	Count(ctx context.Context) (int, error)
	Create(ctx context.Context, input CreateUserRequest) (User, error)
	Update(ctx context.Context, id string, input interface{}) (User, error)
	Patch(ctx context.Context, id, path string, input interface{}) error
	Delete(ctx context.Context, id string) (User, error)
	Activities(ctx context.Context, id string, offset, limit int) (
		[]interface{}, error)
	Likes(ctx context.Context, id string, offset, limit int) (
		[]interface{}, error)
	Followers(ctx context.Context, id string, offset, limit int) (
		[]interface{}, error)
	Following(ctx context.Context, id string, offset, limit int) (
		[]interface{}, error)
	Submissions(ctx context.Context, id string, offset, limit int) (
		[]interface{}, error)
	Comments(ctx context.Context, id string, offset, limit int) (
		[]interface{}, error)
	CountActivities(ctx context.Context) (int, error)
	CountLikes(ctx context.Context, id string) (int, error)
	CountFollowing(ctx context.Context, id string) (int, error)
	CountFollowers(ctx context.Context, id string) (int, error)
	CountComments(ctx context.Context, id string) (int, error)
	CountSubmissions(ctx context.Context, id string) (int, error)
	Follow(ctx context.Context, id string) error
	Unfollow(ctx context.Context, id string) error
	UpdateAvatar(ctx context.Context, id string, src io.Reader) error
}

Service encapsulates usecase logic for users.

func NewService

func NewService(repo Repository, logger log.Logger, sec Securer,
	bucket string, upl Uploader, actSvc activity.Service) Service

NewService creates a new user service.

type UpdateUserRequest

type UpdateUserRequest struct {
	Name     string `json:"name" validate:"omitempty,min=1,max=32"`
	Location string `json:"location" validate:"omitempty,alphanumunicode,min=2,max=16"`
	URL      string `json:"url" validate:"omitempty,url,max=64"`
	Bio      string `json:"bio" validate:"omitempty,printascii,min=1,max=64"`
}

UpdateUserRequest represents a user update request.

type Uploader

type Uploader interface {
	Upload(ctx context.Context, bucket, key string, file io.Reader) error
}

Uploader represents the file upload interface.

type User

type User struct {
	entity.User
}

User represents the data about a user.

Jump to

Keyboard shortcuts

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