user

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KB = 1000
)

Variables

This section is empty.

Functions

func NewMiddleware added in v0.4.0

func NewMiddleware(service Service, logger log.Logger) middleware

NewMiddleware creates a new user Middleware.

func RegisterHandlers

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

Types

type ConfirmAccountResponse added in v0.3.0

type ConfirmAccountResponse struct {
	Token    string
	Guid     string
	Username string
}

ConfirmAccountResponse holds data coming from the token generator.

type CreateUserRequest

type CreateUserRequest struct {
	Email    string `json:"email" validate:"required,email" example:"mike@protonmail.com"`
	Username string `json:"username" validate:"required,alphanum,min=1,max=20" example:"mike"`
	Password string `json:"password" validate:"required,min=8,max=30" example:"control123"`
}

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
	// Exists checks if a user exists with a given ID.
	Exists(ctx context.Context, id string) (bool, error)
	EmailExists(ctx context.Context, email string) (bool, error)
	GetByEmail(ctx context.Context, email string) (entity.User, 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)
}

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 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)
	Exists(ctx context.Context, id string) (bool, 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
	GetByEmail(ctx context.Context, id string) (User, error)
	UpdateAvatar(ctx context.Context, id string, src io.Reader) error
	UpdatePassword(ctx context.Context, input UpdatePasswordRequest) error
	UpdateEmail(ctx context.Context, input UpdateEmailRequest) error
	GenerateConfirmationEmail(ctx context.Context, user User) (
		ConfirmAccountResponse, error)
}

Service encapsulates use case logic for users.

func NewService

func NewService(repo Repository, logger log.Logger, tokenGen secure.TokenGenerator,
	sec secure.Password, bucket string, upl Uploader, actSvc activity.Service) Service

NewService creates a new user service.

type UpdateEmailRequest added in v0.3.0

type UpdateEmailRequest struct {
	Password string `json:"password" validate:"required,min=8,max=30" example:"control123"`
	NewEmail string `json:"email" validate:"required,email" example:"mike@proton.me"`
}

UpdateEmailRequest represents an email update request.

type UpdatePasswordRequest added in v0.3.0

type UpdatePasswordRequest struct {
	OldPassword string `json:"old" validate:"required,min=8,max=30" example:"control123"`
	NewPassword string `json:"new_password" validate:"required,necsfield=OldPassword,min=8,max=30" example:"secretControl"`
}

UpdatePasswordRequest represents a password update request.

type UpdateUserRequest

type UpdateUserRequest struct {
	Name     string `json:"name" validate:"omitempty,min=1,max=32" example:"Ibn Taymiyyah"`
	Location string `json:"location" validate:"omitempty,min=1,max=16" example:"Damascus"`
	URL      string `json:"url" validate:"omitempty,url,max=64" example:"https://en.wikipedia.org/wiki/Ibn_Taymiyyah"`
	Bio      string `json:"bio" validate:"omitempty,min=1,max=64" example:"What really counts are good endings, not flawed beginnings."`
}

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