model

package
v0.0.0-...-b80ed3d Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountUsers

func CountUsers(u *User) (int, int, error)

CountUsers counts specified type of users

func InitDB

func InitDB(url string) error

InitDB connects to and sets up the database

Types

type Article

type Article struct {
	PostBase
	Content string `json:"content"`
}

Article represents prose posts

func ReadAllArticles

func ReadAllArticles() ([]Article, int, error)

ReadAllArticles fetches all Articles

func (*Article) Create

func (a *Article) Create() (int, error)

Create makes an Article

func (*Article) Delete

func (a *Article) Delete() (int, error)

Delete removes an Article

func (*Article) Publish

func (a *Article) Publish() (int, error)

Publish makes an Article public

func (*Article) Read

func (a *Article) Read() (int, error)

Read fetches an Article

func (*Article) Retract

func (a *Article) Retract() (int, error)

Retract makes an Article private

func (*Article) Update

func (a *Article) Update() (int, error)

Update edits an Article

type Base

type Base struct {
	ID        uuid.UUID  `gorm:"type:uuid;primary_key;"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `sql:"index" json:"deleted_at"`
}

Base contains common columns for all tables.

func (*Base) BeforeCreate

func (base *Base) BeforeCreate(scope *gorm.Scope) error

BeforeCreate will set a UUID rather than numeric ID.

type Flicker

type Flicker struct {
	PostBase
	Content string `json:"content"`
	Caption string `json:"caption"`
}

Flicker represents video posts

func ReadAllFlickers

func ReadAllFlickers() ([]Flicker, int, error)

ReadAllFlickers fetches all Flickers

func (*Flicker) Create

func (f *Flicker) Create() (int, error)

Create makes a Flicker

func (*Flicker) Delete

func (f *Flicker) Delete() (int, error)

Delete removes a Flicker

func (*Flicker) Publish

func (f *Flicker) Publish() (int, error)

Publish makes a Flicker public

func (*Flicker) Read

func (f *Flicker) Read() (int, error)

Read fetches a Flicker

func (*Flicker) Retract

func (f *Flicker) Retract() (int, error)

Retract makes makes a Flicker private

func (*Flicker) Update

func (f *Flicker) Update() (int, error)

Update edits a Flicker

type Gallery struct {
	PostBase
	Content pq.StringArray `json:"content" gorm:"type:varchar(255)[]"`
	Caption pq.StringArray `json:"caption" gorm:"type:varchar(255)[]"`
}

Gallery represents image posts

func ReadAllGalleries

func ReadAllGalleries() ([]Gallery, int, error)

ReadAllGalleries fetches all Galleries

func (*Gallery) Create

func (g *Gallery) Create() (int, error)

Create makes a Gallery

func (*Gallery) Delete

func (g *Gallery) Delete() (int, error)

Delete removes a Gallery

func (*Gallery) Publish

func (g *Gallery) Publish() (int, error)

Publish makes a Gallery public

func (*Gallery) Read

func (g *Gallery) Read() (int, error)

Read fetches a Gallery

func (*Gallery) Retract

func (g *Gallery) Retract() (int, error)

Retract makes makes a Gallery private

func (*Gallery) Update

func (g *Gallery) Update() (int, error)

Update edits a Gallery

type Post

type Post interface {
	// Read fetches a Post
	Read() (int, error)
	// Delete removes a Post
	Delete() (int, error)
	// Publish makes a Post public
	Publish() (int, error)
	// Retract makes a Post private
	Retract() (int, error)
}

Post represents all post types

func GetPost

func GetPost(id uuid.UUID) (Post, int, error)

GetPost finds a Post across Post models.

type PostBase

type PostBase struct {
	Base
	Subject   string         `json:"subject"`
	Summary   string         `json:"summary"`
	Overlay   string         `json:"overlay"`
	Section   string         `json:"section"`
	Summons   int            `json:"summons"`
	Release   bool           `json:"release"`
	Pattern   postPattern    `json:"pattern"`
	Creator   uuid.UUID      `json:"creator" gorm:"type:uuid"`
	Markers   pq.StringArray `json:"markers" gorm:"type:varchar(255)[]"`
	Reactions []Reaction     `json:"reactions,omitempty" sql:"-" gorm:"foreignkey:Post"`
}

PostBase is the underlying object for all post types

type Reaction

type Reaction struct {
	Base
	Type ReactionType `json:"type"`
	User uuid.UUID    `gorm:"type:uuid" json:"user"`
	Item uuid.UUID    `gorm:"type:uuid" json:"item"`
	Site string       `json:"site"`
	Text string       `json:"text"`
}

Reaction represents a User action on a Post

func ReadAllReactions

func ReadAllReactions() ([]Reaction, int, error)

ReadAllReactions fetches all Reactions

func (*Reaction) Create

func (r *Reaction) Create() (int, error)

Create makes new reactions

func (*Reaction) Delete

func (r *Reaction) Delete() (int, error)

Delete removes existing reactions

func (*Reaction) Read

func (r *Reaction) Read() (int, error)

Read returns an existing reaction

func (*Reaction) Update

func (r *Reaction) Update() (int, error)

Update edits reaction text

type ReactionType

type ReactionType string

ReactionType represents a user action on a post.

const (
	ReactionApprove ReactionType = "approve"
	ReactionSticker ReactionType = "sticker"
	ReactionComment ReactionType = "comment"
)

ReactionTypes represent available user actions on posts.

type User

type User struct {
	Base
	Name      string     `json:"name"`
	Mail      string     `json:"mail"`
	Pass      string     `json:"pass"`
	Auth      string     `json:"auth"`
	Life      string     `json:"life"`
	Role      UserRole   `json:"role"`
	Posts     []Post     `json:"posts,omitempty" sql:"-" gorm:"foreignkey:Creator"`
	Reactions []Reaction `json:"reactions,omitempty" sql:"-" gorm:"foreignkey:User"`
}

User is a registered user TODO User status

func ReadAllUsers

func ReadAllUsers() ([]User, int, error)

ReadAllUsers fetches all Users

func (*User) Create

func (u *User) Create() (int, error)

Create makes a User First user is automatically promoted to "UserKeeper" role

func (*User) Delete

func (u *User) Delete() (int, error)

Delete removes a User

func (*User) Read

func (u *User) Read() (int, error)

Read fetches a User

func (*User) TryAuth

func (u *User) TryAuth() (int, error)

TryAuth checks user credentials

func (*User) Update

func (u *User) Update() (int, error)

Update edits a User

func (*User) ValidateAuth

func (u *User) ValidateAuth() (int, error)

ValidateAuth checks user details format

type UserRole

type UserRole string

UserRole represents a user rank

const (
	UserReader UserRole = "reader"
	UserEditor UserRole = "editor"
	UserKeeper UserRole = "keeper"
)

UserRoles represent various user ranks

Jump to

Keyboard shortcuts

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