9075798128
Tweaked some bits to make them more 32-bit friendly for GopherJS, but this might not be necessary now. Added notice.html Added an alerts package to fix the import cycles, more things may be moved here soon. Saved a few lines of accumulator code in a few stores. Moved the AccountEditCriticalSubmit, AccountEditAvatar, AccountEditAvatarSubmit, AccountEditUsername, and AccountEditUsernameSubmit routes into the routes package. Added a QueryRow method to AccSelectBuilder. Tweaked the indentation in the generated templates. Simplified the template render in the AccountEditUsernameSubmit route into a redirect back to the previous page. Run the update script / patcher to replace the route names in the viewchunks table.
45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
package common
|
|
|
|
import "database/sql"
|
|
import "../query_gen/lib"
|
|
|
|
var Rstore ReplyStore
|
|
|
|
type ReplyStore interface {
|
|
Get(id int) (*Reply, error)
|
|
Create(topic *Topic, content string, ipaddress string, uid int) (id int, err error)
|
|
}
|
|
|
|
type SQLReplyStore struct {
|
|
get *sql.Stmt
|
|
create *sql.Stmt
|
|
}
|
|
|
|
func NewSQLReplyStore(acc *qgen.Accumulator) (*SQLReplyStore, error) {
|
|
return &SQLReplyStore{
|
|
get: acc.Select("replies").Columns("tid, content, createdBy, createdAt, lastEdit, lastEditBy, ipaddress, likeCount").Where("rid = ?").Prepare(),
|
|
create: acc.Insert("replies").Columns("tid, content, parsed_content, createdAt, lastUpdated, ipaddress, words, createdBy").Fields("?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?").Prepare(),
|
|
}, acc.FirstError()
|
|
}
|
|
|
|
func (store *SQLReplyStore) Get(id int) (*Reply, error) {
|
|
reply := Reply{ID: id}
|
|
err := store.get.QueryRow(id).Scan(&reply.ParentID, &reply.Content, &reply.CreatedBy, &reply.CreatedAt, &reply.LastEdit, &reply.LastEditBy, &reply.IPAddress, &reply.LikeCount)
|
|
return &reply, err
|
|
}
|
|
|
|
// TODO: Write a test for this
|
|
func (store *SQLReplyStore) Create(topic *Topic, content string, ipaddress string, uid int) (id int, err error) {
|
|
wcount := WordCount(content)
|
|
res, err := store.create.Exec(topic.ID, content, ParseMessage(content, topic.ParentID, "forums"), ipaddress, wcount, uid)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
lastID, err := res.LastInsertId()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return int(lastID), topic.AddReply(uid)
|
|
}
|