Make threads openable from catalog
This commit is contained in:
@@ -28,12 +28,15 @@ func GetBoard(db *sql.DB, slug string) (Board, error) {
|
||||
row := db.QueryRow(`SELECT id, name, slug, tag FROM boards WHERE slug = ?`, slug)
|
||||
|
||||
var result Board
|
||||
row.Scan(&result.Id, &result.Name, &result.Slug, &result.Tag)
|
||||
err := row.Scan(&result.Id, &result.Name, &result.Slug, &result.Tag)
|
||||
if err != nil {
|
||||
return Board{}, err
|
||||
}
|
||||
|
||||
return result, row.Err()
|
||||
}
|
||||
|
||||
func GetBoardThreads(db *sql.DB, slug string) ([]Thread, error) {
|
||||
func GetThreads(db *sql.DB, slug string) ([]Thread, error) {
|
||||
rows, err := db.Query(
|
||||
`SELECT id, board_slug, subject, created_at, bumped_at FROM threads WHERE board_slug = ?`, slug)
|
||||
if err != nil {
|
||||
@@ -54,8 +57,20 @@ func GetBoardThreads(db *sql.DB, slug string) ([]Thread, error) {
|
||||
return result, rows.Err()
|
||||
}
|
||||
|
||||
func GetThreadPosts(db *sql.DB, thread_id int) ([]Post, error) {
|
||||
rows, err := db.Query(`SELECT id, thread_id, author, body, created_at FROM posts where thread_id = ?`, thread_id)
|
||||
func GetThread(db *sql.DB, threadId int) (Thread, error) {
|
||||
row := db.QueryRow(`SELECT id, board_slug, subject, created_at, bumped_at FROM threads WHERE id = ?`, threadId)
|
||||
|
||||
var thread Thread
|
||||
err := row.Scan(&thread.Id, &thread.BoardSlug, &thread.Subject, &thread.CreatedAt, &thread.BumpedAt)
|
||||
if err != nil {
|
||||
return Thread{}, err
|
||||
}
|
||||
|
||||
return thread, row.Err()
|
||||
}
|
||||
|
||||
func GetThreadPosts(db *sql.DB, threadId int) ([]Post, error) {
|
||||
rows, err := db.Query(`SELECT id, thread_id, author, body, created_at FROM posts where thread_id = ?`, threadId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -74,14 +89,14 @@ func GetThreadPosts(db *sql.DB, thread_id int) ([]Post, error) {
|
||||
return result, rows.Err()
|
||||
}
|
||||
|
||||
func PutBoardThread(db *sql.DB, board_slug string, subject string, body string) error {
|
||||
func PutBoardThread(db *sql.DB, boardSlug string, subject string, body string) error {
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
|
||||
res, err := tx.Exec(`INSERT INTO threads (board_slug, subject) VALUES (?, ?) RETURNING id`, board_slug, subject)
|
||||
res, err := tx.Exec(`INSERT INTO threads (board_slug, subject) VALUES (?, ?) RETURNING id`, boardSlug, subject)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user