add stray dbi files
parent
0fe34ddb61
commit
8e0565293f
@ -0,0 +1,45 @@
|
||||
package dbi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type DashboardItem struct {
|
||||
UID string
|
||||
Created string
|
||||
LastName string
|
||||
FirstName string
|
||||
Title string
|
||||
Description string
|
||||
Hyperlink 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'
|
||||
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'
|
||||
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'
|
||||
FROM appearances ap JOIN users u ON u.Username = ap.Username WHERE ap.Status = 'reported'
|
||||
ORDER BY Created DESC
|
||||
`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, item)
|
||||
}
|
||||
return items, rows.Err()
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package dbi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func MarkPosted(conn *sql.Conn, uid string) error {
|
||||
for _, table := range []string{"scholarship", "activities", "appearances"} {
|
||||
res, err := conn.ExecContext(context.Background(),
|
||||
"UPDATE "+table+" SET Status = 'posted' WHERE UID = ? AND Status = 'reported'",
|
||||
uid,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if n > 0 {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("UID %q not found among reported items", uid)
|
||||
}
|
||||
Loading…
Reference in New Issue