2016-03-05 15:15:49 -06:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2022-03-17 07:07:20 -05:00
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
2016-03-14 05:12:52 -05:00
|
|
|
"time"
|
2016-03-05 15:15:49 -06:00
|
|
|
)
|
|
|
|
|
2022-03-17 07:07:20 -05:00
|
|
|
type NavLink struct {
|
|
|
|
Id string `json:"id,omitempty"`
|
|
|
|
Text string `json:"text,omitempty"`
|
|
|
|
Url string `json:"url,omitempty"`
|
|
|
|
Target string `json:"target,omitempty"`
|
|
|
|
}
|
|
|
|
|
2016-03-06 05:47:39 -06:00
|
|
|
type Preferences struct {
|
2016-03-15 16:49:52 -05:00
|
|
|
Id int64
|
|
|
|
OrgId int64
|
|
|
|
UserId int64
|
2018-11-12 13:01:53 -06:00
|
|
|
TeamId int64
|
2016-03-15 16:49:52 -05:00
|
|
|
Version int
|
|
|
|
HomeDashboardId int64
|
|
|
|
Timezone string
|
2021-10-18 08:27:14 -05:00
|
|
|
WeekStart string
|
2016-03-15 16:49:52 -05:00
|
|
|
Theme string
|
|
|
|
Created time.Time
|
|
|
|
Updated time.Time
|
2022-03-17 07:07:20 -05:00
|
|
|
JsonData *PreferencesJsonData
|
|
|
|
}
|
|
|
|
|
|
|
|
// The following needed for to implement the xorm/database ORM Conversion interface do the
|
|
|
|
// conversion when reading/writing to the database, see https://gobook.io/read/gitea.com/xorm/manual-en-US/chapter-02/4.columns.html.
|
|
|
|
|
|
|
|
func (j *PreferencesJsonData) FromDB(data []byte) error {
|
|
|
|
dec := json.NewDecoder(bytes.NewBuffer(data))
|
|
|
|
dec.UseNumber()
|
|
|
|
return dec.Decode(j)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *PreferencesJsonData) ToDB() ([]byte, error) {
|
|
|
|
if j == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return json.Marshal(j)
|
|
|
|
}
|
|
|
|
|
|
|
|
type NavbarPreference struct {
|
|
|
|
SavedItems []NavLink `json:"savedItems"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type PreferencesJsonData struct {
|
|
|
|
Navbar NavbarPreference `json:"navbar"`
|
2016-03-05 15:15:49 -06:00
|
|
|
}
|
|
|
|
|
2016-03-06 13:42:15 -06:00
|
|
|
// ---------------------
|
|
|
|
// QUERIES
|
|
|
|
|
|
|
|
type GetPreferencesQuery struct {
|
2016-03-11 08:30:05 -06:00
|
|
|
Id int64
|
|
|
|
OrgId int64
|
2016-03-14 05:12:52 -05:00
|
|
|
UserId int64
|
2018-11-12 13:01:53 -06:00
|
|
|
TeamId int64
|
2016-03-06 13:42:15 -06:00
|
|
|
|
2016-03-06 14:32:22 -06:00
|
|
|
Result *Preferences
|
2016-03-06 13:42:15 -06:00
|
|
|
}
|
|
|
|
|
2016-04-02 15:54:06 -05:00
|
|
|
type GetPreferencesWithDefaultsQuery struct {
|
2018-11-12 13:01:53 -06:00
|
|
|
User *SignedInUser
|
2016-04-02 15:54:06 -05:00
|
|
|
|
|
|
|
Result *Preferences
|
|
|
|
}
|
|
|
|
|
2016-03-05 15:15:49 -06:00
|
|
|
// ---------------------
|
|
|
|
// COMMANDS
|
2016-03-06 05:47:39 -06:00
|
|
|
type SavePreferencesCommand struct {
|
2016-03-15 16:49:52 -05:00
|
|
|
UserId int64
|
|
|
|
OrgId int64
|
2018-11-12 13:01:53 -06:00
|
|
|
TeamId int64
|
2016-03-06 13:42:15 -06:00
|
|
|
|
2022-03-17 07:07:20 -05:00
|
|
|
HomeDashboardId int64 `json:"homeDashboardId,omitempty"`
|
|
|
|
Timezone string `json:"timezone,omitempty"`
|
|
|
|
WeekStart string `json:"weekStart,omitempty"`
|
|
|
|
Theme string `json:"theme,omitempty"`
|
|
|
|
Navbar *NavbarPreference `json:"navbar,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type PatchPreferencesCommand struct {
|
|
|
|
UserId int64
|
|
|
|
OrgId int64
|
|
|
|
TeamId int64
|
|
|
|
|
|
|
|
HomeDashboardId *int64 `json:"homeDashboardId,omitempty"`
|
|
|
|
Timezone *string `json:"timezone,omitempty"`
|
|
|
|
WeekStart *string `json:"weekStart,omitempty"`
|
|
|
|
Theme *string `json:"theme,omitempty"`
|
|
|
|
Navbar *NavbarPreference `json:"navbar,omitempty"`
|
2016-03-06 13:42:15 -06:00
|
|
|
}
|