aboutsummaryrefslogtreecommitdiff
path: root/database.go
diff options
context:
space:
mode:
authorknotteye <knotteye@airmail.cc>2021-07-01 17:56:04 -0500
committerknotteye <knotteye@airmail.cc>2021-07-01 17:56:04 -0500
commit4e3848cadbb3fd89b94a7ef24838173939d198db (patch)
tree06ea5434986b2b9c00e392a7d44b93d7eae23668 /database.go
parent638a03b458b71564b1db439e6386d7dbf2a5181c (diff)
Add a list of local boards and server news
Diffstat (limited to 'database.go')
-rw-r--r--database.go42
1 files changed, 40 insertions, 2 deletions
diff --git a/database.go b/database.go
index 9d5d721..5fcebf0 100644
--- a/database.go
+++ b/database.go
@@ -7,11 +7,12 @@ import "time"
import "os"
import "strings"
import "sort"
+import "container/list"
func GetActorFromDB(db *sql.DB, id string) Actor {
- var nActor Actor
+ var nActor Actor
- query :=`select type, id, name, preferedusername, inbox, outbox, following, followers, restricted, summary, publickeypem from actor where id=$1`
+ query :=`select type, id, name, preferedusername, inbox, outbox, following, followers, restricted, summary, publickeypem from actor where id=$1`
rows, err := db.Query(query, id)
@@ -1488,3 +1489,40 @@ func MarkObjectSensitive(db *sql.DB, id string, sensitive bool) {
CheckError(err, "error updating sensitive object in cacheactivitystream")
}
+
+func getNewsFromDB(db *sql.DB) []NewsItem {
+ news := list.New()
+ query :=`select title, content, time from newsItem order by time desc`
+
+ rows, err := db.Query(query)
+
+ if CheckError(err, "could not get news from db query") != nil {
+ return make([]NewsItem, 0)
+ }
+
+ defer rows.Close()
+ for rows.Next() {
+ n := NewsItem{}
+ err = rows.Scan(&n.Title, &n.Content, &n.Time)
+ news.PushBack(n)
+ }
+
+ anews := make([]NewsItem, news.Len())
+
+ i:=0
+ for e := news.Front(); e != nil; e = e.Next() {
+ assert := e.Value.(NewsItem)
+ anews[i] = assert
+ i++
+ }
+
+ return anews
+}
+
+func WriteNewsToDB(db *sql.DB, news NewsItem) {
+ query := `insert into newsItem (title, content, time) values ($1, $2, $3)`
+
+ _, err := db.Exec(query, news.Title, news.Content, time.Now().Unix())
+
+ CheckError(err, "error writing news item")
+}