mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-07 00:14:25 +00:00
Combine settings and workspaces tables
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
type UserSettings struct {
|
||||
Theme string `json:"theme" validate:"oneof=light dark"`
|
||||
AutoSave bool `json:"autoSave"`
|
||||
GitEnabled bool `json:"gitEnabled"`
|
||||
GitURL string `json:"gitUrl" validate:"required_with=GitEnabled"`
|
||||
GitUser string `json:"gitUser" validate:"required_with=GitEnabled"`
|
||||
GitToken string `json:"gitToken" validate:"required_with=GitEnabled"`
|
||||
GitAutoCommit bool `json:"gitAutoCommit"`
|
||||
GitCommitMsgTemplate string `json:"gitCommitMsgTemplate"`
|
||||
}
|
||||
|
||||
type WorkspaceSettings struct {
|
||||
WorkspaceID int `json:"workspaceId" validate:"required,min=1"`
|
||||
Settings UserSettings `json:"settings" validate:"required"`
|
||||
}
|
||||
|
||||
var validate = validator.New()
|
||||
|
||||
func (s *UserSettings) Validate() error {
|
||||
return validate.Struct(s)
|
||||
}
|
||||
|
||||
func (ws *WorkspaceSettings) Validate() error {
|
||||
return validate.Struct(ws)
|
||||
}
|
||||
|
||||
func (ws *WorkspaceSettings) UnmarshalJSON(data []byte) error {
|
||||
type Alias WorkspaceSettings
|
||||
aux := &struct {
|
||||
*Alias
|
||||
}{
|
||||
Alias: (*Alias)(ws),
|
||||
}
|
||||
if err := json.Unmarshal(data, &aux); err != nil {
|
||||
return err
|
||||
}
|
||||
return ws.Validate()
|
||||
}
|
||||
@@ -2,8 +2,12 @@ package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
var validate = validator.New()
|
||||
|
||||
type UserRole string
|
||||
|
||||
const (
|
||||
|
||||
@@ -9,8 +9,29 @@ type Workspace struct {
|
||||
UserID int `json:"userId" validate:"required,min=1"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
|
||||
// Integrated settings
|
||||
Theme string `json:"theme" validate:"oneof=light dark"`
|
||||
AutoSave bool `json:"autoSave"`
|
||||
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"`
|
||||
}
|
||||
|
||||
func (w *Workspace) Validate() error {
|
||||
return validate.Struct(w)
|
||||
}
|
||||
|
||||
func (w *Workspace) GetDefaultSettings() {
|
||||
w.Theme = "light"
|
||||
w.AutoSave = false
|
||||
w.GitEnabled = false
|
||||
w.GitURL = ""
|
||||
w.GitUser = ""
|
||||
w.GitToken = ""
|
||||
w.GitAutoCommit = false
|
||||
w.GitCommitMsgTemplate = "${action} ${filename}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user