2023-07-20 00:25:41 +08:00
|
|
|
package model
|
|
|
|
|
2023-10-15 21:27:54 +08:00
|
|
|
import (
|
|
|
|
"database/sql/driver"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2023-07-20 00:25:41 +08:00
|
|
|
// Account is the database model for account.
|
|
|
|
type Account struct {
|
2023-10-15 21:27:54 +08:00
|
|
|
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"`
|
|
|
|
NightMode bool `json:"NightMode"`
|
|
|
|
KeepMetadata bool `json:"KeepMetadata"`
|
|
|
|
UseArchive bool `json:"UseArchive"`
|
2023-10-22 19:25:16 +08:00
|
|
|
CreateEbook bool `json:"CreateEbook"`
|
2023-10-15 21:27:54 +08:00
|
|
|
MakePublic bool `json:"MakePublic"`
|
2023-07-20 00:25:41 +08:00
|
|
|
}
|
|
|
|
|
2023-12-29 01:18:32 +08:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-07-20 00:25:41 +08:00
|
|
|
// ToDTO converts Account to AccountDTO.
|
|
|
|
func (a Account) ToDTO() AccountDTO {
|
|
|
|
return AccountDTO{
|
|
|
|
ID: a.ID,
|
|
|
|
Username: a.Username,
|
|
|
|
Owner: a.Owner,
|
2023-10-15 21:27:54 +08:00
|
|
|
Config: a.Config,
|
2023-07-20 00:25:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AccountDTO is data transfer object for Account.
|
|
|
|
type AccountDTO struct {
|
2023-10-15 21:27:54 +08:00
|
|
|
ID int `json:"id"`
|
|
|
|
Username string `json:"username"`
|
|
|
|
Owner bool `json:"owner"`
|
|
|
|
Config UserConfig `json:"config"`
|
|
|
|
}
|