mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-05 15:44:21 +00:00
49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// Workspace represents a user's workspace in the system
|
|
type Workspace struct {
|
|
ID int `json:"id" validate:"required,min=1"`
|
|
UserID int `json:"userId" validate:"required,min=1"`
|
|
Name string `json:"name" validate:"required"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
LastOpenedFilePath string `json:"lastOpenedFilePath"`
|
|
|
|
// Integrated settings
|
|
Theme string `json:"theme" validate:"oneof=light dark"`
|
|
AutoSave bool `json:"autoSave"`
|
|
ShowHiddenFiles bool `json:"showHiddenFiles"`
|
|
GitEnabled bool `json:"gitEnabled"`
|
|
GitURL string `json:"gitUrl" validate:"required_if=GitEnabled true"`
|
|
GitUser string `json:"gitUser" validate:"required_if=GitEnabled true"`
|
|
GitToken string `json:"gitToken" validate:"required_if=GitEnabled true"`
|
|
GitAutoCommit bool `json:"gitAutoCommit"`
|
|
GitCommitMsgTemplate string `json:"gitCommitMsgTemplate"`
|
|
}
|
|
|
|
// Validate validates the workspace struct
|
|
func (w *Workspace) Validate() error {
|
|
return validate.Struct(w)
|
|
}
|
|
|
|
// SetDefaultSettings sets the default settings for the workspace
|
|
func (w *Workspace) SetDefaultSettings() {
|
|
|
|
if w.Theme == "" {
|
|
w.Theme = "light"
|
|
}
|
|
|
|
w.AutoSave = w.AutoSave || false
|
|
w.ShowHiddenFiles = w.ShowHiddenFiles || false
|
|
w.GitEnabled = w.GitEnabled || false
|
|
|
|
w.GitAutoCommit = w.GitEnabled && (w.GitAutoCommit || false)
|
|
|
|
if w.GitCommitMsgTemplate == "" {
|
|
w.GitCommitMsgTemplate = "${action} ${filename}"
|
|
}
|
|
}
|