service

package
v0.0.0-...-697c109 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserAlreadyExists = fmt.Errorf("user already exist")
	ErrCannotCreateUser  = fmt.Errorf("cannot create user")
	ErrUserNotFound      = fmt.Errorf("user not found")
	ErrCannotGetUser     = fmt.Errorf("cannot get user")

	ErrSlugAlreadyExists = fmt.Errorf("slug already exist")
	ErrCannotCreateSlug  = fmt.Errorf("cannot create slug")
	ErrSlugNotFound      = fmt.Errorf("slug not found")
	ErrCannotDeleteSlug  = fmt.Errorf("cannot delete slug")
	ErrCannotGetSlug     = fmt.Errorf("cannot get slug")

	ErrCannotSignToken  = fmt.Errorf("cannot sign token")
	ErrCannotParseToken = fmt.Errorf("cannot parse tocken")
)

Functions

This section is empty.

Types

type Auth

type Auth interface {
	CreateUser(ctx context.Context, input AuthCreateUserInput) (int, error)
	GenerateToken(ctx context.Context, input AuthGenerateTokenInput) (string, error)
	ParseToken(token string) (int, error)
}

type AuthCreateUserInput

type AuthCreateUserInput struct {
	Username string
	Password string
}

type AuthGenerateTokenInput

type AuthGenerateTokenInput struct {
	Username string
	Password string
}

type AuthService

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

func NewAuthService

func NewAuthService(
	userRepo repo.User,
	passwordHasher hasher.PasswordHasher,
	signKey string,
	tokenTTL time.Duration,
) *AuthService

func (*AuthService) CreateUser

func (s *AuthService) CreateUser(ctx context.Context, input AuthCreateUserInput) (int, error)

func (*AuthService) GenerateToken

func (s *AuthService) GenerateToken(ctx context.Context, input AuthGenerateTokenInput) (string, error)

func (*AuthService) ParseToken

func (s *AuthService) ParseToken(accessToken string) (int, error)

type Services

type Services struct {
	User User
	Slug Slug
	Auth Auth
}

func NewServices

func NewServices(deps *ServicesDependencies) *Services

type ServicesDependencies

type ServicesDependencies struct {
	Repos    *repo.Repositories
	Hasher   hasher.PasswordHasher
	SignKey  string
	TokenTTL time.Duration
}

type Slug

type Slug interface {
	CreateSlug(ctx context.Context, slugName string) (int, error)
	DeleteSlug(ctx context.Context, slugName string) error
	AddUserToSlug(ctx context.Context, slugsToAdd []string, slugsToDelete []string, userId int) error
	GetActiveSlugs(ctx context.Context, userId int) ([]entities.Slug, error)
}

type SlugService

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

func NewSlugService

func NewSlugService(userRepo repo.User, slugRepo repo.Slug, membershipRepo repo.Membership) *SlugService

func (*SlugService) AddUserToSlug

func (s *SlugService) AddUserToSlug(ctx context.Context, slugsToAdd []string, slugsToDelete []string, userId int) error

func (*SlugService) CreateSlug

func (s *SlugService) CreateSlug(ctx context.Context, slugName string) (int, error)

func (*SlugService) DeleteSlug

func (s *SlugService) DeleteSlug(ctx context.Context, slugName string) error

func (*SlugService) GetActiveSlugs

func (s *SlugService) GetActiveSlugs(ctx context.Context, userId int) ([]entities.Slug, error)

type TokenClaims

type TokenClaims struct {
	jwt.StandardClaims
	UserId int
}

type User

type User interface {
	GetUserById(ctx context.Context, id int) (entities.User, error)
	GetUserByUsername(ctx context.Context, username string) (entities.User, error)
	GetUserByUsernameAndPassword(ctx context.Context, username, password string) (entities.User, error)
}

type UserService

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

func NewUserService

func NewUserService(userRepo repo.User) *UserService

func (*UserService) GetUserById

func (s *UserService) GetUserById(ctx context.Context, id int) (entities.User, error)

func (*UserService) GetUserByUsername

func (s *UserService) GetUserByUsername(ctx context.Context, username string) (entities.User, error)

func (*UserService) GetUserByUsernameAndPassword

func (s *UserService) GetUserByUsernameAndPassword(ctx context.Context, username, password string) (entities.User, error)

Jump to

Keyboard shortcuts

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