models

package
v0.0.0-...-66f4895 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

Functions

func AddParticipantsWithUsernamesToGroup

func AddParticipantsWithUsernamesToGroup(groupID uint, usernames []string) error

func AddUserToGroup

func AddUserToGroup(userID uint, groupID uint) error

func CheckCommonMembershipForTwoUsers

func CheckCommonMembershipForTwoUsers(user1ID uint, user2ID uint) (*[]uint, error)

func CheckMembership

func CheckMembership(userID uint, groupID uint) (bool, error)

func ConnectDatabase

func ConnectDatabase()

func DeleteUnreadMessagesForUser

func DeleteUnreadMessagesForUser(userID uint) error

func DeleteUnsentAcknowledgementsForUser

func DeleteUnsentAcknowledgementsForUser(userID uint) error

func GetGroupParticipants

func GetGroupParticipants(groupID uint) (*[]uint, error)

func GetGroupParticipantsExceptUser

func GetGroupParticipantsExceptUser(groupID uint, userID uint) (*[]uint, error)

func GetGroupsForTwoUsers

func GetGroupsForTwoUsers(user1ID uint, user2ID uint) (*[]Group, error)

func GetGroupsForUser

func GetGroupsForUser(userID uint) (*[]Group, error)

func GetMembershipsForUser

func GetMembershipsForUser(userID uint) (*[]uint, error)

func GetUnreadMessagesForUser

func GetUnreadMessagesForUser(userID uint) (*[]UnsentMessage, error)

func GetUnsentAcknowledgementsForUser

func GetUnsentAcknowledgementsForUser(userID uint) (*[]UnsentAcknowledgement, error)

func GetUsersForGroup

func GetUsersForGroup(groupID uint) (*[]User, error)

func RemoveUserFromGroup

func RemoveUserFromGroup(userID uint, groupID uint) error

func UpdateUserWebsocket

func UpdateUserWebsocket(user *User, ws *websocket.Conn) error

func UserFieldIsEmail

func UserFieldIsEmail(emailOrUsername string) bool

func UsernameOrEmailExists

func UsernameOrEmailExists(user *UserSignUp) (bool, error)

Types

type Acknowledgement

type Acknowledgement struct {
	MessageID  uint    `json:"message_id"`
	ReceiverID uint    `json:"receiver_id"`
	GroupID    uint    `json:"group_id"`
	Status     Receipt `json:"status"`
}

type ClientMessage

type ClientMessage struct {
	Content        string `json:"content"`
	MessageID      uint   `json:"message_id"`
	SenderUsername string `json:"sender_username"`
	Type           Type   `json:"type"`
	GroupID        uint   `json:"group_id"`
}

type CreateGroup

type CreateGroup struct {
	Name      string   `json:"name"`
	OwnerID   uint     `json:"owner_id"`
	Usernames []string `json:"usernames"`
}

type Group

type Group struct {
	ID          uint      `json:"id" gorm:"primary_key"`
	Name        string    `json:"name"`
	Description string    `json:"description"`
	OwnerID     uint      `json:"owner_id"`
	CreatedAt   time.Time `json:"created_at"`
}

func (*Group) CreateGroup

func (group *Group) CreateGroup() error

func (*Group) GetGroup

func (group *Group) GetGroup() (err error)

type Membership

type Membership struct {
	UserID  uint `json:"user_id"`
	GroupID uint `json:"group_id"`
}

func (*Membership) CreateMembership

func (membership *Membership) CreateMembership() (err error)

func (*Membership) DeleteMembership

func (membership *Membership) DeleteMembership() (err error)

type Message

type Message struct {
	Content        string `json:"content"`
	MessageID      uint   `json:"message_id"`
	SenderID       uint   `json:"sender_id"`
	SenderUsername string `json:"sender_username"`
	RecipientID    uint   `json:"recipient_id"`
	Type           Type   `json:"type"`
	CreatedAt      string `json:"created_at"`
	GroupID        uint   `json:"group_id"`
}

type Receipt

type Receipt int
const (
	SENT Receipt = iota
	RECEIVED
	READ
	ERROR
)

type Status

type Status struct {
	Activity   StatusType `json:"activity_id"`
	ReceiverID uint       `json:"receiver_id"`
	GroupID    uint       `json:"group_id"`
	SenderID   uint       `json:"sender_id"`
}

type StatusType

type StatusType int
const (
	ONLINE StatusType = iota
	TYPING
	THINKING
	OFFLINE
)

type Type

type Type int
const (
	PRIVATE Type = iota
	GROUP
)

type UnsentAcknowledgement

type UnsentAcknowledgement struct {
	MessageID       uint    `json:"message_id"`
	ReceiverID      uint    `json:"receiver_id"`
	GroupID         uint    `json:"group_id"`
	Status          Receipt `json:"status"`
	MessageSenderID uint    `json:"message_sender_id"`
}

func (*UnsentAcknowledgement) CreateUnsentAcknowledgement

func (unsentAcknowledgement *UnsentAcknowledgement) CreateUnsentAcknowledgement() (err error)

type UnsentMessage

type UnsentMessage struct {
	Content        string `json:"content"`
	MessageID      uint   `json:"message_id"`
	SenderID       uint   `json:"sender_id"`
	SenderUsername string `json:"sender_username"`
	RecipientID    uint   `json:"recipient_id"`
	Type           Type   `json:"type"`
	GroupID        uint   `json:"group_id"`
}

func (*UnsentMessage) CreateUnsentMessage

func (unsentMessage *UnsentMessage) CreateUnsentMessage() (err error)

type UpdateAbout

type UpdateAbout struct {
	ID    uint   `json:"id"`
	About string `json:"about"`
}

type UpdateGroupDescription

type UpdateGroupDescription struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

type UpdateProfilePicture

type UpdateProfilePicture struct {
	ID             uint   `json:"id"`
	ProfilePicture string `json:"profile_picture"`
}

type User

type User struct {
	ID             uint   `json:"id" gorm:"primary_key"`
	Username       string `json:"username" gorm:"unique_index;not null"`
	Email          string `json:"email" gorm:"unique_index;not null"`
	Password       string `json:"password" gorm:"not null"`
	About          string `json:"about"`
	ProfilePicture string `json:"profile_picture"`
}

func GetUser

func GetUser(id uint) (*User, error)

func GetUserByEmail

func GetUserByEmail(email string) (*User, error)

func GetUserByUsername

func GetUserByUsername(username string) (*User, error)

func (*User) CreateUser

func (user *User) CreateUser() (err error)

func (*User) DeleteUser

func (user *User) DeleteUser() (err error)

func (*User) UpdateUser

func (user *User) UpdateUser(updateUser *User) (err error)

type UserLogin

type UserLogin struct {
	UserField string `json:"user_field"`
	Password  string `json:"password"`
}

type UserSignUp

type UserSignUp struct {
	Username        string `json:"username"`
	Email           string `json:"email"`
	Password        string `json:"password"`
	ConfirmPassword string `json:"confirm_password"`
}

Jump to

Keyboard shortcuts

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