package models import ( "database/sql" "encoding/json" ) type Board struct { ID int Name string Description string Private bool PublicVisible bool PinnedThreads []int // Stored as JSON CustomLandingPage string ColorScheme string } func GetBoardByID(db *sql.DB, id int) (*Board, error) { query := "SELECT id, name, description, private, public_visible, pinned_threads, custom_landing_page, color_scheme FROM boards WHERE id = ?" row := db.QueryRow(query, id) board := &Board{} var pinnedThreadsJSON string err := row.Scan(&board.ID, &board.Name, &board.Description, &board.Private, &board.PublicVisible, &pinnedThreadsJSON, &board.CustomLandingPage, &board.ColorScheme) if err == sql.ErrNoRows { return nil, nil } if err != nil { return nil, err } if pinnedThreadsJSON != "" { err = json.Unmarshal([]byte(pinnedThreadsJSON), &board.PinnedThreads) if err != nil { return nil, err } } return board, nil } func GetAllBoards(db *sql.DB, private bool) ([]Board, error) { query := "SELECT id, name, description, private, public_visible, pinned_threads, custom_landing_page, color_scheme FROM boards WHERE private = ? ORDER BY id ASC" rows, err := db.Query(query, private) if err != nil { return nil, err } defer rows.Close() var boards []Board for rows.Next() { board := Board{} var pinnedThreadsJSON string err := rows.Scan(&board.ID, &board.Name, &board.Description, &board.Private, &board.PublicVisible, &pinnedThreadsJSON, &board.CustomLandingPage, &board.ColorScheme) if err != nil { return nil, err } if pinnedThreadsJSON != "" { err = json.Unmarshal([]byte(pinnedThreadsJSON), &board.PinnedThreads) if err != nil { return nil, err } } boards = append(boards, board) } return boards, nil }