2016-12-03 13:45:08 +00:00
|
|
|
package main
|
2017-01-26 13:37:50 +00:00
|
|
|
import "database/sql"
|
|
|
|
import _ "github.com/go-sql-driver/mysql"
|
2016-12-03 13:45:08 +00:00
|
|
|
|
|
|
|
type Forum struct
|
|
|
|
{
|
|
|
|
ID int
|
|
|
|
Name string
|
2016-12-06 10:26:48 +00:00
|
|
|
Active bool
|
2017-01-26 13:37:50 +00:00
|
|
|
TopicCount int
|
2016-12-03 13:45:08 +00:00
|
|
|
LastTopic string
|
|
|
|
LastTopicID int
|
|
|
|
LastReplyer string
|
|
|
|
LastReplyerID int
|
|
|
|
LastTopicTime string
|
|
|
|
}
|
2016-12-04 10:44:28 +00:00
|
|
|
|
|
|
|
type ForumSimple struct
|
|
|
|
{
|
|
|
|
ID int
|
|
|
|
Name string
|
2016-12-07 09:34:09 +00:00
|
|
|
Active bool
|
2017-01-01 15:45:43 +00:00
|
|
|
}
|
2017-01-26 13:37:50 +00:00
|
|
|
|
|
|
|
func create_forum(forum_name string, active bool) (int, error) {
|
|
|
|
var fid int
|
|
|
|
err := forum_entry_exists_stmt.QueryRow().Scan(&fid)
|
|
|
|
if err != nil && err != sql.ErrNoRows {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
if err != sql.ErrNoRows {
|
|
|
|
_, err = update_forum_stmt.Exec(forum_name, active, fid)
|
|
|
|
if err != nil {
|
|
|
|
return fid, err
|
|
|
|
}
|
|
|
|
forums[fid].Name = forum_name
|
|
|
|
forums[fid].Active = active
|
|
|
|
return fid, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := create_forum_stmt.Exec(forum_name, active)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
fid64, err := res.LastInsertId()
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2017-02-04 06:19:55 +00:00
|
|
|
fid = int(fid64)
|
2017-01-26 13:37:50 +00:00
|
|
|
|
2017-02-04 06:19:55 +00:00
|
|
|
forums = append(forums, Forum{fid,forum_name,active,0,"",0,"",0,""})
|
2017-01-26 13:37:50 +00:00
|
|
|
return fid, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func delete_forum(fid int) error {
|
|
|
|
_, err := delete_forum_stmt.Exec(fid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
forums[fid].Name = ""
|
|
|
|
return nil
|
|
|
|
}
|