mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-07 08:24:27 +00:00
Add db support for workspaces
This commit is contained in:
@@ -17,42 +17,30 @@ type UserSettings struct {
|
||||
GitCommitMsgTemplate string `json:"gitCommitMsgTemplate"`
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
UserID int `json:"userId" validate:"required,min=1"`
|
||||
Settings UserSettings `json:"settings" validate:"required"`
|
||||
}
|
||||
|
||||
var defaultUserSettings = UserSettings{
|
||||
Theme: "light",
|
||||
AutoSave: false,
|
||||
GitEnabled: false,
|
||||
GitCommitMsgTemplate: "Update ${filename}",
|
||||
type WorkspaceSettings struct {
|
||||
WorkspaceID int `json:"workspaceId" validate:"required,min=1"`
|
||||
Settings UserSettings `json:"settings" validate:"required"`
|
||||
}
|
||||
|
||||
var validate = validator.New()
|
||||
|
||||
func (s *Settings) Validate() error {
|
||||
func (s *UserSettings) Validate() error {
|
||||
return validate.Struct(s)
|
||||
}
|
||||
|
||||
func (s *Settings) SetDefaults() {
|
||||
if s.Settings.Theme == "" {
|
||||
s.Settings.Theme = defaultUserSettings.Theme
|
||||
}
|
||||
if s.Settings.GitCommitMsgTemplate == "" {
|
||||
s.Settings.GitCommitMsgTemplate = defaultUserSettings.GitCommitMsgTemplate
|
||||
}
|
||||
func (ws *WorkspaceSettings) Validate() error {
|
||||
return validate.Struct(ws)
|
||||
}
|
||||
|
||||
func (s *Settings) UnmarshalJSON(data []byte) error {
|
||||
type Alias Settings
|
||||
func (ws *WorkspaceSettings) UnmarshalJSON(data []byte) error {
|
||||
type Alias WorkspaceSettings
|
||||
aux := &struct {
|
||||
*Alias
|
||||
}{
|
||||
Alias: (*Alias)(s),
|
||||
Alias: (*Alias)(ws),
|
||||
}
|
||||
if err := json.Unmarshal(data, &aux); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.Validate()
|
||||
}
|
||||
return ws.Validate()
|
||||
}
|
||||
Reference in New Issue
Block a user