models

package
v0.0.0-...-f436a4a Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrChatNameIsEmpty modelError = "'name' can't be empty"
	ErrChatNameIsNull  modelError = "'name' can't be null"
	ErrChatUserIsNull  modelError = "'user' can't be null"

	ErrChatUsersIsNull     modelError = "'users' can't be null"
	ErrChatUsersIsEmpty    modelError = "'users' can't be empty"
	ErrChatUsersIDsAreNull modelError = "'users' can't contain null(s)"

	ErrChatAlreadyExists      modelError = "The chat with this name already exists"
	ErrChatSomeUsersDontExist modelError = "Some users don't exist"
)
View Source
const (
	ErrNoSuchEndpointExists modelError = "No such endpoint exists"
	ErrNoSuchHTTPMethod     modelError = "Wrong http method"
)
View Source
const (
	ErrMessageChatDoesntExist modelError = "The chat with the provided id doesn't exist"
	ErrMessageUserDoesntExist modelError = "The user with the provided id doesn't exist"
	ErrMessageUserIsNotInChat modelError = "The user is not in the chat"

	ErrMessageChatIsNull   modelError = "'chat' can't be null"
	ErrMessageAuthorIsNull modelError = "'author' can't be null"
	ErrMessageTextIsNull   modelError = "'text' can't be null"
	ErrMessageTextIsEmpty  modelError = "'text' can't be empty"
)
View Source
const (
	ErrUserNameIsEmpty modelError = "'username' can't be empty"

	ErrUserNameIsNull modelError = "'username' can't be null"

	ErrUserAlreadyExists modelError = "User with this name already exists"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Chat

type Chat struct {
	ID        *uint   `gorm:"primary_key"`
	Name      *string `gorm:"unique;not null"`
	Users     []*User `gorm:"many2many:chats_users"`
	CreatedAt *time.Time
	Messages  []*Message
}

type ChatDB

type ChatDB interface {
	Create(cqp *ChatQueryParams) (uint, int, error)
	ByUserID(userID *uint) ([]*Chat, int, error)
}

type ChatQueryParams

type ChatQueryParams struct {
	Name    *string     `json:"name"`
	UserIDs []*stringID `json:"users"`
	UserID  *uint       `json:"user,string"`
}

type ChatService

type ChatService interface {
	ChatDB
}

func NewChatService

func NewChatService(db *gorm.DB) ChatService

type Message

type Message struct {
	ID        *uint   `gorm:"primary_key"`
	ChatID    *uint   `json:"chat,string"`   // chat
	UserID    *uint   `json:"author,string"` // author
	Text      *string `gorm:"not null" json:"text"`
	CreatedAt *time.Time
}

type MessageDB

type MessageDB interface {
	Create(msg *Message) (uint, int, error)
	ByChatID(chatid *uint) ([]*Message, int, error)
}

type MessageService

type MessageService interface {
	MessageDB
}

func NewMessageService

func NewMessageService(db *gorm.DB) MessageService

type Services

type Services struct {
	User    UserService
	Chat    ChatService
	Message MessageService
	// contains filtered or unexported fields
}

func NewServices

func NewServices(cfgs ...ServicesConfig) (*Services, error)

func (*Services) Close

func (s *Services) Close()

func (*Services) CloseStorage

func (s *Services) CloseStorage()

type ServicesConfig

type ServicesConfig func(*Services) error

func WithChat

func WithChat() ServicesConfig

func WithGorm

func WithGorm(dialect, connectionInfo string, num int, interval uint) ServicesConfig

func WithLogMode

func WithLogMode(mode bool) ServicesConfig

func WithMessage

func WithMessage() ServicesConfig

func WithSetSchema

func WithSetSchema(mode bool) ServicesConfig

func WithUser

func WithUser() ServicesConfig

type User

type User struct {
	ID        *uint   `gorm:"primary_key"`
	Name      *string `gorm:"unique;not null" json:"username"` // username, префикс  user избыточен
	CreatedAt *time.Time
	Chats     []*Chat `gorm:"many2many:chats_users"`
	Messages  []*Message
}

type UserDB

type UserDB interface {
	Create(user *User) (uint, int, error)
}

type UserService

type UserService interface {
	UserDB
}

func NewUserService

func NewUserService(db *gorm.DB) UserService

Jump to

Keyboard shortcuts

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