Skip to content

Commit

Permalink
Refactor models.SubscriberAttribs JSON wrapper to generic name JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Oct 2, 2022
1 parent db2fd9a commit c3d04a5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/subscribers.go
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion internal/messenger/postback/postback.go
Expand Up @@ -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"`
}

Expand Down
2 changes: 1 addition & 1 deletion internal/messenger/postback/postback_easyjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/subimporter/importer.go
Expand Up @@ -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 {
Expand Down
22 changes: 11 additions & 11 deletions models/models.go
Expand Up @@ -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"`
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit c3d04a5

Please sign in to comment.