structs

package
v0.0.0-...-7b0100a Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2021 License: MIT Imports: 7 Imported by: 0

README

Models

This folder should hold all Beubo structs

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatePage

func CreatePage(db *gorm.DB, title string, slug string, tags []Tag, template string, content string, siteID int) bool

CreatePage is a method which creates a page using gorm

func CreateRole

func CreateRole(db *gorm.DB, name string) bool

CreateRole is a method which creates a role using gorm

func CreateSetting

func CreateSetting(db *gorm.DB, key string, value string) bool

CreateSetting is a method which creates a setting using gorm

func CreateUser

func CreateUser(db *gorm.DB, email string, password string, roles []*Role, sites []*Site) bool

CreateUser is a method which creates a user using gorm

func UpdatePage

func UpdatePage(db *gorm.DB, id int, title string, slug string, tags []Tag, template string, content string, siteID int) bool

UpdatePage is a method which updates a page in the database with relevant data

func UpdateRole

func UpdateRole(db *gorm.DB, id int, name string, features []*Feature) bool

UpdateRole updates the role struct with the provided details

func UpdateSetting

func UpdateSetting(db *gorm.DB, id int, key string, value string) bool

UpdateSetting updates a setting key value pair using gorm

func UpdateSite

func UpdateSite(db *gorm.DB, id int, title string, domain string, siteType int, themeID int, destinationDomain string) bool

UpdateSite is a method which updates a site using gorm

func UpdateUser

func UpdateUser(db *gorm.DB, id int, email string, password string, roles []*Role, sites []*Site) bool

UpdateUser updates the user struct with the provided details

Types

type Comment

type Comment struct {
	gorm.Model
	User    User
	UserID  int
	Email   string
	Website string
	Text    string
	Page    Page
	PageID  int
}

Comment can be related to a post created by a user

type Config

type Config struct {
	gorm.Model
	Key   string `gorm:"size:255;unique_index"`
	Value string `sql:"type:text"`
}

Config is a key value store for various settings and configurations

type Feature

type Feature struct {
	gorm.Model
	Key   string  `gorm:"size:255"`
	Roles []*Role `gorm:"many2many:role_features;"`
}

Feature contains a key referencing features in the application

type JSONTag

type JSONTag struct {
	Value string `json:"value"`
}

JSONTag is used for responses where tags are shown TODO is this redundant if we can use Tag?

type Page

type Page struct {
	gorm.Model
	Title       string `gorm:"size:255"`
	Content     string `sql:"type:text"`
	Description string `sql:"type:text"`
	Excerpt     string `sql:"type:text"`
	Slug        string `gorm:"size:255;unique_index:idx_slug_site_id"`
	Template    string `gorm:"size:255"`
	Site        Site
	SiteID      int   `gorm:"unique_index:idx_slug_site_id"`
	Tags        []Tag `gorm:"many2many:page_tags;"`
}

Page represents the content of a page, I wanted to go with the concept of having everything be a post even if it's a page, contact form or product

func DeletePage

func DeletePage(db *gorm.DB, id int) Page

DeletePage deletes a page with the provided id from the database

func FetchPage

func FetchPage(db *gorm.DB, id int) Page

FetchPage gets a page based on the provided id from the database

func FetchPageBySiteIDAndSlug

func FetchPageBySiteIDAndSlug(db *gorm.DB, SiteID int, slug string) Page

FetchPageBySiteIDAndSlug gets a page based on the site id and slug from the database

type PageData

type PageData struct {
	Theme       string
	Template    string
	Templates   map[string]string
	Themes      map[string]string
	Title       string
	WebsiteName string
	URL         string
	Error       string
	Warning     string
	Message     string
	Year        string
	Stylesheets []string
	Scripts     []string
	Favicon     string
	Extra       interface{}
	Components  []page.Component
	Menus       []page.Menu
}

PageData is a general structure that holds all data that can be displayed on a page using go html templates

func (PageData) Content

func (pd PageData) Content(section string) template.HTML

Content renders components for a page for the specified section

func (PageData) Menu

func (pd PageData) Menu(section string) template.HTML

Menu renders a menu for the provided section

type Role

type Role struct {
	gorm.Model
	Name     string     `gorm:"size:255"`
	Users    []*User    `gorm:"many2many:user_roles;"`
	Features []*Feature `gorm:"many2many:role_features;"`
}

Role has one or more users and one or more features. A user belonging to a role which also has a feature will allow that user to use the feature

func DeleteRole

func DeleteRole(db *gorm.DB, id int) (role Role)

DeleteRole deletes a user by id

func FetchRole

func FetchRole(db *gorm.DB, id int) Role

FetchRole retrieves a role from the database using the provided id

func FetchRoleByName

func FetchRoleByName(db *gorm.DB, name string) Role

FetchRoleByName retrieves a role from the database using the provided name

func (Role) HasFeature

func (r Role) HasFeature(db *gorm.DB, f Feature) bool

HasFeature checks if a role has the specified feature

func (Role) IsDefault

func (r Role) IsDefault() bool

IsDefault checks if the role is a default role TODO find a better way to handle default roles

type Session

type Session struct {
	gorm.Model
	Token  string `gorm:"size:255;unique_index"`
	UserID int
	User   User
}

Session represents an authenticated user session, there can be multiple sessions for one user

func CreateSession

func CreateSession(db *gorm.DB, userID int) Session

CreateSession is a method which creates a session using gorm

type Setting

type Setting struct {
	gorm.Model
	Key   string `gorm:"size:255"`
	Value string `gorm:"size:255"`
}

Setting represents a key value setting for Beubo usually used for global config values

func DeleteSetting

func DeleteSetting(db *gorm.DB, id int) Setting

DeleteSetting removes a setting with the matching id from the database

func FetchSetting

func FetchSetting(db *gorm.DB, id int) Setting

FetchSetting gets a setting from the database via the provided id

func FetchSettingByKey

func FetchSettingByKey(db *gorm.DB, key string) Setting

FetchSettingByKey gets a setting from the database via the provided key

func FetchSettings

func FetchSettings(db *gorm.DB) (settings []Setting)

FetchSettings gets all settings from the database

type Site

type Site struct {
	gorm.Model
	Title             string `gorm:"size:255"`
	Domain            string `gorm:"size:255;unique_index"`
	DestinationDomain string
	Type              int
	Theme             Theme
	ThemeID           int
	Users             []*User `gorm:"many2many:user_sites;"`
}

Site represents one website, the idea is that Beubo handles many websites at the same time, you could then have 100s of sites all on the same platform

func CreateSite

func CreateSite(db *gorm.DB, title string, domain string, siteType int, themeID int, destinationDomain string) Site

CreateSite is a method which creates a site using gorm

func DeleteSite

func DeleteSite(db *gorm.DB, id int) Site

DeleteSite removes a site from the database based on the provided id

func FetchSite

func FetchSite(db *gorm.DB, id int) (site Site)

FetchSite gets a site from the database using the provided id

func FetchSiteByHost

func FetchSiteByHost(db *gorm.DB, host string) Site

FetchSiteByHost retrieves a site from the database based on the provided host string TODO what if one site can have many hosts? For now a redirect can be added for other hosts

func FetchSites

func FetchSites(db *gorm.DB) (sites []Site)

FetchSites gets a site from the database using the provided id

type Tag

type Tag struct {
	gorm.Model
	Value string `gorm:"unique;not null"`
}

Tag of a post can be used for post categories or things like meta tag keywords for example

type Theme

type Theme struct {
	gorm.Model
	Title string `gorm:"size:255;unique_index"`
	Slug  string `gorm:"size:255;unique_index"`
}

Theme is the template or html files that a site uses, theme files are found under the web directory

func FetchTheme

func FetchTheme(db *gorm.DB, id int) Theme

FetchTheme gets a theme from the database using the provided id

func FetchThemeBySlug

func FetchThemeBySlug(db *gorm.DB, slug string) Theme

FetchThemeBySlug gets a theme from the database by the slug string

type User

type User struct {
	gorm.Model
	Email       string `gorm:"size:255"`
	Password    string `gorm:"size:255"`
	Activations []UserActivation
	Roles       []*Role `gorm:"many2many:user_roles;"`
	Sites       []*Site `gorm:"many2many:user_sites;"`
}

User is a user who can authenticate with Beubo

func AuthUser

func AuthUser(db *gorm.DB, email string, password string) *User

AuthUser authenticates the user by verifying a username and password

func DeleteUser

func DeleteUser(db *gorm.DB, id int) (user User)

DeleteUser deletes a user by id

func FetchUser

func FetchUser(db *gorm.DB, id int) User

FetchUser retrieves a user from the database using the provided id

func FetchUserByEmail

func FetchUserByEmail(db *gorm.DB, email string) User

FetchUserByEmail retrieves a user from the database using the provided email

func FetchUserFromSession

func FetchUserFromSession(db *gorm.DB, token string) User

FetchUserFromSession takes a provided token string and fetches the user for the session matching the provided token

func (User) CanAccess

func (u User) CanAccess(db *gorm.DB, featureKey string) bool

CanAccess checks if a user has access to the specified feature

func (User) CanAccessSite

func (u User) CanAccessSite(db *gorm.DB, site Site) bool

CanAccessSite checks if a user is allowed to access the specified site

func (User) HasRole

func (u User) HasRole(db *gorm.DB, r Role) bool

HasRole checks if a user has the specified role

type UserActivation

type UserActivation struct {
	gorm.Model
	UserID uint
	Type   string // Email, SMS, PushNotification
	Active bool
	Code   string
}

UserActivation is used to verify a user when signing up

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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