models

package
v0.0.0-...-78c831c Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const MessageWithSequenceNumberViewName = "messages_sequence_numbers"

MessageWithSequenceNumberViewName is the name of the view that represents all messages with their corresponding sequence number.

View Source
const MessageWithSequenceNumberViewQuery = `` /* 138-byte string literal not displayed */

MessageWithSequenceNumberViewQuery query that selects this view.

Variables

This section is empty.

Functions

func HashPassword

func HashPassword(plaintextPassword string) (string, error)

HashPassword hashes a password.

Types

type FindMessagesParameters

type FindMessagesParameters struct {

	// SequenceSet is a list of sequences with sequence numbers.
	SequenceSet []Sequence

	// UIDSet is a list of sequences with uids.
	UIDSet []Sequence

	// OmitBody excludes the email body in the message if set to true.
	OmitBody bool
}

FindMessagesParameters are optional parameters that can be used to get/find messages.

type Mailbox

type Mailbox struct {
	gorm.Model

	ID uint `gorm:"primary_key;auto_increment;not_null"`

	Subscribed bool

	Name   string `gorm:"index:idx_mailbox_user,unique"`
	UserID uint   `gorm:"index:idx_mailbox_user,unique;foreignKey:User"`
	User   *User
}

Mailbox represent a mailbox.

type MailboxRepository

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

MailboxRepository implements the Mailbox repository

func NewMailboxRepository

func NewMailboxRepository(db *gorm.DB) (*MailboxRepository, error)

NewMailboxRepository creates a new MailboxRepository

func (*MailboxRepository) CreateMailbox

func (r *MailboxRepository) CreateMailbox(mailbox *Mailbox) error

CreateMailbox creates a new mailbox in the database.

func (*MailboxRepository) DeleteMailbox

func (r *MailboxRepository) DeleteMailbox(id uint) error

DeleteMailbox deletes a mailbox from the database by its ID.

func (*MailboxRepository) DeleteMailboxByUserIDAndMailboxName

func (r *MailboxRepository) DeleteMailboxByUserIDAndMailboxName(userID uint, mailboxName string) error

DeleteMailboxByUserIDAndMailboxName deletes a mailbox from the database by user ID and mailbox name.

func (*MailboxRepository) FindMailboxesByUserID

func (r *MailboxRepository) FindMailboxesByUserID(userID uint) ([]*Mailbox, error)

FindMailboxesByUserID finds mailboxes in the database by their user ID.

func (*MailboxRepository) GetMailBoxByUserIDAndMailboxName

func (r *MailboxRepository) GetMailBoxByUserIDAndMailboxName(userID uint, mailboxName string) (*Mailbox, error)

GetMailBoxByUserIDAndMailboxName retrieves a mailbox from the database by user ID and mailbox name.

func (*MailboxRepository) GetMailboxByID

func (r *MailboxRepository) GetMailboxByID(id uint) (*Mailbox, error)

GetMailboxByID retrieves a mailbox from the database by its ID.

func (*MailboxRepository) UpdateMailbox

func (r *MailboxRepository) UpdateMailbox(mailbox *Mailbox) error

UpdateMailbox updates an existing mailbox in the database.

type Message

type Message struct {
	gorm.Model

	ID    uint `gorm:"primary_key;auto_increment;not_null"`
	Date  time.Time
	Size  uint32
	Flags StringSlice
	Body  []byte

	MailboxID uint `gorm:"foreignKey:Mailbox"`

	SequenceNumber uint `gorm:"->;-:migration"` // read only and skip in migrations because its the column from a view.
}

Message represents an email message.

type MessageRepository

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

MessageRepository implements the Message repository

func NewMessageRepository

func NewMessageRepository(db *gorm.DB) (*MessageRepository, error)

NewMessageRepository creates a new MessageRepository

func (*MessageRepository) CreateMessage

func (r *MessageRepository) CreateMessage(message *Message) error

CreateMessage creates a new message in the database.

func (*MessageRepository) DeleteMessageByID

func (r *MessageRepository) DeleteMessageByID(id uint) error

DeleteMessageByID deletes a message from the database by its ID.

func (*MessageRepository) FindMessagesByMailboxID

func (r *MessageRepository) FindMessagesByMailboxID(mailboxID uint, parameters FindMessagesParameters) ([]*Message, error)

FindMessagesByMailboxID finds messages in the database by their mailbox ID.

func (*MessageRepository) GetMessageByID

func (r *MessageRepository) GetMessageByID(id uint) (*Message, error)

GetMessageByID retrieves a message from the database by its ID.

func (*MessageRepository) GetNextMessageID

func (r *MessageRepository) GetNextMessageID(mailboxID uint) (uint, error)

GetNextMessageID gets the next available message id.

func (*MessageRepository) GetNumberOfMessagesByMailboxID

func (r *MessageRepository) GetNumberOfMessagesByMailboxID(mailboxID uint) (uint, error)

GetNumberOfMessagesByMailboxID counts the number of messages in the given mailbox.

func (*MessageRepository) GetTotalMessagesCount

func (r *MessageRepository) GetTotalMessagesCount() (int64, error)

GetTotalMessagesCount returns the total number of messages in the database.

func (*MessageRepository) UpdateMessage

func (r *MessageRepository) UpdateMessage(message *Message) error

UpdateMessage updates an existing message in the database.

type Sequence

type Sequence struct {
	// Start denotes the beginning of the range (inclusive)
	Start int
	// Stop denotes the end of the range (inclusive)
	Stop int
}

Sequence represents a sequence of messages going from Start to Stop.

type StringSlice

type StringSlice []string

func (*StringSlice) Scan

func (ss *StringSlice) Scan(src interface{}) error

func (StringSlice) Value

func (ss StringSlice) Value() (driver.Value, error)

type User

type User struct {
	gorm.Model

	ID       uint   `gorm:"primary_key;auto_increment;not_null"`
	Username string `gorm:"unique;not_null"`
	Password string `gorm:"not_null" json:"-"`
	Email    string `gorm:"unique;not_null"`
}

User represents an email user.

func NewUser

func NewUser(username string, plaintextPassword string, email string) (*User, error)

NewUser creates a new user and hashes the plaintext password.

func (*User) CheckPassword

func (u *User) CheckPassword(plaintextPassword string) (bool, error)

CheckPassword validates if the given password matches the hashed password for the user.

type UserRepository

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

UserRepository implements the User repository

func NewUserRepository

func NewUserRepository(db *gorm.DB) (*UserRepository, error)

NewUserRepository creates a new UserRepository

func (*UserRepository) CreateUser

func (r *UserRepository) CreateUser(user *User) error

CreateUser creates a new user in the database.

func (*UserRepository) DeleteUser

func (r *UserRepository) DeleteUser(id uint) error

DeleteUser deletes a user from the database by their ID.

func (*UserRepository) FindUserByEmail

func (r *UserRepository) FindUserByEmail(email string) (*User, error)

FindUserByEmail finds a user in the database by their email address.

func (*UserRepository) GetAllUsers

func (r *UserRepository) GetAllUsers() ([]*User, error)

GetAllUsers retrieves all users from the database.

func (*UserRepository) GetTotalUsersCount

func (r *UserRepository) GetTotalUsersCount() (int64, error)

GetTotalUsersCount returns the total number of users in the database.

func (*UserRepository) GetUserByID

func (r *UserRepository) GetUserByID(id uint) (*User, error)

GetUserByID retrieves a user from the database by their ID.

func (*UserRepository) UpdateUser

func (r *UserRepository) UpdateUser(user *User) error

UpdateUser updates an existing user in the database.

Jump to

Keyboard shortcuts

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