diff --git a/dbi/dashboard.go b/dbi/dashboard.go index 281567e..5088e07 100644 --- a/dbi/dashboard.go +++ b/dbi/dashboard.go @@ -6,25 +6,26 @@ import ( ) type DashboardItem struct { - UID string - Created string - LastName string - FirstName string - Title string - Description string - Hyperlink string - ItemType string + UID string + Created string + LastName string + FirstName string + Title string + Description string + Hyperlink string + DocumentLink string + ItemType string } func GetReportedItems(conn *sql.Conn) ([]DashboardItem, error) { rows, err := conn.QueryContext(context.Background(), ` - SELECT s.UID, s.Created, u.LastName, u.FirstName, '' AS Title, s.Citation AS Description, s.Hyperlink, 'Scholarship' + SELECT s.UID, s.Created, u.LastName, u.FirstName, '' AS Title, s.Citation AS Description, s.Hyperlink, s.DocumentLink, 'Scholarship' FROM scholarship s JOIN users u ON u.Username = s.Username WHERE s.Status = 'reported' UNION ALL - SELECT a.UID, a.Created, u.LastName, u.FirstName, a.Title, a.Description, a.Hyperlink, 'Activity' + SELECT a.UID, a.Created, u.LastName, u.FirstName, a.Title, a.Description, a.Hyperlink, '' AS DocumentLink, 'Activity' FROM activities a JOIN users u ON u.Username = a.Username WHERE a.Status = 'reported' UNION ALL - SELECT ap.UID, ap.Created, u.LastName, u.FirstName, ap.Title, ap.Description, ap.Hyperlink, 'Media Appearance' + SELECT ap.UID, ap.Created, u.LastName, u.FirstName, ap.Title, ap.Description, ap.Hyperlink, '' AS DocumentLink, 'Media Appearance' FROM appearances ap JOIN users u ON u.Username = ap.Username WHERE ap.Status = 'reported' ORDER BY Created DESC `) @@ -36,7 +37,7 @@ func GetReportedItems(conn *sql.Conn) ([]DashboardItem, error) { var items []DashboardItem for rows.Next() { var item DashboardItem - if err := rows.Scan(&item.UID, &item.Created, &item.LastName, &item.FirstName, &item.Title, &item.Description, &item.Hyperlink, &item.ItemType); err != nil { + if err := rows.Scan(&item.UID, &item.Created, &item.LastName, &item.FirstName, &item.Title, &item.Description, &item.Hyperlink, &item.DocumentLink, &item.ItemType); err != nil { return nil, err } items = append(items, item) diff --git a/dbi/schema.go b/dbi/schema.go index 4f7bbbd..14bdb97 100644 --- a/dbi/schema.go +++ b/dbi/schema.go @@ -13,6 +13,7 @@ CREATE TABLE scholarship ( UID text PRIMARY KEY, Citation text, Hyperlink text, + DocumentLink text, Status text not null CHECK (Status in ('reported','posted')), Created text, Modified text, diff --git a/dbi/scholarship.go b/dbi/scholarship.go index cbf91c5..8de93a7 100644 --- a/dbi/scholarship.go +++ b/dbi/scholarship.go @@ -8,13 +8,14 @@ import ( ) type Scholarship struct { - UID string `json:"uid"` - Citation string `json:"citation"` - Hyperlink string `json:"hyperlink"` - Status string `json:"status"` - Created string `json:"created"` - Modified string `json:"modified"` - Username string `json:"username"` + UID string `json:"uid"` + Citation string `json:"citation"` + Hyperlink string `json:"hyperlink"` + DocumentLink string `json:"document_link"` + Status string `json:"status"` + Created string `json:"created"` + Modified string `json:"modified"` + Username string `json:"username"` } func CreateScholarship(conn *sql.Conn, s *Scholarship) error { @@ -25,21 +26,21 @@ func CreateScholarship(conn *sql.Conn, s *Scholarship) error { s.Created = now s.Modified = now _, err := conn.ExecContext(context.Background(), - `INSERT INTO scholarship (UID, Citation, Hyperlink, Status, Created, Modified, Username) - VALUES (?, ?, ?, ?, ?, ?, ?)`, - s.UID, s.Citation, s.Hyperlink, s.Status, s.Created, s.Modified, s.Username, + `INSERT INTO scholarship (UID, Citation, Hyperlink, DocumentLink, Status, Created, Modified, Username) + VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, + s.UID, s.Citation, s.Hyperlink, s.DocumentLink, s.Status, s.Created, s.Modified, s.Username, ) return err } func GetScholarship(conn *sql.Conn, uid string) (Scholarship, error) { row := conn.QueryRowContext(context.Background(), - `SELECT UID, Citation, Hyperlink, Status, Created, Modified, Username + `SELECT UID, Citation, Hyperlink, DocumentLink, Status, Created, Modified, Username FROM scholarship WHERE UID = ?`, uid, ) var s Scholarship - err := row.Scan(&s.UID, &s.Citation, &s.Hyperlink, &s.Status, &s.Created, &s.Modified, &s.Username) + err := row.Scan(&s.UID, &s.Citation, &s.Hyperlink, &s.DocumentLink, &s.Status, &s.Created, &s.Modified, &s.Username) if err == sql.ErrNoRows { return Scholarship{}, fmt.Errorf("scholarship %q not found", uid) } @@ -49,9 +50,9 @@ func GetScholarship(conn *sql.Conn, uid string) (Scholarship, error) { func UpdateScholarship(conn *sql.Conn, s *Scholarship) error { s.Modified = GetNow() _, err := conn.ExecContext(context.Background(), - `UPDATE scholarship SET Citation = ?, Hyperlink = ?, Status = ?, Modified = ?, Username = ? + `UPDATE scholarship SET Citation = ?, Hyperlink = ?, DocumentLink = ?, Status = ?, Modified = ?, Username = ? WHERE UID = ?`, - s.Citation, s.Hyperlink, s.Status, s.Modified, s.Username, s.UID, + s.Citation, s.Hyperlink, s.DocumentLink, s.Status, s.Modified, s.Username, s.UID, ) return err } @@ -66,7 +67,7 @@ func DeleteScholarship(conn *sql.Conn, uid string) error { func GetScholarshipsForUsername(conn *sql.Conn, username string) ([]Scholarship, error) { rows, err := conn.QueryContext(context.Background(), - `SELECT UID, Citation, Hyperlink, Status, Created, Modified, Username + `SELECT UID, Citation, Hyperlink, DocumentLink, Status, Created, Modified, Username FROM scholarship WHERE Username = ?`, username, ) @@ -78,7 +79,7 @@ func GetScholarshipsForUsername(conn *sql.Conn, username string) ([]Scholarship, var results []Scholarship for rows.Next() { var s Scholarship - if err := rows.Scan(&s.UID, &s.Citation, &s.Hyperlink, &s.Status, &s.Created, &s.Modified, &s.Username); err != nil { + if err := rows.Scan(&s.UID, &s.Citation, &s.Hyperlink, &s.DocumentLink, &s.Status, &s.Created, &s.Modified, &s.Username); err != nil { return nil, err } results = append(results, s) diff --git a/dbi/scholarship_test.go b/dbi/scholarship_test.go index acfd6f3..0505e53 100644 --- a/dbi/scholarship_test.go +++ b/dbi/scholarship_test.go @@ -6,10 +6,11 @@ import ( func genScholarship(username string) Scholarship { return Scholarship{ - Citation: randString(40), - Hyperlink: "https://" + randString(12) + ".example.com", - Status: "reported", - Username: username, + Citation: randString(40), + Hyperlink: "https://" + randString(12) + ".example.com", + DocumentLink: "https://" + randString(12) + ".example.com/doc.pdf", + Status: "reported", + Username: username, } } @@ -112,6 +113,7 @@ func TestUpdateScholarship(t *testing.T) { originalCreated := s.Created s.Citation = randString(40) s.Hyperlink = "https://" + randString(12) + ".example.com" + s.DocumentLink = "https://" + randString(12) + ".example.com/updated.pdf" s.Status = "posted" if err := UpdateScholarship(conn, &s); err != nil { @@ -131,6 +133,9 @@ func TestUpdateScholarship(t *testing.T) { if got.Citation != s.Citation { t.Errorf("Citation not updated: got %q, want %q", got.Citation, s.Citation) } + if got.DocumentLink != s.DocumentLink { + t.Errorf("DocumentLink not updated: got %q, want %q", got.DocumentLink, s.DocumentLink) + } if got.Status != "posted" { t.Errorf("Status not updated: got %q", got.Status) } diff --git a/pages/dashboard.go b/pages/dashboard.go index 991be2d..68e8f00 100644 --- a/pages/dashboard.go +++ b/pages/dashboard.go @@ -64,7 +64,8 @@ var dashboardTmpl = template.Must(template.New("dashboard").Parse(`Title