user

package module
v0.0.0-...-ded953e Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHandlers

func RegisterHandlers(r *routing.RouteGroup, agregator Agregator, authHandler routing.Handler, logger log.Logger)

RegisterHandlers sets up the routing of the HTTP handlers.

Types

type Agregator

type Agregator 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 UpdateUserRequest) (User, error)
	Delete(ctx context.Context, id string) (User, error)
}

Agregator encapsulates usecase logic for users

func NewAgregator

func NewAgregator(repo Repository, logger log.Logger) Agregator

NewAgregator creates a new user agregator.

type CreateUserRequest

type CreateUserRequest struct {
	Name string `json:"name"`
}

CreateUserRequest represents an user creation request.

func (CreateUserRequest) Validate

func (m CreateUserRequest) Validate() error

Validate validates the CreateUserRequest fields

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
	// Delete removes the user with given ID from the storage.
	Delete(ctx context.Context, id 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 UpdateUserRequest

type UpdateUserRequest struct {
	Name string `json:"name"`
}

UpdateUserRequest represents an user update request.

func (UpdateUserRequest) Validate

func (m UpdateUserRequest) Validate() error

Validate validates the CreateUserRequest fields

type User

type User struct {
	entity.User
}

User represents the data about an user.

Jump to

Keyboard shortcuts

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