ctdo.de/events.go

76 lines
1.4 KiB
Go
Raw Normal View History

package main
func getEvents() []event {
2023-01-28 18:52:41 +00:00
db := ctdoConnect()
2023-01-29 14:39:38 +00:00
defer dbClose(db)
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()
2023-01-29 14:39:38 +00:00
defer dbClose(db)
2023-01-28 22:09:31 +00:00
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()
2023-01-29 14:39:38 +00:00
defer dbClose(db)
2023-01-28 18:52:41 +00:00
2023-01-29 14:39:38 +00:00
if len(Event.title) > 80 || len(Event.description) > 500 || len(Event.media) == 10000 || len(Event.date) > 10 {
2023-01-28 18:52:41 +00:00
return false
}
2023-01-29 14:54:38 +00:00
sqlString := "insert into events (title, description, media, date) values ('" + sqlClean(Event.title) + "', '" + sqlClean(Event.description) + "', '" + sqlClean(Event.media) + "', '" + sqlClean(Event.date) + "');"
2023-01-29 14:39:38 +00:00
2023-01-29 14:54:38 +00:00
dbQuerry(db, sqlString)
2023-01-28 18:52:41 +00:00
return true
}
func getAdminKeys() []string {
db := ctdoConnect()
2023-01-29 14:39:38 +00:00
defer dbClose(db)
2023-01-28 18:52:41 +00:00
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
}