user

package
v0.0.0-...-c380036 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(logger *logger.Logger, service IService, cfg *config.Config) *handler

Types

type IService

type IService interface {
	Create(ctx context.Context, user models.UserDTO) (id string, err error)
	Login(ctx context.Context, dto *models.UserDTO) (u *models.User, err error)
	FindByUUID(ctx context.Context, uid string) (u *models.User, err error)
	RevokeToken(ctx context.Context, u *models.User) (ok bool)
	CreateToken(ctx context.Context, u *models.User) (hash string, err error)
	GetOnlineUsers(ctx context.Context) (count int, err error)
	StartWS(w http.ResponseWriter, r *http.Request, u *models.User) error
	ChatStart(ctx context.Context, token string) (u *models.User, code int, err error)
	InitSocketConnection(w http.ResponseWriter, r *http.Request, u *models.User) error
}

func NewService

func NewService(logger *logger.Logger, storage Repository, tokenTTL time.Duration) IService

type Repository

type Repository interface {
	Create(ctx context.Context, user *models.User) (id string, err error)
	StoreMessage(ctx context.Context, message *models.Message) (id int, err error)
	GetUnreadMessages(ctx context.Context, u *models.User, unreadMC int) (messages []models.Message, err error)
	GetUnreadMessagesCount(ctx context.Context, u *models.User) (count int, err error)
	FindOneUser(ctx context.Context, username string) (u *models.User, err error)
	FindOneMessage(ctx context.Context, mid int) (m *models.Message, err error)
	FindByUUID(ctx context.Context, uuid string) (u *models.User, err error)
	UpdateKey(ctx context.Context, user *models.User, key string) (err error)
	UpdateOnline(ctx context.Context, user *models.User, isOnline bool) (err error)
	GetOnline(ctx context.Context) (count int, err error)
}

type Service

type Service struct {
	Upgrader websocket.Upgrader
	// contains filtered or unexported fields
}

func (Service) ChatStart

func (s Service) ChatStart(ctx context.Context, token string) (u *models.User, code int, err error)

func (Service) Create

func (s Service) Create(ctx context.Context, user models.UserDTO) (id string, err error)

func (Service) CreateToken

func (s Service) CreateToken(ctx context.Context, u *models.User) (hash string, err error)

func (Service) FindByUUID

func (s Service) FindByUUID(ctx context.Context, uid string) (u *models.User, err error)

func (Service) GetOnlineUsers

func (s Service) GetOnlineUsers(ctx context.Context) (count int, err error)

func (*Service) InitSocketConnection

func (s *Service) InitSocketConnection(w http.ResponseWriter, r *http.Request, u *models.User) error

func (Service) Login

func (s Service) Login(ctx context.Context, dto *models.UserDTO) (u *models.User, err error)

func (Service) RevokeToken

func (s Service) RevokeToken(ctx context.Context, u *models.User) (ok bool)

func (*Service) StartWS

func (s *Service) StartWS(w http.ResponseWriter, r *http.Request, u *models.User) error

type UserCreateResponse

type UserCreateResponse struct {
	ID       string `json:"id"`
	Username string `json:"userName"`
}

type UserLoginResponse

type UserLoginResponse struct {
	Url string `json:"url" example:"ws://fancy-chat.io/ws&token=one-time-token"`
}

type UserOnlineResponse

type UserOnlineResponse struct {
	Count int `json:"count" example:"0"`
}

Directories

Path Synopsis
database
Package mock_user is a generated GoMock package.
Package mock_user is a generated GoMock package.

Jump to

Keyboard shortcuts

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