Refactor models.SubscriberAttribs
JSON wrapper to generic name JSON
.
This commit is contained in:
parent
db2fd9ad70
commit
c3d04a5490
5 changed files with 15 additions and 15 deletions
|
@ -53,7 +53,7 @@ var (
|
|||
Email: "demo@listmonk.app",
|
||||
Name: "Demo Subscriber",
|
||||
UUID: dummyUUID,
|
||||
Attribs: models.SubscriberAttribs{"city": "Bengaluru"},
|
||||
Attribs: models.JSON{"city": "Bengaluru"},
|
||||
}
|
||||
|
||||
subQuerySortFields = []string{"email", "name", "created_at", "updated_at"}
|
||||
|
|
|
@ -37,7 +37,7 @@ type recipient struct {
|
|||
UUID string `json:"uuid"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Attribs models.SubscriberAttribs `json:"attribs"`
|
||||
Attribs models.JSON `json:"attribs"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
|
|
|
@ -513,7 +513,7 @@ func easyjsonDf11841fDecodeGithubComKnadhListmonkInternalMessengerPostback1(in *
|
|||
in.Skip()
|
||||
} else {
|
||||
in.Delim('{')
|
||||
out.Attribs = make(models.SubscriberAttribs)
|
||||
out.Attribs = make(models.JSON)
|
||||
for !in.IsDelim('}') {
|
||||
key := string(in.String())
|
||||
in.WantColon()
|
||||
|
|
|
@ -536,7 +536,7 @@ func (s *Session) LoadCSV(srcPath string, delim rune) error {
|
|||
// JSON attributes.
|
||||
if len(row["attributes"]) > 0 {
|
||||
var (
|
||||
attribs models.SubscriberAttribs
|
||||
attribs models.JSON
|
||||
b = []byte(row["attributes"])
|
||||
)
|
||||
if err := json.Unmarshal(b, &attribs); err != nil {
|
||||
|
|
|
@ -157,12 +157,12 @@ type User struct {
|
|||
type Subscriber struct {
|
||||
Base
|
||||
|
||||
UUID string `db:"uuid" json:"uuid"`
|
||||
Email string `db:"email" json:"email" form:"email"`
|
||||
Name string `db:"name" json:"name" form:"name"`
|
||||
Attribs SubscriberAttribs `db:"attribs" json:"attribs"`
|
||||
Status string `db:"status" json:"status"`
|
||||
Lists types.JSONText `db:"lists" json:"lists"`
|
||||
UUID string `db:"uuid" json:"uuid"`
|
||||
Email string `db:"email" json:"email" form:"email"`
|
||||
Name string `db:"name" json:"name" form:"name"`
|
||||
Attribs JSON `db:"attribs" json:"attribs"`
|
||||
Status string `db:"status" json:"status"`
|
||||
Lists types.JSONText `db:"lists" json:"lists"`
|
||||
}
|
||||
type subLists struct {
|
||||
SubscriberID int `db:"subscriber_id"`
|
||||
|
@ -178,8 +178,8 @@ type SubscriberExportProfile struct {
|
|||
LinkClicks json.RawMessage `db:"link_clicks" json:"link_clicks,omitempty"`
|
||||
}
|
||||
|
||||
// SubscriberAttribs is the map of key:value attributes of a subscriber.
|
||||
type SubscriberAttribs map[string]interface{}
|
||||
// JSON is is the wrapper for reading and writing arbitrary JSONB fields from the DB.
|
||||
type JSON map[string]interface{}
|
||||
|
||||
// StringIntMap is used to define DB Scan()s.
|
||||
type StringIntMap map[string]int
|
||||
|
@ -398,14 +398,14 @@ func (subs Subscribers) LoadLists(stmt *sqlx.Stmt) error {
|
|||
}
|
||||
|
||||
// Value returns the JSON marshalled SubscriberAttribs.
|
||||
func (s SubscriberAttribs) Value() (driver.Value, error) {
|
||||
func (s JSON) Value() (driver.Value, error) {
|
||||
return json.Marshal(s)
|
||||
}
|
||||
|
||||
// Scan unmarshals JSONB from the DB.
|
||||
func (s SubscriberAttribs) Scan(src interface{}) error {
|
||||
func (s JSON) Scan(src interface{}) error {
|
||||
if src == nil {
|
||||
s = make(SubscriberAttribs)
|
||||
s = make(JSON)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue