account

package
v0.0.0-...-d0162ed Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHandlers

func RegisterHandlers(r *echo.Group, service Service, logger log.Logger)

RegisterHandlers sets up the routing of the HTTP handlers.

Types

type Account

type Account struct {
	entity.Account
}

Account represents the data about an account.

type ChangePasswordRequest

type ChangePasswordRequest struct {
	Password    string `json:"password"`
	NewPassword string `json:"new_password"`
}

ChangePasswordRequest represents an account update request.

func (ChangePasswordRequest) Validate

func (m ChangePasswordRequest) Validate() *response.Error

Validate validates the CreateAccountRequest fields.

type CreateAccountRequest

type CreateAccountRequest struct {
	Username               string   `json:"username"`
	Password               string   `json:"password"`
	Resources              []string `json:"resources"`
	RequiresPasswordChange *bool    `json:"requires_password_change,omitempty"`
}

CreateAccountRequest represents an account creation request.

func (CreateAccountRequest) Validate

func (m CreateAccountRequest) Validate() *response.Error

Validate validates the CreateAccountRequest fields.

type CreateAccountResponse

type CreateAccountResponse struct {
	UserName               string `json:"user_name"`
	Resources              string `json:"resources"`
	RequiresPasswordChange bool   `json:"requires_password_change"`
}

CreateAccountResponse the response returned on account creation.

type ExtAccount

type ExtAccount struct {
	UserName               string `json:"id"`
	Resources              string `json:"resources"`
	RequiresPasswordChange bool   `json:"requires_password_change"`
}

type ExtListResponse

type ExtListResponse struct {
	Page       int          `json:"page"`
	PerPage    int          `json:"per_page"`
	PageCount  int          `json:"page_count"`
	TotalCount int          `json:"total_count"`
	Items      []ExtAccount `json:"items"`
}

type FactService

type FactService interface {
	Request(*fact.FactRequest) (*fact.FactResponse, error)
}

FactService service to manage sending and receiving fact requests

type Repository

type Repository interface {
	// Get returns the account with the specified username and password.
	Get(ctx context.Context, username, password string) (entity.Account, error)
	// GetByUsername returns the account with the specified username.
	GetByUsername(ctx context.Context, username string) (entity.Account, error)
	// Count returns the number of accounts.
	Count(ctx context.Context) (int, error)
	// Create saves a new account in the storage.
	Create(ctx context.Context, account entity.Account) error
	// Update updates the account with given ID in the storage.
	Update(ctx context.Context, account entity.Account) error
	// SetPassword updates the password for the given account id.
	SetPassword(ctx context.Context, id int, password string) error
	// Delete removes the account with given ID from the storage.
	Delete(ctx context.Context, id int) error
	// List returns a list of all entity.Account
	List(ctx context.Context) ([]entity.Account, error)
}

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

func NewRepository

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

NewRepository creates a new account repository

type Service

type Service interface {
	Get(ctx context.Context, username, password string) (Account, error)
	Create(ctx context.Context, input CreateAccountRequest) (Account, error)
	SetPassword(ctx context.Context, username, password, newPassword string) error
	Delete(ctx context.Context, username string) error
	Count(ctx context.Context) (int, error)
	List(ctx context.Context) []ExtAccount
}

Service encapsulates usecase logic for accounts.

func NewService

func NewService(repo Repository, logger log.Logger) Service

NewService creates a new account service.

Jump to

Keyboard shortcuts

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