ctdo.de/events.go

70 lines
1.2 KiB
Go
Raw Normal View History

package main
func getEvents() []event {
2023-01-28 18:52:41 +00:00
db := ctdoConnect()
rows := dbQuerry(db, "SELECT * FROM events;")
events := []event{}
for rows.Next() {
Event := new(event)
2023-01-28 17:41:04 +00:00
err := rows.Scan(&Event.id, &Event.title, &Event.description, &Event.media, &Event.date)
if err != nil {
2023-01-28 17:44:11 +00:00
panic(err.Error())
}
events = append(events, *Event)
}
return events
}
2023-01-28 18:52:41 +00:00
2023-01-28 22:09:31 +00:00
func getEventCount() int {
db := ctdoConnect()
row := dbQuerry(db, "SELECT COUNT(*) FROM events;")
count := 0
for row.Next() {
row.Scan(&count)
}
return count
}
2023-01-28 18:52:41 +00:00
func addEvent(Event event) bool {
db := ctdoConnect()
if len(Event.title) > 80 || len(Event.description) > 500 || len(Event.media) > 10000 || len(Event.date) > 10 {
return false
}
dbQuerry(db, "insert into events (title, description, media, date) values ('"+Event.title+"', '"+Event.description+"', '"+Event.media+"', '"+Event.date+"');")
return true
}
func getAdminKeys() []string {
db := ctdoConnect()
rows := dbQuerry(db, "select * from adminKeys;")
output := []string{}
for rows.Next() {
temp := ""
2023-01-28 19:02:24 +00:00
err := rows.Scan(&temp)
2023-01-28 18:52:41 +00:00
if err != nil {
panic(err.Error())
}
output = append(output, temp)
}
if len(output) == 0 {
return nil
}
return output
}