From 01901c9008d4d34f78ef5ade2ae46f44fac69a75 Mon Sep 17 00:00:00 2001 From: Jordan Date: Sat, 21 Jun 2014 12:19:49 -0500 Subject: [PATCH] Decoupling campaign.go a bit Added #!/campaigns route so that #!/ can be used for a dashboard in the future --- controllers/api.go | 26 ------------------- models/campaign.go | 14 ++++++++++ static/js/app/partials/campaign_results.html | 2 ++ static/js/app/partials/campaigns.html | 6 +++-- .../js/app/partials/modals/campaignModal.html | 4 +-- static/js/app/partials/settings.html | 2 ++ static/js/app/partials/templates.html | 2 ++ static/js/app/partials/users.html | 2 ++ templates/base.html | 2 ++ 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/controllers/api.go b/controllers/api.go index a64bdacc..3d0db708 100644 --- a/controllers/api.go +++ b/controllers/api.go @@ -73,11 +73,6 @@ func API_Campaigns(w http.ResponseWriter, r *http.Request) { http.Error(w, "Error: "+m, http.StatusBadRequest) return } - // Fill in the details - c.CreatedDate = time.Now() - c.CompletedDate = time.Time{} - c.Status = models.QUEUED - c.UserId = ctx.Get(r, "user_id").(int64) err = models.PostCampaign(&c, ctx.Get(r, "user_id").(int64)) if checkError(err, w, "Cannot insert campaign into database", http.StatusInternalServerError) { return @@ -110,27 +105,6 @@ func API_Campaigns_Id(w http.ResponseWriter, r *http.Request) { // API_Groups returns details about the requested group. If the campaign is not // valid, API_Groups returns null. -// Example: -/* -POST /api/groups - { "name" : "Test Group", - "targets" : [ - { - "email" : "test@example.com" - }, - { "email" : test2@example.com" - }] - } - -RESULT { "name" : "Test Group", - "targets" : [ - { - "email" : "test@example.com" - }, - { "email" : test2@example.com" - }] - } -*/ func API_Groups(w http.ResponseWriter, r *http.Request) { switch { case r.Method == "GET": diff --git a/models/campaign.go b/models/campaign.go index ea605e88..7e8f35b1 100644 --- a/models/campaign.go +++ b/models/campaign.go @@ -20,6 +20,7 @@ type Campaign struct { EmailsSent string `json:"emails_sent"` Results []Result `json:"results,omitempty"` Groups []Group `json:"groups,omitempty"` + Events []Event `json:"timeline,omitemtpy"` SMTP SMTP `json:"smtp"` } @@ -42,6 +43,14 @@ type Result struct { Status string `json:"status" sql:"not null"` } +type Event struct { + Id int64 `json:"-"` + CampaignId int64 `json:"-"` + Email string `json:"email"` + Time time.Time `json:"time"` + Message time.Time `json:"message"` +} + // GetCampaigns returns the campaigns owned by the given user. func GetCampaigns(uid int64) ([]Campaign, error) { cs := []Campaign{} @@ -71,6 +80,11 @@ func GetCampaign(id int64, uid int64) (Campaign, error) { // PostCampaign inserts a campaign and all associated records into the database. func PostCampaign(c *Campaign, uid int64) error { + // Fill in the details + c.CreatedDate = time.Now() + c.CompletedDate = time.Time{} + c.Status = QUEUED + c.Events = append(c.Events) // Check to make sure all the groups already exist for i, g := range c.Groups { c.Groups[i], err = GetGroupByName(g.Name, uid) diff --git a/static/js/app/partials/campaign_results.html b/static/js/app/partials/campaign_results.html index ec3d7f8d..78652449 100644 --- a/static/js/app/partials/campaign_results.html +++ b/static/js/app/partials/campaign_results.html @@ -4,6 +4,8 @@