service

package
v0.0.0-...-96f74f2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateEmail

func ValidateEmail(v *validator.MyValidator, email string)

func ValidateLogin

func ValidateLogin(v *validator.MyValidator, login string)

func ValidatePasswordPlaintext

func ValidatePasswordPlaintext(v *validator.MyValidator, password string)

func ValidatePaste

func ValidatePaste(v *validator.MyValidator, p *models.Paste)

func ValidateTokenPlaintext

func ValidateTokenPlaintext(v *validator.MyValidator, plaintext string)

func ValidateUser

func ValidateUser(v *validator.MyValidator, user *models.User)

Types

type ActivateUserInput

type ActivateUserInput struct {
	TokenPlainText string `json:"token"`
}

type AuthInput

type AuthInput struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

type AuthResp

type AuthResp struct {
	*models.Token `json:"authentication_token"`
}

type Config

type Config struct {
	Host           string
	Port           int
	Env            string
	Status         string
	ActivationLink string
	ResetLink      string
	Limiter        struct {
		RPS     float64
		Burst   int
		Enabled bool
	}
	CORS struct {
		TrustedOrigins config.StringSlice
	}
	BuildTime string
	Version   string
}

Config represents 'super-config' for all services

type CreatePasteInput

type CreatePasteInput struct {
	Title    string `json:"title"`
	Category uint8  `json:"category,omitempty"`
	Text     string `json:"text"`
	Minutes  int32  `json:"minutes"`
}

type Dependencies

type Dependencies struct {
	Logger *logrus.Logger
	DB     postgres.Database
	Cache  cache.Cache
	Mailer rabbitmq.Mailer
	Models *repository.Models
	Wg     *sync.WaitGroup
}

type ListPastesOutput

type ListPastesOutput struct {
	Pastes   []*models.Paste  `json:"pastes"`
	Metadata *models.Metadata `json:"metadata"`
}

type MessageResp

type MessageResp struct {
	Message string `json:"message"`
}

type PastePermissionResponse

type PastePermissionResponse struct {
	Permission models.Permission `json:"permission"`
}

type PasteResp

type PasteResp struct {
	R *models.Paste `json:"paste"`
}

type PasteService

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

func (*PasteService) Create

func (s *PasteService) Create(paste *models.Paste, creator *models.User) error

func (*PasteService) Delete

func (s *PasteService) Delete(id uint16) error

func (*PasteService) GetList

func (s *PasteService) GetList(settings SearchSettings, user *models.User) (*ListPastesOutput, error)

func (*PasteService) GetPaste

func (s *PasteService) GetPaste(id uint16, user *models.User) (*models.Paste, error)

func (*PasteService) GetPasteForUpdate

func (s *PasteService) GetPasteForUpdate(pasteId uint16, in UpdatePasteInput) (*models.Paste, error)

func (*PasteService) GivePermission

func (s *PasteService) GivePermission(pasteId uint16, userLogin string) (*PastePermissionResponse, error)

func (*PasteService) Update

func (s *PasteService) Update(paste *models.Paste) error

type Pastes

type Pastes interface {
	GetList(settings SearchSettings, user *models.User) (*ListPastesOutput, error)
	GetPaste(id uint16, user *models.User) (*models.Paste, error)
	Delete(id uint16) error
	Create(paste *models.Paste, creator *models.User) error
	GetPasteForUpdate(pasteId uint16, in UpdatePasteInput) (*models.Paste, error)
	Update(paste *models.Paste) error
	GivePermission(pasteId uint16, userLogin string) (*PastePermissionResponse, error)
}

type RegistrationInput

type RegistrationInput struct {
	Login    string `json:"login"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

type ResetPasswordInput

type ResetPasswordInput struct {
	Email string `json:"email"`
}

type SearchSettings

type SearchSettings struct {
	Title     string
	Category  uint8
	OnlyUsers bool
	Filters   models.Filters
}

type Services

type Services struct {
	Config
	Deps   Dependencies
	Pastes Pastes
	Users  Users
}

func New

func New(cfg Config, deps Dependencies) *Services

type UpdatePasswordInput

type UpdatePasswordInput struct {
	TokenPlainText string `json:"token"`
	NewPassword    string `json:"password"`
}

type UpdatePasteInput

type UpdatePasteInput struct {
	Title    *string `json:"title"`
	Category *uint8  `json:"category,omitempty"`
	Text     *string `json:"text"`
	Minutes  *int32  `json:"minutes"`
}

type UserResp

type UserResp struct {
	U *models.User `json:"user"`
}

type UserService

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

func (*UserService) Activate

func (s *UserService) Activate(token string) (*models.User, error)

func (*UserService) ActivationRequest

func (s *UserService) ActivationRequest(user *models.User) error

func (*UserService) Login

func (s *UserService) Login(email, password string) (*models.Token, error)

func (*UserService) Register

func (s *UserService) Register(user *models.User) error

func (*UserService) ResetPasswordRequest

func (s *UserService) ResetPasswordRequest(emailAddr string) error

func (*UserService) UpdatePassword

func (s *UserService) UpdatePassword(token, newPasswordPlain string) error

type UserServiceConfig

type UserServiceConfig struct {
	Environment string
}

type Users

type Users interface {
	Register(user *models.User) error
	Login(email, password string) (*models.Token, error)
	Activate(token string) (*models.User, error)
	ActivationRequest(user *models.User) error
	UpdatePassword(token, newPassword string) error
	ResetPasswordRequest(email string) error
}

Jump to

Keyboard shortcuts

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