models

package
v0.0.0-...-9fe57bb Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DONTREPEAT = iota // == 0
	DAILY             //== 1
	WEEKLY            // == 2, etc
	MONTHLY
	YEARLY
)

Task periodicity type

View Source
const (
	PRIORITY1 = iota + 1 //== 1
	PRIORITY2            // == 2, etc
	PRIORITY3
	PRIORITY4
)

Task priorities from high to low, their proper titles are set on client side

View Source
const (
	NOTACTIVE uint = 0
	ACTIVE    uint = 1
	SUSPENDED uint = 2
)

User status codes

View Source
const (
	ADMIN  = 1
	EDITOR = 2
	USER   = 3
)

Mandatory user group IDs, adjust them accordingly if you need

Variables

This section is empty.

Functions

func Close

func Close()

Close terminates db handler

func InitializeDB

func InitializeDB()

InitializeDB initializes db variable by establishing connection to the db server

Types

type AccountVM

type AccountVM struct {
	Name            string `json:"name" binding:"required"`
	CurrentPassword string `json:"current_password"`
	NewPassword     string `json:"new_password"`
}

AccountVM is an account view model

type ActivateVM

type ActivateVM struct {
	Token string `json:"token" binding:"required"`
}

ActivateVM is an activation view model

type AttachedFile

type AttachedFile struct {
	ID        uint64    `gorm:"primary_key" json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	OwnerID   uint64    `json:"owner_id" gorm:"index:owner" valid:"required"`
	OwnerType string    `json:"owner_type" gorm:"index:owner" valid:"required"`
	UserID    uint64    `json:"user_id" valid:"-"`
	User      User      `json:"user" gorm:"save_associations:false" valid:"-"`
	Name      string    `json:"name"`
	FilePath  string    `json:"file_path" valid:"required"`
	URL       string    `json:"url" valid:"required"`
}

AttachedFile represents a polymorphic file attachment

func (*AttachedFile) BeforeDelete

func (a *AttachedFile) BeforeDelete(tx *gorm.DB) (err error)

BeforeDelete - gorm hook, validate removal here & delete other related records (no cascade tag atm)

type CategoriesRepository

type CategoriesRepository interface {
	GetAll(userID uint64) ([]Category, error)
	Get(userID uint64, id interface{}) (Category, error)
	Create(userID uint64, category Category) (Category, error)
	Update(userID uint64, category Category) (Category, error)
	Delete(userID uint64, id interface{}) error
	Summary(userID uint64) (CategoriesSummaryVM, error)
}

CategoriesRepository is a categories repository interface

var CategoriesDB CategoriesRepository

CategoriesDB is a categories db repository

type CategoriesSummaryVM

type CategoriesSummaryVM struct {
	Count int `json:"count"`
}

CategoriesSummaryVM is a view model for categories statistics

type Category

type Category struct {
	ID        uint64    `gorm:"primary_key" json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Name      string    `json:"name" valid:"required,length(1|1500)"`
	Tasks     []Task    `json:"tasks" gorm:"save_associations:false" valid:"-"`
	Projects  []Project `json:"projects" gorm:"save_associations:false" valid:"-"`
	UserID    uint64    `json:"user_id" valid:"-"`
	User      User      `json:"user" gorm:"save_associations:false" valid:"-"`
}

Category represents a project or task category (n:1 atm)

func (*Category) BeforeDelete

func (c *Category) BeforeDelete(tx *gorm.DB) (err error)

BeforeDelete - gorm hook, validate removal here

func (*Category) BeforeUpdate

func (c *Category) BeforeUpdate(tx *gorm.DB) (err error)

BeforeUpdate - gorm hook, fired before record update

type Comment

type Comment struct {
	ID            uint64         `gorm:"primary_key" json:"id"`
	CreatedAt     time.Time      `json:"created_at"`
	UpdatedAt     time.Time      `json:"updated_at"`
	Contents      string         `json:"contents" valid:"required,length(1|5000)"`
	IsSolution    bool           `json:"is_solution"`
	UserID        uint64         `json:"user_id" valid:"-"`
	User          User           `json:"user" gorm:"save_associations:false" valid:"-"`
	TaskID        uint64         `json:"task_id" gorm:"index" valid:"required"`
	Task          Task           `json:"task" gorm:"save_associations:false" valid:"-"`
	AttachedFiles []AttachedFile `json:"files" gorm:"polymorphic:Owner" valid:"-"`
}

Comment represents a task comment

func (*Comment) BeforeDelete

func (c *Comment) BeforeDelete(tx *gorm.DB) (err error)

BeforeDelete - gorm hook, validate removal here & delete other related records (no cascade tag atm)

func (*Comment) BeforeSave

func (c *Comment) BeforeSave(tx *gorm.DB) (err error)

BeforeSave - gorm hook, fired before record create or update

func (*Comment) BeforeUpdate

func (c *Comment) BeforeUpdate(tx *gorm.DB) (err error)

BeforeUpdate - gorm hook, fired before record update

type CommentsRepository

type CommentsRepository interface {
	GetAll(userID uint64, taskID interface{}) ([]Comment, error)
	Get(userID uint64, id interface{}) (Comment, error)
	Create(userID uint64, comment Comment) (Comment, error)
	Update(userID uint64, comment Comment) (Comment, error)
	Delete(userID uint64, id interface{}) error
}

CommentsRepository is a repository of comments

var CommentsDB CommentsRepository

CommentsDB is a comments db repository

type EditProjectVM

type EditProjectVM struct {
	Project    `json:"project"`
	Categories []Category `json:"categories"`
}

EditProjectVM is a view model for a new or an edited project

type EditTaskVM

type EditTaskVM struct {
	Projects   []Project  `json:"projects"`
	Categories []Category `json:"categories"`
	Task       `json:"task"`
}

EditTaskVM is a view model for a new or an edited task

type ForgotVM

type ForgotVM struct {
	Email string `json:"email" binding:"required"`
}

ForgotVM is a view model for forgotten password request

type JWTClaims

type JWTClaims struct {
	jwt.StandardClaims
	Name   string `json:"name,omitempty"`
	Role   string `json:"role,omitempty"`
	UserID uint64 `json:"user_id,omitempty"`
}

JWTClaims extends jwt-go.StandardClaims with custom fields

type Log

type Log struct {
	ID        uint64    `gorm:"primary_key" json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	IP        string    `json:"ip"`
	Session   string    `json:"session"`
	URL       string    `json:"url"`
	Headers   string    `json:"headers"`
	Message   string    `json:"message"`
}

Log represent log table Work in progress

type LoginVM

type LoginVM struct {
	Email    string `json:"email" binding:"required"`
	Password string `json:"password" binding:"required"`
}

LoginVM is a login view model

type NewSessionVM

type NewSessionVM struct {
	TaskLogs []TaskLog `json:"task_logs"`
}

NewSessionVM is a view model for a new session

type Page

type Page struct {
	ID              uint64    `gorm:"primary_key" json:"id"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`
	Name            string    `json:"name" valid:"required, length(1|500)"`
	Description     string    `json:"description" valid:"length(0|100000)"`
	MetaKeywords    string    `json:"meta_keywords" valid:"length(0|200)"`
	MetaDescription string    `json:"meta_description" valid:"length(0|200)"`
	Slug            string    `json:"slug"`
	Published       bool      `json:"published"`
}

Page represents a record in pages table

func (*Page) BeforeSave

func (p *Page) BeforeSave() (err error)

BeforeSave gorm hook

func (*Page) Excerpt

func (p *Page) Excerpt(length int) string

Excerpt returns page excerpt

func (*Page) HTMLContent

func (p *Page) HTMLContent() template.HTML

HTMLContent returns parsed html content

type PagesRepository

type PagesRepository interface {
	GetAll() ([]Page, error)
	Get(id interface{}) (Page, error)
	GetPagesForMenu() ([]Page, error)
	Create(page Page) (Page, error)
	Update(page Page) (Page, error)
	Delete(id interface{}) error
}

PagesRepository is a repository of pages

var PagesDB PagesRepository

PagesDB is a pages db repository

type ParticipantRequest

type ParticipantRequest struct {
	IDFrom    uint64    `json:"id_from" valid:"required"`
	EmailTo   string    `json:"email_to" valid:"required,email"`
	Token     string    `json:"token" valid:"required,length(1|500)"`
	CreatedAt time.Time `json:"created_at,omitempty"`
}

ParticipantRequest represents a row from participant_requests table

func (*ParticipantRequest) BeforeCreate

func (r *ParticipantRequest) BeforeCreate() (err error)

BeforeCreate gorm hook

type PeriodicitiesRepository

type PeriodicitiesRepository interface {
	CreateRecurringTasks(date time.Time) error
}

PeriodicitiesRepository is a repository of periodicities

var PeriodicitiesDB PeriodicitiesRepository

PeriodicitiesDB is a periodicities db repository

type Periodicity

type Periodicity struct {
	ID              uint64     `gorm:"primary_key" json:"id"`
	CreatedAt       time.Time  `json:"created_at"`
	UpdatedAt       time.Time  `json:"updated_at"`
	PeriodicityType uint       `json:"periodicity_type,string"` //see constants
	Weekdays        uint       `json:"weekdays"`                //a bitmask of selected weekdays, makes sense only for periodicity == WEEKLY. 1 - Monday ... 64 - Sunday
	RepeatingFrom   *time.Time `json:"repeating_from"`          //for periodicity == MONTHLY or YEARLY. This will be the StartDate and EndDate (for each month or year) of the newly created task accordingly
	RepeatingTo     *time.Time `json:"repeating_to"`            //see RepeatingFrom
	Tasks           []Task     `json:"tasks" gorm:"save_associations:false" valid:"-"`
	UserID          uint64     `json:"user_id" valid:"-"`
	User            User       `json:"user" gorm:"save_associations:false" valid:"-"`
}

Periodicity represents a periodicity settings for periodical tasks

func (*Periodicity) BeforeUpdate

func (p *Periodicity) BeforeUpdate(tx *gorm.DB) (err error)

BeforeUpdate - gorm hook, fired before record update

type Project

type Project struct {
	ID            uint64         `gorm:"primary_key" json:"id"`
	CreatedAt     time.Time      `json:"preated_at"`
	UpdatedAt     time.Time      `json:"updated_at"`
	Favorite      bool           `json:"favorite"`
	Name          string         `json:"name" valid:"required,length(1|1500)"`
	Despription   string         `json:"description" valid:"length(0|100000)"`
	Archived      bool           `json:"archived"`
	UserID        uint64         `json:"user_id" valid:"-"`
	User          User           `json:"user" gorm:"save_associations:false" valid:"-"`
	CategoryID    uint64         `json:"category_id,string,omitempty"`
	AttachedFiles []AttachedFile `json:"files" gorm:"polymorphic:Owner" valid:"-"`
	Tasks         []Task         `json:"tasks" gorm:"save_associations:false" valid:"-"`
	Category      Category       `json:"category" gorm:"save_associations:false" valid:"-"`
}

Project represents a record from projects table

func (*Project) BeforeDelete

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

BeforeDelete - gorm hook, validate removal here & delete other related records (no cascade tag atm)

func (*Project) BeforeSave

func (p *Project) BeforeSave(tx *gorm.DB) (err error)

BeforeSave - gorm hook, fired before record update or preation

func (*Project) BeforeUpdate

func (p *Project) BeforeUpdate(tx *gorm.DB) (err error)

BeforeUpdate - gorm hook, fired before record update

type ProjectsRepository

type ProjectsRepository interface {
	GetAll(userID uint64) ([]Project, error)
	GetAllFavorite(userID uint64) ([]Project, error)
	Get(userID uint64, id interface{}) (Project, error)
	GetNew(userID uint64) (EditProjectVM, error)
	GetEdit(userID uint64, id interface{}) (EditProjectVM, error)
	Create(userID uint64, project Project) (Project, error)
	Update(userID uint64, project Project) (Project, error)
	ToggleArchive(userID uint64, project Project) (Project, error)
	ToggleFavorite(userID uint64, project Project) (Project, error)
	Delete(userID uint64, id interface{}) error
	Summary(userID uint64) (ProjectsSummaryVM, error)
}

ProjectsRepository is a projects repository

var ProjectsDB ProjectsRepository

ProjectsDB is a projects db repository

type ProjectsSummaryVM

type ProjectsSummaryVM struct {
	Count int `json:"count"`
}

ProjectsSummaryVM is a view model for projects statistics

type RegisterVM

type RegisterVM struct {
	Name     string `json:"name" binding:"required"`
	Email    string `json:"email" binding:"required"`
	Password string `json:"password" binding:"required"`
}

RegisterVM is a registration view model

type ReportsRepository

type ReportsRepository interface {
	Spent(userID uint64) ([]TaskLog, error)
}

ReportsRepository is a reports repository

var ReportsDB ReportsRepository

ReportsDB is a reports db repository

type ResetVM

type ResetVM struct {
	Token    string `json:"token" binding:"required"`
	Password string `json:"password" binding:"required"`
}

ResetVM is a view model for password reset requests

type SearchRepository

type SearchRepository struct{}

SearchRepository is a repository for searching entities

var SearchDB SearchRepository

SearchDB is a db search repository

func (*SearchRepository) Search

func (pr *SearchRepository) Search(userID uint64, query string) (SearchVM, error)

Search returns all matching entities owned by the specified user

type SearchVM

type SearchVM struct {
	Categories []Category `json:"categories"`
	Projects   []Project  `json:"projects"`
	Tasks      []Task     `json:"tasks"`
	Comments   []Comment  `json:"comments"`
}

SearchVM is a view model for search queries

type Session

type Session struct {
	ID        uint64    `gorm:"primary_key" json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Contents  string    `json:"contents" valid:"length(0|5000)"`
	UserID    uint64    `json:"user_id" valid:"-"`
	User      User      `json:"user" gorm:"save_associations:false" valid:"-"`
	TaskLogs  []TaskLog `json:"task_logs" gorm:"save_associations:true" valid:"-"`
}

Session represents a work session, where task logs (spent time) are commited once the task log is commited and session saved, it's is not shown in spent report

func (*Session) BeforeCreate

func (s *Session) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate - gorm hook, fired before record creation

func (*Session) BeforeDelete

func (s *Session) BeforeDelete(tx *gorm.DB) (err error)

BeforeDelete - gorm hook, validate removal here & delete other related records (no cascade tag atm)

type SessionsRepository

type SessionsRepository interface {
	GetAll(userID uint64) ([]Session, error)
	Get(userID uint64, id interface{}) (Session, error)
	NewGet(userID uint64) (Session, error)
	Create(userID uint64, session Session) (Session, error)
	Delete(userID uint64, id interface{}) error
	Summary(userID uint64) (SessionsSummaryVM, error)
}

SessionsRepository is a repository of sessions

var SessionsDB SessionsRepository

SessionsDB is a sessions db repository

type SessionsSummaryVM

type SessionsSummaryVM struct {
	Count int `json:"count"`
}

SessionsSummaryVM is a view model for sessions statistics

type Setting

type Setting struct {
	ID        uint64    `gorm:"primary_key" json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Code      string    `json:"code" valid:"required,length(1|100)"`
	Title     string    `json:"title"`
	Value     string    `json:"value" valid:"required"`
}

Setting type contains settings info

type SettingsRepository

type SettingsRepository interface {
	GetAll() ([]Setting, error)
	Get(id interface{}) (Setting, error)
	Create(setting Setting) (Setting, error)
	Update(setting Setting) (Setting, error)
	Delete(id interface{}) error
}

SettingsRepository is a repository of settings

var SettingsDB SettingsRepository

SettingsDB is a settings db repository

type Task

type Task struct {
	ID            uint64         `gorm:"primary_key" json:"id"`
	CreatedAt     time.Time      `json:"treated_at"`
	UpdatedAt     time.Time      `json:"updated_at"`
	Name          string         `json:"name" valid:"required,length(1|1500)"`
	Destription   string         `json:"description" valid:"length(0|10000)"`
	StartDate     *time.Time     `json:"start_date"`
	EndDate       *time.Time     `json:"end_date"`
	PeriodicityID uint64         `json:"periodicity_id,omitempty" gorm:"index"`
	Periodicity   Periodicity    `json:"periodicity" gorm:"save_associations:true"`
	Completed     bool           `json:"completed"`
	Priority      uint           `json:"priority,string"` //see constants
	ProjectID     uint64         `json:"project_id,string,omitempty" gorm:"index" valid:"required"`
	Project       Project        `json:"project" gorm:"save_associations:false" valid:"-"`
	CategoryID    uint64         `json:"category_id,string,omitempty" gorm:"index"`
	Category      Category       `json:"category" gorm:"save_associations:false" valid:"-"`
	UserID        uint64         `json:"user_id" valid:"-"`
	User          User           `json:"user" gorm:"save_associations:false" valid:"-"`
	Comments      []Comment      `json:"comments" gorm:"save_associations:false" valid:"-"`
	TaskLogs      []TaskLog      `json:"task_logs" gorm:"save_associations:false" valid:"-"`
	AttachedFiles []AttachedFile `json:"files" gorm:"polymorphic:Owner" valid:"-"`
}

Task represents a row from tasks table

func (*Task) BeforeDelete

func (t *Task) BeforeDelete(tx *gorm.DB) (err error)

BeforeDelete - gorm hook, validate removal here & delete other related records (no cascade tag atm)

func (*Task) BeforeSave

func (t *Task) BeforeSave(tx *gorm.DB) (err error)

BeforeSave - gorm hook, fired before record update or treation

func (*Task) BeforeUpdate

func (t *Task) BeforeUpdate(tx *gorm.DB) (err error)

BeforeUpdate - gorm hook, fired before record update

type TaskLog

type TaskLog struct {
	ID        uint64    `gorm:"primary_key" json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	TaskID    uint64    `json:"task_id" gorm:"index" valid:"required"`
	Minutes   uint64    `json:"minutes"`
	Commited  bool      `json:"commited"`
	UserID    uint64    `json:"user_id" valid:"-"`
	User      User      `json:"user" gorm:"save_associations:false" valid:"-"`
	Task      Task      `json:"task" gorm:"save_associations:false" valid:"-"`
	SessionID uint64    `json:"session_id" gorm:"index"`
	Session   Session   `json:"session" gorm:"save_associations:false" valid:"-"`
}

TaskLog represents a task workflow log

func (*TaskLog) BeforeDelete

func (t *TaskLog) BeforeDelete(tx *gorm.DB) (err error)

BeforeDelete - gorm hook, validate removal here & delete other related records (no cascade tag atm)

func (*TaskLog) BeforeUpdate

func (t *TaskLog) BeforeUpdate(tx *gorm.DB) (err error)

BeforeUpdate - gorm hook, fired before record update

type TaskLogsRepository

type TaskLogsRepository interface {
	Create(userID uint64, taskLog TaskLog) (TaskLog, error)
	Update(userID uint64, taskLog TaskLog) (TaskLog, error)
	Latest(userID uint64) ([]TaskLog, error)
}

TaskLogsRepository is a taskLogs repository

var TaskLogsDB TaskLogsRepository

TaskLogsDB is a task logs db repository

type TasksRepository

type TasksRepository interface {
	GetAll(userID uint64) ([]Task, error)
	Get(userID uint64, id interface{}) (Task, error)
	GetNew(userID uint64, projectID uint64) (EditTaskVM, error)
	GetEdit(userID uint64, id interface{}) (EditTaskVM, error)
	Create(userID uint64, task Task) (Task, error)
	Update(userID uint64, task Task) (Task, error)
	Delete(userID uint64, id interface{}) error
	Summary(userID uint64) (TasksSummaryVM, error)
	Latest(userID uint64) ([]Task, error)
}

TasksRepository is a repository of tasks

var TasksDB TasksRepository

TasksDB is a tasks db repository

type TasksSummaryVM

type TasksSummaryVM struct {
	Count int `json:"count"`
}

TasksSummaryVM is a view model for tasks statistics

type User

type User struct {
	ID           uint64    `gorm:"primary_key" json:"id"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
	Name         string    `json:"name" valid:"required,length(1|100)"`
	Email        string    `json:"email" gorm:"unique_index" valid:"required,email,length(1|100)"`
	PasswordHash string    `json:"-" valid:"required"`
	Token        string    `json:"token" valid:"length(0|1500)"` //activation|password reset token
	JWTToken     string    `json:"jwt_token"`                    //jwt token
	UserGroupID  uint64    `json:"user_group_id" gorm:"index" valid:"required"`
	Status       uint      `json:"status"` //See constants
	UserGroup    UserGroup `json:"user_group" gorm:"save_associations:false" valid:"-"`
}

User represents a row from users table

func (*User) BeforeCreate

func (u *User) BeforeCreate() (err error)

BeforeCreate gorm hook

func (*User) BeforeDelete

func (u *User) BeforeDelete() (err error)

BeforeDelete gorm hook

func (*User) BeforeUpdate

func (u *User) BeforeUpdate() (err error)

BeforeUpdate gorm hook

func (*User) CreateJWTToken

func (u *User) CreateJWTToken() error

CreateJWTToken issues a valid JWT token

func (*User) HasPassword

func (u *User) HasPassword(password string) bool

HasPassword checks if user has this password

func (*User) IsActive

func (u *User) IsActive() bool

IsActive checks if user is active

func (*User) IsAdmin

func (u *User) IsAdmin() bool

IsAdmin checks if user is admin

func (*User) IsEditor

func (u *User) IsEditor() bool

IsEditor checks if user is editor

func (*User) IsUser

func (u *User) IsUser() bool

IsUser checks if user is a regular user

type UserGroup

type UserGroup struct {
	ID         uint64    `gorm:"primary_key" json:"id"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
	Name       string    `json:"name" valid:"required,length(1|100)"`
	Persistent bool      `json:"persistent"`
	Users      []User    `json:"users" gorm:"save_associations:false" valid:"-"`
}

UserGroup represents a row from user_groups table

func (*UserGroup) BeforeDelete

func (ug *UserGroup) BeforeDelete(tx *gorm.DB) (err error)

BeforeDelete gorm hook

type UsersRepository

type UsersRepository interface {
	GetAll() ([]User, error)
	Get(id interface{}) (User, error)
	GetByEmail(email string) (User, error)
	UpdateStatus(user User) (User, error)
	UpdateAccount(vm AccountVM, user User) (User, error)
	Login(vm LoginVM) (User, error)
	Activate(vm ActivateVM) (User, error)
	Register(vm RegisterVM) (User, error)
	Forgot(vm ForgotVM) (User, error)
	ResetPassword(vm ResetVM) (User, error)
	Summary() (UsersSummaryVM, error)
}

UsersRepository is a users repository interface

var UsersDB UsersRepository

UsersDB is a user db repository

type UsersSummaryVM

type UsersSummaryVM struct {
	Count int `json:"count"`
}

UsersSummaryVM is a view model for users statistics

Jump to

Keyboard shortcuts

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