Refactor models.SubscriberAttribs JSON wrapper to generic name JSON.

This commit is contained in:
Kailash Nadh 2022-10-02 22:53:38 +05:30
parent db2fd9ad70
commit c3d04a5490
5 changed files with 15 additions and 15 deletions

View file

@ -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"}

View file

@ -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"`
}

View file

@ -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()

View file

@ -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 {

View file

@ -160,7 +160,7 @@ type Subscriber struct {
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"`
Attribs JSON `db:"attribs" json:"attribs"`
Status string `db:"status" json:"status"`
Lists types.JSONText `db:"lists" json:"lists"`
}
@ -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
}