From b3e411c54c70616fb7ef6daa8fa9355da482a212 Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 18 Mar 2014 18:08:17 -0500 Subject: [PATCH] Adding DB table for template attachments (coming soon) Cleanup API docs for campaigns Added "omitempty" for Campaign model --- db/db.go | 10 ++++- models/models.go | 4 +- static/api-doc/resources/campaigns | 61 +++--------------------------- templates/users.html | 8 ++-- 4 files changed, 20 insertions(+), 63 deletions(-) diff --git a/db/db.go b/db/db.go index c7b920a5..49d03af0 100644 --- a/db/db.go +++ b/db/db.go @@ -40,11 +40,13 @@ func Setup() error { `CREATE TABLE targets (id INTEGER PRIMARY KEY AUTOINCREMENT, email TEXT NOT NULL, UNIQUE(email));`, `CREATE TABLE groups (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, modified_date TIMESTAMP NOT NULL);`, `CREATE TABLE campaign_results (cid INTEGER NOT NULL, email TEXT NOT NULL, status TEXT NOT NULL, FOREIGN KEY (cid) REFERENCES campaigns(id), UNIQUE(cid, email, status))`, + `CREATE TABLE templates (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, modified_date TIMESTAMP NOT NULL, html TEXT NOT NULL, text TEXT NOT NULL);`, + `CREATE TABLE files (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, path TEXT NOT NULL);`, `CREATE TABLE user_campaigns (uid INTEGER NOT NULL, cid INTEGER NOT NULL, FOREIGN KEY (uid) REFERENCES users(id), FOREIGN KEY (cid) REFERENCES campaigns(id), UNIQUE(uid, cid))`, `CREATE TABLE user_groups (uid INTEGER NOT NULL, gid INTEGER NOT NULL, FOREIGN KEY (uid) REFERENCES users(id), FOREIGN KEY (gid) REFERENCES groups(id), UNIQUE(uid, gid))`, `CREATE TABLE group_targets (gid INTEGER NOT NULL, tid INTEGER NOT NULL, FOREIGN KEY (gid) REFERENCES groups(id), FOREIGN KEY (tid) REFERENCES targets(id), UNIQUE(gid, tid));`, - `CREATE TABLE templates (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, modified_date TIMESTAMP NOT NULL, html TEXT NOT NULL, text TEXT NOT NULL);`, `CREATE TABLE user_templates (uid INTEGER NOT NULL, tid INTEGER NOT NULL, FOREIGN KEY (uid) REFERENCES users(id), FOREIGN KEY (tid) REFERENCES templates(id), UNIQUE(uid, tid));`, + `CREATE TABLE template_files (tid INTEGER NOT NULL, fid INTEGER NOT NULL, FOREIGN KEY (tid) REFERENCES templates(id), FOREIGN KEY(fid) REFERENCES files(id), UNIQUE(tid, fid));`, } Logger.Printf("Creating db at %s\n", config.Conf.DBPath) //Create the tables needed @@ -220,7 +222,7 @@ func GetGroup(id int64, uid int64) (models.Group, error) { return g, nil } -// GetGroup returns the group, if it exists, specified by the given name and user_id. +// GetGroupByName returns the group, if it exists, specified by the given name and user_id. func GetGroupByName(n string, uid int64) (models.Group, error) { g := models.Group{} err := Conn.SelectOne(&g, "SELECT g.id, g.name, g.modified_date FROM groups g, user_groups ug, users u WHERE ug.uid=u.id AND ug.gid=g.id AND g.name=? AND u.id=?", n, uid) @@ -338,6 +340,10 @@ func PostTemplate(t *models.Template, uid int64) error { return nil } +func PutTemplate(t *models.Template, uid int64) error { + return nil +} + func insertTargetIntoGroup(t models.Target, gid int64) error { if _, err = mail.ParseAddress(t.Email); err != nil { Logger.Printf("Invalid email %s\n", t.Email) diff --git a/models/models.go b/models/models.go index c4c60ddc..fb4f354a 100644 --- a/models/models.go +++ b/models/models.go @@ -40,8 +40,8 @@ type Campaign struct { CompletedDate time.Time `json:"completed_date" db:"completed_date"` Template string `json:"template"` //This may change Status string `json:"status"` - Results []Result `json:"results" db:"-"` - Groups []Group `json:"groups" db:"-"` + Results []Result `json:"results,omitempty" db:"-"` + Groups []Group `json:"groups,omitempty" db:"-"` } type Result struct { diff --git a/static/api-doc/resources/campaigns b/static/api-doc/resources/campaigns index 08f67d9d..9bdf9885 100644 --- a/static/api-doc/resources/campaigns +++ b/static/api-doc/resources/campaigns @@ -145,8 +145,8 @@ "Result": { "id": "Result", "properties": { - "target": { - "$ref": "Target" + "email": { + "type": "string" }, "status": { "type": "string" @@ -192,66 +192,15 @@ "targets": { "type" : "array", "items" : { - "$ref" : "Target" + "email" : { + "type" : "string" + } } }, "modified_date": { "type" : "date" } } - }, - "Pet": { - "id": "Pet", - "description": "A pet is a person's best friend", - "required": [ - "name", - "id" - ], - "properties": { - "name": { - "type": "string" - }, - "tags": { - "type": "array", - "items": { - "$ref": "Tag" - } - }, - "photoUrls": { - "type": "array", - "items": { - "type": "string" - } - }, - "id": { - "type": "integer", - "format": "int64" - }, - "status": { - "type": "string", - "description": "pet status in the store", - "enum": [ - "available", - "pending", - "sold" - ] - }, - "category": { - "$ref": "Category" - } - } - }, - "Category": { - "id": "Category", - "properties": { - "name": { - "type": "string" - }, - "id": { - "type": "integer", - "format": "int64" - } - } } } } \ No newline at end of file diff --git a/templates/users.html b/templates/users.html index 9bacd1e8..81915190 100644 --- a/templates/users.html +++ b/templates/users.html @@ -69,9 +69,11 @@
-
- -
+
+
+ +
+