Documentation ¶
Overview ¶
Package usecase содержит реализацию логики взаимодействия с сервисами/хранилищем. А также интерфейсы для взаимодействия с этим слоем.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrLoginNotExist = errors.New("login not exist") ErrMismatchPassword = errors.New("password mismatch") )
Functions ¶
This section is empty.
Types ¶
type AuthService ¶
type AuthService struct {
// contains filtered or unexported fields
}
AuthService сервис аутентификации пользователей.
func NewAuthService ¶
func NewAuthService(repo IAuthorizationRepo, hasher password.IPasswordHash, maker token.IMaker) *AuthService
NewAuthService создаёт объект типа AuthService.
func (*AuthService) LoginUser ¶
func (s *AuthService) LoginUser(login, pass string) (string, error)
LoginUser - авторизация существующего пользователя.
Возвращает токен или ошибку (например, если логина не существует).
func (*AuthService) ParseToken ¶
func (s *AuthService) ParseToken(token string) (int, error)
ParseToken - проверяет переданный токен.
Возвращает id пользователя или ошибку.
func (*AuthService) RegisterUser ¶
func (s *AuthService) RegisterUser(login, pass string) (string, error)
RegisterUser - регистрация нового пользователя с переданным логином и паролем.
Возвращает токен или ошибку (например, если логин уже существует).
type BankService ¶
type BankService struct {
// contains filtered or unexported fields
}
BankService сервис доступа к банковским картам.
func NewBankService ¶
func NewBankService(repo IBankRepo) *BankService
NewBankService создаёт объект типа BankService.
func (*BankService) ViewAllCards ¶
func (s *BankService) ViewAllCards(userID int) ([]entity.BankDTO, error)
ViewAllCards получение всех значений банковских карт.
type IAuthorizationRepo ¶
type IAuthorizationRepo interface { // CreateUser - создание пользователя с заданными логином и хэшем пароля. // // Возвращает id пользователя или ошибку (если логин уже существует). CreateUser(login, passwordHash string) (int, error) // GetUser - находит пользователя в БД по логину. // // Возвращает объект пользователя или ошибку (при отсутствии логина). GetUser(login string) (entity.UserDAO, error) }
IAuthorizationRepo абстракция взаимодействия с частью хранилища отвечающей за авторизацию пользователей.
type IAuthorizationService ¶
type IAuthorizationService interface { // RegisterUser - регистрация нового пользователя с переданным логином и паролем. // // Возвращает токен или ошибку (например, если логин уже существует). RegisterUser(login, password string) (string, error) // LoginUser - авторизация существующего пользователя. // // Возвращает токен или ошибку (например, если логина не существует). LoginUser(login, password string) (string, error) // ParseToken - проверяет переданный токен. // // Возвращает id пользователя или ошибку. ParseToken(token string) (int, error) }
IAuthorizationService абстракция сервиса авторизации.
type IBankRepo ¶
type IBankRepo interface { // GetAllCards находит в БД все записи банковских карт принадлежащие конкретному пользователю (userID). GetAllCards(ctx context.Context, userID int) ([]entity.BankDAO, error) }
IBankRepo абстракция взаимодействия с частью хранилища отвечающей за хранение банковских данных о картах.
type IBankService ¶
type IBankService interface { // ViewAllCards получение всех значений банковских карт. ViewAllCards(userID int) ([]entity.BankDTO, error) }
IBankService абстракция сервиса доступа к банковским картам.
type IPairsRepo ¶
type IPairsRepo interface { // GetAllPairs находит в БД все записи типа логин/пароль принадлежащие конкретному пользователю (userID). GetAllPairs(ctx context.Context, userID int) ([]entity.PairDAO, error) }
IPairsRepo абстракция взаимодействия с частью хранилища отвечающей за хранение пар логин/пароль.
type IPairsService ¶
type IPairsService interface { // ViewAllPairs получение всех значений типа логин/пароль. ViewAllPairs(userID int) ([]entity.PairDTO, error) }
IPairsService абстракция сервиса доступа к парам логин/пароль.
type IRepo ¶
type IRepo interface { IAuthorizationRepo IPairsRepo IBankRepo ITextRepo CloseConnection() error }
IRepo общая абстракция для взаимодействия с хранилищем.
type IService ¶
type IService interface { IAuthorizationService IPairsService IBankService ITextService }
IService общая абстракция для взаимодействия с сервисами.
type ITextService ¶
type ITextService interface { // ViewAllNotes получение всех значений заметок. ViewAllNotes(userID int) ([]entity.TextDTO, error) }
ITextService абстракция сервиса доступа к заметкам.
type PairsService ¶
type PairsService struct {
// contains filtered or unexported fields
}
PairsService сервис доступа к типу логин/пароль.
func NewPairsService ¶
func NewPairsService(repo IPairsRepo) *PairsService
NewPairsService создаёт объект типа PairsService.
func (*PairsService) ViewAllPairs ¶
func (s *PairsService) ViewAllPairs(userID int) ([]entity.PairDTO, error)
ViewAllPairs получение всех значений типа логин/пароль.
type TextService ¶
type TextService struct {
// contains filtered or unexported fields
}
TextService сервис доступа к заметкам.
func NewTextService ¶
func NewTextService(repo ITextRepo) *TextService
NewTextService создаёт объект типа TextService.
func (*TextService) ViewAllNotes ¶
func (s *TextService) ViewAllNotes(userID int) ([]entity.TextDTO, error)
ViewAllNotes получение всех значений заметок.
type Usecase ¶
type Usecase struct { IAuthorizationService IPairsService IBankService ITextService }
Usecase обеспечивает логику взаимодействия с сервисами/хранилищем.
func New ¶
func New(auth IAuthorizationService, pairs IPairsService, cards IBankService, notes ITextService, ) (*Usecase, error)
New создаёт объект Usecase.