Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Models = []interface{}{ &User{}, &Connection{}, &Session{}, &Post{}, &Like{}, }
Models is a slice of all the models in the application.
Functions ¶
This section is empty.
Types ¶
type BaseModel ¶
type BaseModel struct {
ID string `gorm:"primaryKey" json:"id"` // ID is the primary key.
Timestamps // Timestamps for creation and update.
}
BaseModel defines the basic structure for database models.
type Connection ¶
type Connection struct {
BaseModel
// Email connection fields
Password string `gorm:"size:512" json:"-"` // Password for the connection, only used for emails.
Verified bool `gorm:"default:false" json:"verified"` // Whether the connection is verified, only used for emails.
TOTPVerify string `gorm:"size:512" json:"-"` // Time-based One-Time Password for verification of the email address
// User owner of the connection
UserID string `gorm:"not null" json:"-"`
User *User `gorm:"foreignKey:UserID;references:ID;constraint:OnDelete:CASCADE" json:"user,omitempty"`
// Sessions related to the connection
Sessions []Session `gorm:"foreignKey:ConnectionID;references:ID;constraint:OnDelete:CASCADE" json:"sessions,omitempty"`
}
Connection represents an authentication connection, such as an email or an oauth connection.
func (*Connection) Type ¶
func (c *Connection) Type() ConnectionType
func (*Connection) TypeID ¶
func (c *Connection) TypeID() ConnectionType
type ConnectionType ¶
type ConnectionType string
ConnectionType represents the type of connection.
const (
ProviderEmailType ConnectionType = "email"
)
func (ConnectionType) WithID ¶
func (c ConnectionType) WithID(id string) string
type Follow ¶
type Follow struct {
BaseModel
// Follower and Following are the users involved in the follow relationship.
FollowerID string `gorm:"not null" json:"follower_id"`
Follower *User `gorm:"foreignKey:FollowerID;references:ID;constraint:OnDelete:CASCADE" json:"follower,omitempty"`
FollowingID string `gorm:"not null" json:"following_id"`
Following *User `gorm:"foreignKey:FollowingID;references:ID;constraint:OnDelete:CASCADE" json:"following,omitempty"`
}
Follow represents a follow relationship between two users.
type Like ¶
type Like struct {
BaseModel
// Author of the post
LikedByID string `gorm:"not null" json:"liked_by_id"`
LikedBy *User `gorm:"foreignKey:LikedByID;references:ID;constraint:OnDelete:CASCADE" json:"liked_by,omitempty"`
PostID string `gorm:"not null" json:"post_id"`
Post *Post `gorm:"foreignKey:PostID;references:ID;constraint:OnDelete:CASCADE" json:"post,omitempty"`
}
type Post ¶
type Post struct {
BaseModel
// Author of the post
AuthorID string `gorm:"not null" json:"author_id"`
Author *User `gorm:"foreignKey:AuthorID;references:ID;constraint:OnDelete:CASCADE" json:"author,omitempty"`
Content string `gorm:"size:512" json:"content"`
// Relations
Likes []Like `gorm:"foreignKey:PostID;references:ID;constraint:OnDelete:CASCADE" json:"likes,omitempty"`
// -- Replies
// Parent is only used when a post is a reply to another post.
ParentID *string `gorm:"null" json:"parent_id,omitempty"` // Parent is only used when a post is a reply to another post, therefore it is nullable and optional
Parent *Post `gorm:"foreignKey:ParentID;references:ID;constraint:OnDelete:CASCADE" json:"parent,omitempty"`
// delete all replies when a post is deleted
Replies []Post `gorm:"foreignKey:ParentID;references:ID;constraint:OnDelete:CASCADE" json:"replies,omitempty"` // delete all replies when a post is deleted
}
Post represents a post made by a user.
type Session ¶
type Session struct {
BaseModel
ConnectionID string `gorm:"not null" json:"-"`
Connection *Connection `gorm:"foreignKey:ConnectionID;references:ID;constraint:OnDelete:CASCADE" json:"connection,omitempty"`
ExpiresAt time.Time `gorm:"not null" json:"expires_at"`
}
Session represents an authenticated session related to a connection.
type Timestamps ¶
type Timestamps struct {
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"` // Time of creation.
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"` // Time of update.
}
Timestamps holds creation and update times.
func (*Timestamps) BeforeCreate ¶
func (t *Timestamps) BeforeCreate(tx *gorm.DB) error
BeforeCreate sets timestamps before creating a record.
type User ¶
type User struct {
BaseModel
Username string `gorm:"size:64;not null;unique" json:"username"`
DisplayName string `gorm:"size:512" json:"display_name"`
Email string `gorm:"size:255;unique;not null" json:"email,omitempty"` // Ommitted for security reasons
Connections []Connection `gorm:"foreignKey:UserID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"connections,omitempty"`
Posts []Post `gorm:"foreignKey:AuthorID;references:ID;constraint:OnDelete:CASCADE" json:"posts,omitempty"`
Likes []Like `gorm:"foreignKey:LikedByID;references:ID;constraint:OnDelete:CASCADE" json:"likes,omitempty"`
Followers []Follow `gorm:"foreignKey:FollowingID;references:ID;constraint:OnDelete:CASCADE" json:"followers,omitempty"`
Following []Follow `gorm:"foreignKey:FollowerID;references:ID;constraint:OnDelete:CASCADE" json:"following,omitempty"`
}
Click to show internal directories.
Click to hide internal directories.