ffk-timetracker/backend/database/models.go
2026-07-27 20:33:49 +02:00

88 lines
3.2 KiB
Go

package database
import (
"time"
"gorm.io/gorm"
)
type UserRole string
const (
UserRoleUser UserRole = "user"
UserRoleAdmin UserRole = "admin"
)
type User struct {
ID uint `gorm:"primaryKey" json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
Subject string `gorm:"uniqueIndex;size:191;not null" json:"subject"`
Email string `gorm:"index;size:191;not null" json:"email"`
Name string `gorm:"size:191;not null" json:"name"`
FirstName string `gorm:"size:191" json:"firstName"`
LastName string `gorm:"size:191" json:"lastName"`
Role UserRole `gorm:"size:16;not null;default:user" json:"role"`
FavoriteFunctionID *uint `gorm:"index" json:"favoriteFunctionId,omitempty"`
Language string `gorm:"size:8" json:"language"`
TimeEntries []TimeEntry `json:"-"`
APITokens []APIToken `json:"-"`
}
type AppSettings struct {
ID uint `gorm:"primaryKey" json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
ApplicationTitle string `gorm:"size:191;not null;default:Timetracker" json:"applicationTitle"`
OrganizationName string `gorm:"size:191;not null;default:Feuerwehr Ketsch" json:"organizationName"`
DefaultLanguage string `gorm:"size:8;not null;default:de" json:"defaultLanguage"`
}
type Function struct {
ID uint `gorm:"primaryKey" json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
Name string `gorm:"uniqueIndex;size:191;not null" json:"name"`
Description string `gorm:"size:512" json:"description"`
Color string `gorm:"size:32;not null;default:#C62828" json:"color"`
Active bool `gorm:"not null;default:true" json:"active"`
TimeEntries []TimeEntry `json:"-"`
}
type TimeEntry struct {
ID uint `gorm:"primaryKey" json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
UserID uint `gorm:"index;not null" json:"userId"`
User User `json:"user"`
FunctionID uint `gorm:"index;not null" json:"functionId"`
Function Function `json:"function"`
StartedAt time.Time `gorm:"index;not null" json:"startedAt"`
EndedAt *time.Time `gorm:"index" json:"endedAt"`
Notes string `gorm:"size:1000" json:"notes"`
Source string `gorm:"size:32;not null;default:timer" json:"source"`
}
type APIToken struct {
ID uint `gorm:"primaryKey" json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
UserID uint `gorm:"index;not null" json:"userId"`
User User `json:"-"`
Name string `gorm:"size:191;not null" json:"name"`
TokenHash string `gorm:"uniqueIndex;size:64;not null" json:"-"`
TokenHint string `gorm:"size:24;not null" json:"tokenHint"`
LastUsedAt *time.Time `json:"lastUsedAt"`
}