Refactor default install records and add test campaign

This commit is contained in:
Kailash Nadh 2019-07-04 14:47:33 +05:30
parent 1ca8c2faf2
commit 69e5e351e0
1 changed files with 25 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"strings" "strings"
"time"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/knadh/goyesql" "github.com/knadh/goyesql"
@ -57,9 +58,9 @@ func install(app *App, qMap goyesql.Queries) {
// Sample subscriber. // Sample subscriber.
if _, err := q.UpsertSubscriber.Exec( if _, err := q.UpsertSubscriber.Exec(
uuid.NewV4(), uuid.NewV4(),
"test@test.com", "john@example.com",
"Test Subscriber", "John Doe",
`{"type": "known", "good": true}`, `{"type": "known", "good": true, "city": "Bengaluru"}`,
pq.Int64Array{int64(listID)}, pq.Int64Array{int64(listID)},
); err != nil { ); err != nil {
logger.Fatalf("Error creating subscriber: %v", err) logger.Fatalf("Error creating subscriber: %v", err)
@ -76,10 +77,29 @@ func install(app *App, qMap goyesql.Queries) {
"Default template", "Default template",
string(tplBody), string(tplBody),
); err != nil { ); err != nil {
logger.Fatalf("Error creating default template: %v", err) logger.Fatalf("error creating default template: %v", err)
} }
if _, err := q.SetDefaultTemplate.Exec(tplID); err != nil { if _, err := q.SetDefaultTemplate.Exec(tplID); err != nil {
logger.Fatalf("Error setting default template: %v", err) logger.Fatalf("error setting default template: %v", err)
}
// Sample campaign.
sendAt := time.Now()
sendAt.Add(time.Minute * 43200)
if _, err := q.CreateCampaign.Exec(uuid.NewV4(),
"Test campaign",
"Welcome to listmonk",
"noreply@yoursite.com",
`<h3>Hi {{ .Subscriber.FirstName }}!</h3>
This is a test e-mail campaign. Your second name is {{ .Subscriber.LastName }} and you are from {{ .Subscriber.Attribs.city }}.`,
"richtext",
sendAt,
pq.StringArray{"test-campaign"},
"email",
1,
pq.Int64Array{1},
); err != nil {
logger.Fatalf("error creating sample campaign: %v", err)
} }
logger.Printf("Setup complete") logger.Printf("Setup complete")