model

package
v0.0.0-...-54a4899 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2022 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DB          *gorm.DB
	Redis       *redis.Client
	AuthLimiter *redis_rate.Limiter
)

Functions

func AddLog

func AddLog(db *gorm.DB, body string)

func AddMime

func AddMime(db *gorm.DB, mime string) int

func AddTagToFile

func AddTagToFile(db *gorm.DB, tag string, fileId int, userId int)

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

func ConnectToMysql

func ConnectToMysql()

func CreateCounter

func CreateCounter(name string) uint

func CreateDevice

func CreateDevice(name string, userId uint) uint

func CreateGroup

func CreateGroup(name string) uint

func CreateProject

func CreateProject(name string, groupId uint) uint

func CreateTask

func CreateTask(task Task)

func CreateUser

func CreateUser(username string, email string, password string)

func DeviceEventAdd

func DeviceEventAdd(code EventCode, userId uint, deviceId uint)

func DeviceEventAddInt

func DeviceEventAddInt(code EventCode, userId uint, deviceId uint, val int)

func DeviceEventAddStr

func DeviceEventAddStr(code EventCode, userId uint, deviceId uint, str string)

func HashPassword

func HashPassword(password string) (string, error)

func ImportCountersFromJson

func ImportCountersFromJson(pathToFile string)

func ImportZfire

func ImportZfire(pathToJson string)

func InitMysql

func InitMysql()

func InitRedis

func InitRedis()

func IsInArray

func IsInArray(list []string, name string) bool

helper

func IsInList

func IsInList(list []ZfireLogGameList, name string) bool

helper

func MigrateMysql

func MigrateMysql()

func PrettyTime

func PrettyTime(s uint) string

func StartCounterSession

func StartCounterSession(counterId uint, userId uint) uint

func StopCounterSession

func StopCounterSession(counterId uint, userId uint) (sessionId uint, sessionTaken string)

func TaskDoneEvent

func TaskDoneEvent(userId uint, taskId int)

Types

type Counter

type Counter struct {
	Id        uint       `json:"id" gorm:"primary_key;type:uint(10)" json:"id"`
	Name      string     `gorm:"column:name" json:"username"`
	ProjectId uint       `gorm:"column:project_id" json:"group_id"`
	CreatedAt *time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt *time.Time `gorm:"column:updated_at" json:"updated_at"`
	DeletedAt *time.Time `gorm:"column:deleted_at" json:"deleted_at"`
}

type CounterList

type CounterList struct {
	Counter
	Tags                string `json:"tags"`
	Seconds7d           uint   `json:"secondsD7"`
	Seconds30d          uint   `json:"secondsD30"`
	SecondsAll          uint   `json:"secondsAll"`
	Seconds7dFormatted  string `json:"secondsD7F"`
	Seconds30dFormatted string `json:"secondsD30F"`
	SecondsAllFormatted string `json:"secondsAllF"`
	Running             uint   `json:"running"`
}

func CounterStats

func CounterStats(counterId, userId uint) (result []CounterList)

func CountersLatestListAndroid

func CountersLatestListAndroid(userId uint) (err error, result []CounterList)

func CountersLongList

func CountersLongList(userId uint) (result []CounterList)

func CountersLongListPaginate

func CountersLongListPaginate(userId uint, limit int, nextId int, prevId int, qTerm string) (result []CounterList, allRecords int)

type CounterSession

type CounterSession struct {
	Id        uint       `json:"id" gorm:"primary_key;type:uint(10)" json:"id"`
	CounterId uint       `gorm:"column:counter_id" json:"counter_id"`
	UserId    uint       `gorm:"column:user_id" json:"user_id"`
	StartedAt *time.Time `gorm:"column:started_at" json:"started_at"`
	EndedAt   *time.Time `gorm:"column:ended_at" json:"ended_at"`
	Precise   uint       `gorm:"column:precise" json:"precise"`
	CreatedAt *time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt *time.Time `gorm:"column:updated_at" json:"updated_at"`
	DeletedAt *time.Time `gorm:"column:deleted_at" json:"deleted_at"`
}

type CounterSessionList

type CounterSessionList struct {
	CounterId         uint
	Id                uint
	UserId            uint
	Name              string
	Tags              string
	StartedAt         time.Time
	EndedAt           mysql.NullTime
	Duration          uint
	DurationFormatted string
	Running           bool
}

func CounterLog

func CounterLog(counterId int, userId uint, limit int) (result []CounterSessionList)

func CounterLogList

func CounterLogList(userId uint, limit int) (result []CounterSessionList)

type CounterTag

type CounterTag struct {
	Id        uint       `json:"id" gorm:"primary_key;type:uint(10)" json:"id"`
	CounterId uint       `gorm:"column:counter_id" json:"counter_id"`
	Name      string     `gorm:"column:name" json:"name"`
	CreatedAt *time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt *time.Time `gorm:"column:updated_at" json:"updated_at"`
	DeletedAt *time.Time `gorm:"column:deleted_at" json:"deleted_at"`
}

type Device

type Device struct {
	Id        uint       `json:"id" gorm:"primary_key;type:uint(10)" json:"id"`
	UserId    uint       `gorm:"column:user_id"`
	Name      string     `gorm:"column:name"`
	Token     string     `gorm:"token"`
	TokenPush string     `gorm:"token_push"`
	CreatedAt *time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt *time.Time `gorm:"column:updated_at" json:"updated_at"`
	DeletedAt *time.Time `gorm:"column:deleted_at" json:"deleted_at"`
}

type DeviceList

type DeviceList struct {
	Id                 uint      `json:"id"`
	UserId             uint      `json:"userId"`
	Name               string    `json:"name"`
	CreatedAt          time.Time `json:"createdAt"`
	DisplayState       string    `json:"displayState"`
	DisplayOnLastTime  time.Time `json:"displayLastOn"`
	DisplayOffLastTime time.Time `json:"displayLastOff"`
	BatteryLeft        uint      `json:"battery"`
	Username           string    `json:"username"`
	MusicTrack         string    `json:"musicTrack"`
	MusicArtist        string    `json:"musicArtist"`
	MusicLastPlayed    time.Time `json:"musicLastPlayed"`
}

func GetListOfDevices

func GetListOfDevices() (result []DeviceList)

type Event

type Event struct {
	Id        uint           `json:"id" gorm:"primary_key;type:uint(10)" json:"id"`
	UserId    uint           `gorm:"column:user_id"`
	DeviceId  uint           `gorm:"column:device_id"`
	Code      EventCode      `gorm:"column:code" json:"code"`
	ValueStr  sql.NullString `gorm:"column:val_str" json:"valStr"`
	ValueInt  sql.NullInt64  `gorm:"column:val_int"`
	CreatedAt *time.Time     `gorm:"column:created_at" json:"createdAt"`
}

type EventCode

type EventCode uint
const (
	Noop EventCode = iota
	DeviceBatteryPercent
	DeviceScreenOn
	DeviceMusicTrack
	DeviceMusicArtist
	DeviceScreenOff
	TaskDone
)

type File

type File struct {
	Id       int    `gorm:"AUTO_INCREMENT" json:"id"`
	Filename string `gorm:"column:file_name" json:"filename"`
	FilePath string `gorm:"column:file_path;type:varchar(4096)" json:"filePath"`
	SizeB    int    `gorm:"column:size_b" json:"sizeB"`
	MimeId   int    `gorm:"column:mime_id" json:"-"`
	PhashA   int    `gorm:"column:phash_a;type:bigint(16)" json:"-"`
	PhashB   int    `gorm:"column:phash_b;type:bigint(16)" json:"-"`
	PhashC   int    `gorm:"column:phash_c;type:bigint(16)" json:"-"`
	PhashD   int    `gorm:"column:phash_d;type:bigint(16)" json:"-"`
	Sha256   string `gorm:"column:sha256;type:char(64)" json:"sha256"`

	CreatedAt *time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt *time.Time `gorm:"column:updated_at" json:"updated_at"`
	DeletedAt *time.Time `gorm:"column:deleted_at" json:"-"`

	// helpers, not present in DB
	Mime     string `gorm:"-" json:"mime"`
	Tags     string `gorm:"-" json:"tags"`
	Distance int    `gorm:"-" json:"distance"`
}

func FileListPaginate

func FileListPaginate(userId int, limit int, nextId int, prevId int, qTerm string) (result []File, allRecords int)

func GetFileByIdForUser

func GetFileByIdForUser(fileId int, userId int) (res File)

func SimilarFiles

func SimilarFiles(sha256 string, userId int, limit int) (result []File)

TODO userId as a option, cross user suggestions

type FileTag

type FileTag struct {
	Id     int `json:"id" gorm:"AUTO_INCREMENT" json:"id"`
	UserId int `gorm:"column:user_id"`
	FileId int `gorm:"column:file_id"`
	TagId  int `gorm:"column:tag_id"`

	CreatedAt *time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt *time.Time `gorm:"column:updated_at" json:"updated_at"`
	DeletedAt *time.Time `gorm:"column:deleted_at" json:"deleted_at"`
}

type FileTagList

type FileTagList struct {
	FileId int    `json:"fileId"`
	Tags   string `json:"tags"`
}

func FileTagsList

func FileTagsList(fileList []FileTagList, userId int) []FileTagList

TODO optimize, don't run it in loop

type FileUser

type FileUser struct {
	Id     int `json:"id" gorm:"AUTO_INCREMENT" json:"id"`
	FileId int `gorm:"column:file_id"`
	UserId int `gorm:"column:user_id"`

	CreatedAt *time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt *time.Time `gorm:"column:updated_at" json:"updated_at"`
	DeletedAt *time.Time `gorm:"column:deleted_at" json:"deleted_at"`
}

type Group

type Group struct {
	Id        uint       `json:"id" gorm:"primary_key;type:uint(10)" json:"id"`
	Name      string     `gorm:"column:name" json:"username"`
	CreatedAt *time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt *time.Time `gorm:"column:updated_at" json:"updated_at"`
}

type Log

type Log struct {
	Id        int        `json:"id" gorm:"AUTO_INCREMENT" json:"id"`
	Body      string     `gorm:"column:body"`
	CreatedAt *time.Time `gorm:"column:created_at" json:"created_at"`
}

type Mime

type Mime struct {
	Id   int    `json:"id" gorm:"AUTO_INCREMENT" json:"id"`
	Mime string `gorm:"column:mime"`

	CreatedAt *time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt *time.Time `gorm:"column:updated_at" json:"updated_at"`
	DeletedAt *time.Time `gorm:"column:deleted_at" json:"deleted_at"`
}

type Note

type Note struct {
	Id        uint          `json:"id" gorm:"primary_key;type:uint(10)" json:"id"`
	Title     string        `gorm:"column:title" json:"title"`
	Body      string        `gorm:"column:body" json:"body"`
	BodyShort string        `gorm:"-"`
	BodyMd    template.HTML `gorm:"-"`
	ProjectId uint          `gorm:"column:project_id" json:"projectId"`
	Tags      string        `gorm:"-"`
	CreatedAt *time.Time    `gorm:"column:created_at" json:"createdAt"`
	UpdatedAt *time.Time    `gorm:"column:updated_at" json:"updatedAt"`
	DeletedAt *time.Time    `gorm:"column:deleted_at" json:"deletedAt"`
}

func CreateNote

func CreateNote(title string, body string, tags string, projectId uint) Note

func NoteLongList

func NoteLongList() (result []Note)

func OneNote

func OneNote(id uint) (result []Note)

func (*Note) BeforeSave

func (note *Note) BeforeSave(scope *gorm.Scope) (err error)

type NoteTag

type NoteTag struct {
	Id        uint       `json:"id" gorm:"primary_key;type:uint(10)" json:"id"`
	NoteId    uint       `gorm:"column:note_id" json:"note_id"`
	Name      string     `gorm:"column:name" json:"name"`
	CreatedAt *time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt *time.Time `gorm:"column:updated_at" json:"updated_at"`
	DeletedAt *time.Time `gorm:"column:deleted_at" json:"deleted_at"`
}

type Project

type Project struct {
	// ID
	//
	// required: true
	Id uint `json:"id" gorm:"primary_key;type:uint(10)" json:"id"`

	// Username
	//
	// required: true
	Name      string     `gorm:"column:name" json:"name"`
	GroupId   uint       `gorm:"column:group_id" json:"groupId"`
	CreatedAt *time.Time `gorm:"column:created_at" json:"createdAt"`
	UpdatedAt *time.Time `gorm:"column:updated_at" json:"updatedAt"`
	DeletedAt *time.Time `gorm:"column:deleted_at" json:"deletedAt"`
}

Host represents the host for this application swagger:model user

type Tag

type Tag struct {
	Id  int    `json:"id" gorm:"AUTO_INCREMENT" json:"id"`
	Tag string `gorm:"column:tag" json:"tag"`

	CreatedAt *time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt *time.Time `gorm:"column:updated_at" json:"updated_at"`
	DeletedAt *time.Time `gorm:"column:deleted_at" json:"deleted_at"`

	// not in table
	Counter int `gorm:"-" json:"counter"`
}

func TagList

func TagList(userId int) (result []Tag)

type Task

type Task struct {
	Id             uint       `gorm:"primary_key;type:uint(10)" json:"id"`
	Subject        string     `gorm:"column:subject" json:"subject"`
	ProjectId      uint       `gorm:"column:project_id"`
	AssignedUserId uint       `gorm:"column:assigned_user_id"`
	Repeating      uint       `gorm:"column:repeating"`
	NeverEnding    uint       `gorm:"column:never_ending"`
	RepeatUnit     string     `gorm:"column:repeat_unit"`
	RepeatMin      uint       `gorm:"column:repeat_min"`
	RepeatBest     uint       `gorm:"column:repeat_best"`
	RepeatMax      uint       `gorm:"column:repeat_max"`
	RepeatFrom     *time.Time `gorm:"column:repeat_from"`
	SnoozeTo       *time.Time `gorm:"column:snooze_to"`
	// RepeatFrom       mysql.NullTime `gorm:"column:repeat_from"`
	EstimateS        uint          `gorm:"column:estimate_s"`
	MasterTaskId     uint          `gorm:"column:master_task_id"`
	SeparateChildren uint          `gorm:"column:separate_children"`
	DoneAt           *sql.NullTime `gorm:"column:done_at" json:"doneAt"`
	CreatedAt        *time.Time    `gorm:"column:created_at" json:"created_at"`
	UpdatedAt        *time.Time    `gorm:"column:updated_at" json:"updated_at"`
	DeletedAt        *time.Time    `gorm:"column:deleted_at" json:"deleted_at"`
}

type TaskDoneT

type TaskDoneT struct {
	Subject   string     `json:"subject"`
	Username  string     `json:"username"`
	CreatedAt *time.Time `json:"createdAt"`
}

func TaskDoneEvents7days

func TaskDoneEvents7days() (result []TaskDoneT)

type TaskTabExport

type TaskTabExport struct {
	Name            string               `json:"name"`
	CreatedAt       time.Time            `json:"createdAt"`
	Tags            []string             `json:"tags"`
	ZfireTimeSumS   uint                 `json:"zfireTimeSummaryS"`
	TaskTabTimeSumS uint                 `json:"taskTabTimeSummaryS"`
	ZfireTimeSumP   uint                 `json:"zfireTimeSummaryP"`
	TaskTabTimeSumP uint                 `json:"taskTabTimeSummaryP"`
	SessionsS       TaskTabExportSession `json:"sessionsS"`
	SessionsP       TaskTabExportSession `json:"sessionsP"`
}

final export json

type TaskTabExportSession

type TaskTabExportSession []struct {
	Duration  int
	StartedAt time.Time
	EndedAt   time.Time
	Precise   uint
}

func (TaskTabExportSession) Len

func (a TaskTabExportSession) Len() int

func (TaskTabExportSession) Less

func (a TaskTabExportSession) Less(i, j int) bool

func (TaskTabExportSession) Swap

func (a TaskTabExportSession) Swap(i, j int)

type TaskTabExports

type TaskTabExports []TaskTabExport

func (TaskTabExports) Len

func (a TaskTabExports) Len() int

func (TaskTabExports) Less

func (a TaskTabExports) Less(i, j int) bool

func (TaskTabExports) Swap

func (a TaskTabExports) Swap(i, j int)

type User

type User struct {
	// ID
	//
	// required: true
	Id uint `json:"id" gorm:"primary_key;type:uint(10)" json:"id"`

	// Username
	//
	// required: true
	Username         string     `gorm:"column:username" json:"username"`
	Email            string     `gorm:"column:email" json:"email"`
	Hash             string     `gorm:"column:hash" json:"hash"`
	DefaultProjectId uint       `gorm:"column:default_project_id"`
	CreatedAt        *time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt        *time.Time `gorm:"column:updated_at" json:"updated_at"`
}

Host represents the host for this application swagger:model user

func GetUserById

func GetUserById(id uint) (ok bool, usr User)

func IsPasswordOk

func IsPasswordOk(username string, password string) (ok bool, usr User)

type WebhookAction

type WebhookAction struct {
	Id        uint       `json:"id" gorm:"primary_key;type:uint(10)" json:"id"`
	Extra     string     `gorm:"column:extra"`
	Type      uint       `gorm:"column:type"`
	CreatedAt *time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt *time.Time `gorm:"column:updated_at" json:"updated_at"`
	DeletedAt *time.Time `gorm:"column:deleted_at" json:"deleted_at"`
}

type WebhookReceiver

type WebhookReceiver struct {
	Id        uint       `json:"id" gorm:"primary_key;type:uint(10)" json:"id"`
	ProjectId uint       `gorm:"column:project_id"`
	ActionId  uint       `gorm:"column:action_id"`
	CreatedAt *time.Time `gorm:"column:created_at" json:"created_at"`
	UpdatedAt *time.Time `gorm:"column:updated_at" json:"updated_at"`
	DeletedAt *time.Time `gorm:"column:deleted_at" json:"deleted_at"`
}

type ZfireGame

type ZfireGame []struct {
	Date  time.Time `json:"date"`
	Name  string    `json:"name"`
	TimeP int       `json:"time_p"`
	TimeS int       `json:"time_s"`
	Tags  []string  `json:"tags"`
}

store complete game list with game time summary

func (ZfireGame) Len

func (a ZfireGame) Len() int

sorting functions

func (ZfireGame) Less

func (a ZfireGame) Less(i, j int) bool

func (ZfireGame) Swap

func (a ZfireGame) Swap(i, j int)

type ZfireLog

type ZfireLog []struct {
	Name  string    `json:"name"`
	TimeP int       `json:"time_p"`
	TimeS int       `json:"time_s"`
	Date  time.Time `json:"date"`
}

store game sessions this log doesn't have entries pre 2012-10-03 - instead it's counted in time_p and time_s as a summary

func (ZfireLog) Len

func (a ZfireLog) Len() int

sorting functions

func (ZfireLog) Less

func (a ZfireLog) Less(i, j int) bool

func (ZfireLog) Swap

func (a ZfireLog) Swap(i, j int)

type ZfireLogGameList

type ZfireLogGameList struct {
	Name string
	Date time.Time
}

temp local store

Jump to

Keyboard shortcuts

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