shiori/internal/model/account.go
Monirzadeh 2a231ecc37
feat: allow selecting light/dark/follow themes in the webui (#924)
* login page follow browser darkmode settings

* theme change based on selection in settings between follw system , light, dark

* content page follow settings and fix syntax error

* drop down menu color follow current theme

* version number follow theme in login page

* use footer instead of id for version

* replace space with tab

* move theme settings to the top of the list and fix typo

* remove duplicate code and use a function instead

* fix logic of change theme if you select follow system to not need reload anymore

* fix code style with make styles

* fix bug that eventlistener not remove when activate light or dark theme

* less js and add theme with patch by @fmartingr

* remove NightMode config and now everythings control with Theme

* error instead of log if invalid theme selected

Co-authored-by: Felipe Martin <812088+fmartingr@users.noreply.github.com>

* remove unneeded part and update swagger documents

---------

Co-authored-by: Felipe Martin <812088+fmartingr@users.noreply.github.com>
2024-06-06 10:44:43 +02:00

63 lines
1.5 KiB
Go

package model
import (
"database/sql/driver"
"encoding/json"
"fmt"
)
// Account is the database model for account.
type Account struct {
ID int `db:"id" json:"id"`
Username string `db:"username" json:"username"`
Password string `db:"password" json:"password,omitempty"`
Owner bool `db:"owner" json:"owner"`
Config UserConfig `db:"config" json:"config"`
}
type UserConfig struct {
ShowId bool `json:"ShowId"`
ListMode bool `json:"ListMode"`
HideThumbnail bool `json:"HideThumbnail"`
HideExcerpt bool `json:"HideExcerpt"`
Theme string `json:"Theme"`
KeepMetadata bool `json:"KeepMetadata"`
UseArchive bool `json:"UseArchive"`
CreateEbook bool `json:"CreateEbook"`
MakePublic bool `json:"MakePublic"`
}
func (c *UserConfig) Scan(value interface{}) error {
switch v := value.(type) {
case []byte:
json.Unmarshal(v, &c)
return nil
case string:
json.Unmarshal([]byte(v), &c)
return nil
default:
return fmt.Errorf("unsupported type: %T", v)
}
}
func (c UserConfig) Value() (driver.Value, error) {
return json.Marshal(c)
}
// ToDTO converts Account to AccountDTO.
func (a Account) ToDTO() AccountDTO {
return AccountDTO{
ID: a.ID,
Username: a.Username,
Owner: a.Owner,
Config: a.Config,
}
}
// AccountDTO is data transfer object for Account.
type AccountDTO struct {
ID int `json:"id"`
Username string `json:"username"`
Owner bool `json:"owner"`
Config UserConfig `json:"config"`
}