model

package
v0.0.0-...-af7b3a9 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPasswordTooLong                      = errors.New("password too long")
	ErrPasswordContainsUnsuportedCharacters = errors.New("password contains unsuported characters")
	ErrInvalidUsername                      = errors.New("invalid username")
	AUTH_BASE_USER                          = Authority{AuthName: "User", Level: 0}
	AUTH_MODERATOR                          = Authority{AuthName: "Moderator", Level: 1}
	AUTH_ADMIN                              = Authority{AuthName: "Admin", Level: 255}
)

Functions

This section is empty.

Types

type Article

type Article struct {
	BasePost
	Votes   []Vote `gorm:"many2many:article_votes;"`
	Content string
}

func (*Article) AfterCreate

func (a *Article) AfterCreate(tx *gorm.DB) error

AfterCreate is a hook that creates a post after creating an article It helps indexing posts arbitrarily

func (*Article) AfterSave

func (a *Article) AfterSave(tx *gorm.DB) error

func (*Article) BeforeDelete

func (a *Article) BeforeDelete(tx *gorm.DB) error

func (Article) GetVotes

func (a Article) GetVotes() []Vote

type Authority

type Authority struct {
	AuthName string
	Level    uint8
}

type BasePost

type BasePost struct {
	ID        uint64
	Title     string
	Author    string
	User      User `gorm:"foreignKey:Author;references:Username"`
	Published bool
	CreatedAt time.Time
	UpdatedAt time.Time
}

func (BasePost) GetAuthor

func (p BasePost) GetAuthor() string

func (BasePost) GetCreatedAt

func (p BasePost) GetCreatedAt() time.Time

func (BasePost) GetID

func (p BasePost) GetID() uint64

func (BasePost) GetTitle

func (p BasePost) GetTitle() string

func (BasePost) GetUpdatedAt

func (p BasePost) GetUpdatedAt() time.Time

type FollowList

type FollowList struct {
	ID        uint64
	Owner     string `gorm:"unique"`
	Following []User `gorm:"many2many:follows;foreignKey:Owner;joinForeignKey:Owner;joinReferences:Username;references:Username"`
}
type Gallery struct {
	BasePost
	Votes  []Vote `gorm:"many2many:gallery_votes;"`
	Images []Image
}

func (*Gallery) AfterCreate

func (g *Gallery) AfterCreate(tx *gorm.DB) error

func (*Gallery) AfterSave

func (g *Gallery) AfterSave(tx *gorm.DB) error

func (*Gallery) BeforeDelete

func (g *Gallery) BeforeDelete(tx *gorm.DB) error

func (Gallery) GetVotes

func (g Gallery) GetVotes() []Vote

type Image

type Image struct {
	ID        uint64
	Owner     string
	User      User `gorm:"foreignKey:Owner;references:Username"`
	Footer    string
	ImageURL  string
	ThumbURL  string
	DeleteURL string
	GalleryID uint64
	Gallery   Gallery
}

type Password

type Password struct {
	HashedPassword string
	UpdatedAt      time.Time
}

func (*Password) ComparePassword

func (p *Password) ComparePassword(password string) bool

func (*Password) SetPasswordAsHash

func (p *Password) SetPasswordAsHash(password string) error

func (*Password) ValidateAndSetPassword

func (p *Password) ValidateAndSetPassword(password string) error

type Post

type Post struct {
	BasePost
	Votes     []Vote `gorm:"many2many:post_votes;"`
	OwnerID   uint64
	OwnerType string
}

func (*Post) AfterCreate

func (p *Post) AfterCreate(tx *gorm.DB) error

func (Post) GetVotes

func (p Post) GetVotes() []Vote

type Postable

type Postable interface {
	GetID() uint64
	GetTitle() string
	GetAuthor() string
	GetCreatedAt() time.Time
	GetUpdatedAt() time.Time
	GetVotes() []Vote
}

Postable is an interface that all posts must implement It allows to easily index posts in a single slice

type Profile

type Profile struct {
	Bio          string
	PfPUrl       string
	PfPDeleteUrl string
}

type Project

type Project struct {
	BasePost
	Description string
	Votes       []Vote `gorm:"many2many:project_votes;"`
	Link        string
}

func (*Project) AfterCreate

func (p *Project) AfterCreate(tx *gorm.DB) error

func (*Project) AfterSave

func (p *Project) AfterSave(tx *gorm.DB) error

func (*Project) BeforeDelete

func (p *Project) BeforeDelete(tx *gorm.DB) error

func (Project) GetVotes

func (p Project) GetVotes() []Vote

type Report

type Report struct {
	ID          uint64
	Description string
	CreatedAt   time.Time
}

type Section

type Section struct {
	ID    uint64
	Name  string
	Owner string
	User  User   `gorm:"foreignKey:Owner;references:Username"`
	Posts []Post `gorm:"many2many:section_posts;"`
}

type Tag

type Tag struct {
	ID   uint64
	Name string `gorm:"unique"`
}

func (*Tag) ColorOfTag

func (t *Tag) ColorOfTag() string

type User

type User struct {
	ID         uint64
	Username   string   `gorm:"unique"`
	Password   Password `gorm:"embedded"`
	Profile    Profile  `gorm:"embedded"`
	Email      string
	CreatedAt  time.Time
	UpdatedAt  time.Time
	FullName   string
	FollowList FollowList `gorm:"foreignKey:Owner;references:Username"`
	Active     bool       `gorm:"default:true"`
	Authority
}

func NewUser

func NewUser() User

func (*User) ValidateAndSetUsername

func (u *User) ValidateAndSetUsername(username string) error

type Vote

type Vote struct {
	ID    uint64
	Voter string
	User  User `gorm:"foreignKey:Voter;references:Username"`
	TagID uint64
	Tag   Tag `gorm:"foreignKey:TagID;references:ID"`
}

A user can vote for a specific tag on a post

Jump to

Keyboard shortcuts

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