db2

package
v0.0.0-...-1a912f8 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2019 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//GetUserError - cannot get user
	GetUserError = "Get user error ->"
	//InsertChatError - cannot make insert
	InsertChatError = "Insert chat error ->"
	//InsertUserInChatError - cannot insert user in chat
	InsertUserInChatError = "Insert user in chat error ->"
	//InsertUserInDialogError - cannot insert user in dialog
	InsertUserInDialogError = "Insert user in dialog error ->"
	//InsertUserInChannelError - cannot insert user in cahnnel
	InsertUserInChannelError = "Insert user in channel error ->"
	//UserAlreadyExistInChatError - cannot insert user in chat user already in
	UserAlreadyExistInChatError = "User already in chat ->"
	//AddMessageError - cannot send message
	AddMessageError = "Send message error ->"
	//GetChatError - getting chat failed
	GetChatError = "Getting chat failed ->"
	//UserIsntAuthorError - user havent rights
	UserIsntAuthorError = "User isnt author ->"
	//GetChatUserError - cannot get chat's user
	GetChatUserError = "Gettings chat user failed ->"
	//GetDeletePointsError - getting delete points failed
	GetDeletePointsError = "Failed get delete points ->"
	//SetDeletePointsError - settings delete points failed
	SetDeletePointsError = "Failed set delete points ->"
	//UpdateChatUserError - updating chat user failed
	UpdateChatUserError = "Failed update chat user ->"
	//UpdateChatError - updating chat failed
	UpdateChatError = "Failed update chat ->"
	//UserYetDidntDeleteError - user wasn't deleted
	UserYetDidntDeleteError = "User wasn't delete ->"
	//WrongChatType - got wrong chat's type
	WrongChatType = "Got wrong chat't type ->"
	//GettingUsersChatInfoFailed - getting user's chat info failed
	GettingUsersChatInfoFailed = "Getting user's chat info failed ->"
	//CheckingUserDeletedInChatFailed - checking user deleted in chat failed
	CheckingUserDeletedInChatFailed = "Checking user deleted in chat failed ->"
	//GetChatsUsersFailed - getting chat's users failed
	GetChatsUsersFailed = "Getting chat's users failed ->"
)
View Source
const (
	//DialogAlreadyCreated - dialog was already created
	DialogAlreadyCreated = "Dialog already created ->"
	//CreatingChatFailed - chat creating failed
	CreatingChatFailed = "Chat creating failed ->"
	//InsertingDialogFailed - inserting dialog in db failed
	InsertingDialogFailed = "Dialog inserting into db failed ->"
	//GettingDialogFailed - dialog getting failed
	GettingDialogFailed = "Dialog getting failed ->"
	//CheckingDialogExistsFailed - checking dialog exists failed
	CheckingDialogExistsFailed = "Checking dialog exists failed ->"
	//UsersDontHaveDialog - users dont have dialog
	UsersDontHaveDialog = "Users doent have dialog ->"
)
View Source
const (
	//CannotReadRandomBytes - reading reandom bytes failed
	CannotReadRandomBytes = "Reading random bytes failed ->"
	//FileInsertingFailed = inserting file into db failed
	FileInsertingFailed = "Inserting file into db failed ->"
	//CannotFindFile = file not found
	CannotFindFile = "File not found ->"
	//CannotDeleteFile = file deleting failed
	CannotDeleteFile = "File deleting failed ->"
)
View Source
const (
	//MarshalingFailed - marshaling failed
	MarshalingFailed = "Marshaling failed ->"
	//UnmarshalingFailed - unmarshaling failed
	UnmarshalingFailed = "Unmarshaling failed ->"
	//AddingMessageFailed - inserting message failed
	AddingMessageFailed = "Adding message failed ->"
	//CheckingUserInChatFailed - checking user in chat failed
	CheckingUserInChatFailed = "Checking user in chat faile ->"
	//UserDeletedFromChat - user was deleted from chat
	UserDeletedFromChat = "User deleted from chat ->"
	//MessageInsertingFailed - message inserting was failed
	MessageInsertingFailed = "Message insert error ->"
	//GettingFileInfoFailed - cannot get file's info
	GettingFileInfoFailed = "Getting file's information failed ->"
)
View Source
const (
	//UserInsertError - User insertion into DB failed
	UserInsertError = "User insert error ->"
	//UserUpdateError - User updation into DB failed
	UserUpdateError = "User updating failed ->"
	//UserWithThisLoginAlreadyExists - User with this login already exists in DB
	UserWithThisLoginAlreadyExists = "User with this login already exists ->"
	//GetChatInfoError - Getting chat's info failed
	GetChatInfoError = "Getting chat info failed ->"
	//UserNotFound - User with this data doesnt exist
	UserNotFound = "User not found ->"
	//PasswordEncodingFailed - Password encoding failed
	PasswordEncodingFailed = "Pass encoding failed ->"
	//GetMessageError - getting message failed
	GetMessageError = "Getting message failed ->"
	//MessageContentDecodeError - decoding message was failed
	MessageContentDecodeError = "Message's content decoding failed ->"
)

Variables

View Source
var (

	//UserInsertedToChat - is a callback triggered when user requesting in chat(uses for sending notifications by WS)
	UserInsertedToChat userInsertedCallback
	//ChatCreated - is a callback triggered when user creating chat(uses for sending notifications by WS)
	ChatCreated chatCreatedCallback
	// SendUserMessageToSocket - using for sending message
	SendUserMessageToSocket sendUserMessage
	// UserLeaveChat - using as callback after user get banned
	UserLeaveChat userLeaveChatCallback
	// UserReturnToChat - using as callback after user was unbanned
	UserReturnToChat userReturnToChatCallback
)

Functions

func AddMessage

func AddMessage(userID int64, chatID int64, content string, docs []int64,
	mtype models.MessageType, command models.MessageCommand) (int64, error)

AddMessage - handle inserting message into db

func BeginDB

func BeginDB(logger *log.Logger) error

BeginDB - create connection or/and new DB file

func CheckFileRights

func CheckFileRights(userID int64, fileID int64) (string, error)

CheckFileRights - checking if user have rights for getting file (e.g. user is in a chat where file is), return path to file

func CheckUserInChatDeleted

func CheckUserInChatDeleted(userID int64, chatID int64) (bool, error)

CheckUserInChatDeleted - check user delete stat, if users deleted return true, else false

func CheckUserRights

func CheckUserRights(userID int64, chatID int64) error

CheckUserRights - return is user author of the chat (error - no, nil - yes)

func Create

func Create(name string, authorID int64, chattype ChatMode) (int64, error)

Create - creating chat, dialog or channel and auto inserting author in it

func CreateDialog

func CreateDialog(userID int64, yetuserID int64) (int64, error)

CreateDialog - creating dialog between two users

func CreateFile

func CreateFile(name string, size int64, userID int64,
	chatID int64, ratio float64, duration int64) (int64, string, error)

CreateFile - insert file data into db

func CreateUser

func CreateUser(login string, pass string, name string) (int64, error)

CreateUser - creating creating user record in DB by his login, Pass and name pass will be encoding to sha256

func DBE

func DBE(text string, err error) error

func DeleteChatFromList

func DeleteChatFromList(userID int64, chatID int64) error

DeleteChatFromList - delete chat from certain user's menu

func DeleteFile

func DeleteFile(fileID int64, userID int64) (string, error)

DeleteFile - delete file info into db and return path to file

func DeleteUsersInChat

func DeleteUsersInChat(usersIDs []int64, chatID int64, deleteByYourself bool) error

DeleteUsersInChat - delete users from certain chat or ban them(if deleteByYourself = false)

func GetChatSettings

func GetChatSettings(chatID int64) (models.ChatSettings, error)

GetChatSettings - return chat settings by chat's ID

func GetChatUsersInfo

func GetChatUsersInfo(chatID int64) (*[]models.FolkChatsInfo, error)

GetChatUsersInfo - returning user's chat info by certain chat

func GetChatsUsers

func GetChatsUsers(chatID int64) (*[]int64, error)

GetChatsUsers - returning user's ids in the certain chat

func GetMessages

func GetMessages(userID int64, chatID int64, tranches bool, lastID int64) (*[]models.NewMessageToUser, error)

GetMessages - retrun user's messages in certain chat, supporting tranches(pages)

func GetOnlineUsersIDsInChat

func GetOnlineUsersIDsInChat(chatsID *[]int64, usersOnlineID *[]int64) (*[]int64, error)

GetOnlineUsersIDsInChat - return online users IDs in chats by online usesrs slice

func GetUserChats

func GetUserChats(userID int64) (*[]models.UserChatInfo, error)

GetUserChats - return users chats

func GetUserSettings

func GetUserSettings(userID int64) (models.UserSettings, error)

GetUserSettings - return user's settings

func GetUsersChatsIDs

func GetUsersChatsIDs(userID int64) (*[]int64, error)

GetUsersChatsIDs - return user's chats ID

func GetUsersForAddByName

func GetUsersForAddByName(chatID int64, name string) (*[]models.User, error)

GetUsersForAddByName - return users for add to certain chat if yet aren't there

func GetUsersForCreateDialog

func GetUsersForCreateDialog(userID int64, name string) (*[]models.User, error)

GetUsersForCreateDialog - return pointer to users slice for probably starting dialog with supporting of name/login search

func HaveAlreadyDialog

func HaveAlreadyDialog(userID int64, yetuserID int64) (int64, error)

HaveAlreadyDialog - return dialog ID if users have a dialog

func InsertUserInChat

func InsertUserInChat(userID int64, chatID int64, invited bool) error

InsertUserInChat - adding user to chat

func RecoveryUsersInChat

func RecoveryUsersInChat(userIDs []int64, chatID int64, recoveryByYourself bool) error

RecoveryUsersInChat - recovery users for chats if they're was deleted, but not banned

func SetChatSettings

func SetChatSettings(chatID int64, settings models.ChatSettings) error

SetChatSettings - apply settigns for certain chat

func SetUserSettigns

func SetUserSettigns(userID int64, settings models.UserSettings) error

SetUserSettigns - save settings to DB

Types

type Chat

type Chat struct {
	ID       int64
	Name     string `gorm:"size:100"`
	AuthorID int64
	Author   User
	Type     ChatMode `gorm:"DEFAULT:0"`
	Files    []File
	Messages []Message
}

func (*Chat) TableName

func (u *Chat) TableName() string

type ChatMode

type ChatMode int

ChatMode - type for decalring chat's modesChatMode

const (
	//ChatType - chat's type for Create funnction
	ChatType ChatMode = iota
	//DialogType - dialog's type for Create funnction
	DialogType
	//ChannelType - channel's type for Create funnction
	ChannelType
)

func GetChatMode

func GetChatMode(chatID int64) (ChatMode, error)

GetChatMode - returning chat's type

type ChatUser

type ChatUser struct {
	ID            int64
	UserID        int64
	User          User
	ChatID        int64
	Chat          Chat
	Start         int64  `gorm:"DEFAULT:0"`
	DeleteLast    int64  `gorm:"DEFAULT:0"`
	DeletePoints  string `gorm:"size:1024"`
	Ban           bool   `gorm:"DEFAULT:false"`
	ListInvisible bool   `gorm:"DEFAULT:false"`
}

func (*ChatUser) TableName

func (c *ChatUser) TableName() string

type DBError

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

func (*DBError) Error

func (e *DBError) Error() string

func (*DBError) Original

func (e *DBError) Original() error

func (*DBError) Type

func (e *DBError) Type() string

type Dialog

type Dialog struct {
	ID      int64
	ChatID  int64
	User1ID int64
	User1   User
	User2ID int64
	User2   User
}

func (*Dialog) TableName

func (u *Dialog) TableName() string

type File

type File struct {
	ID        int64
	AuthorID  int64
	Author    User
	ChatID    int64
	Chat      Chat
	Name      string
	Path      string
	RatioSize float64 `gorm:"DEFAULT:0"`
	Size      int64   `gorm:"DEFAULT:0"`
	Duration  int64   `gorm:"DEFAULT:0"`
}

func GetFile

func GetFile(fileID int64) (*File, error)

GetFile - return pointer to file

func (*File) TableName

func (u *File) TableName() string

type Message

type Message struct {
	ID       int64
	AuthorID int64
	Author   User
	ChatID   int64
	Chat     Chat
	Content  string `gorm:"size:1024"`
	Time     int64  `gorm:"DEFAULT:0"`
}

func (*Message) TableName

func (u *Message) TableName() string

type System

type System struct {
	ID      int64
	Date    int64 `gorm:"DEFAULT:0"`
	Version string
}

func (*System) TableName

func (u *System) TableName() string

type User

type User struct {
	ID       int64
	Login    string     `gorm:"size:32"`
	Name     string     `gorm:"size:100"`
	Pass     string     `gorm:"size:45"`
	Language string     `gorm:"size:5;DEFAULT:en"`
	Chats    []ChatUser `gorm:"PRELOAD:false"`
	Messages []Message  `gorm:"PRELOAD:false"`
	Files    []File     `gorm:"PRELOAD:false"`
	MyChats  []Chat     `gorm:"PRELOAD:false"`
	Dialogs  []Dialog   `gorm:"PRELOAD:false"`
}

func GetUserByID

func GetUserByID(ID int64) (*User, error)

GetUserByID - getting user by his ID or retrun error

func GetUserByLoginAndPass

func GetUserByLoginAndPass(login string, pass string) (*User, error)

GetUserByLoginAndPass - getting user by his login and pass or return error

func (*User) TableName

func (u *User) TableName() string

Jump to

Keyboard shortcuts

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