47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
/*
|
|
* Amsterdam Web Communities System
|
|
* Copyright (c) 2025 Erbosoft Metaverse Design Solutions, All Rights Reserved
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
// The database package contains database management and storage logic.
|
|
package database
|
|
|
|
type Sidebox struct {
|
|
Uid int32 `db:"uid"`
|
|
Boxid int32 `db:"boxid"`
|
|
Sequence int32 `db:"sequence"`
|
|
Param *string `db:"param"`
|
|
}
|
|
|
|
/* AmGetSideboxes returns all the configured sideboxes for a user.
|
|
* Parameters:
|
|
* uid = The ID of the user to retrieve sideboxes for.
|
|
* Returns:
|
|
* Array of Sidebox structures for the user, or nil
|
|
* Standard Go error status
|
|
*/
|
|
func AmGetSideboxes(uid int32) ([]*Sidebox, error) {
|
|
stmt, err := amdb.Preparex("SELECT * FROM sideboxes WHERE uid = ? ORDER BY SEQUENCE")
|
|
if err == nil {
|
|
defer stmt.Close()
|
|
rows, err := stmt.Queryx(uid)
|
|
if err == nil {
|
|
defer rows.Close()
|
|
sboxes := make([]*Sidebox, 0, 3)
|
|
for i := 0; rows.Next(); i++ {
|
|
box := Sidebox{}
|
|
rows.StructScan(&box)
|
|
sboxes = append(sboxes, &box)
|
|
}
|
|
if rows.Err() == nil {
|
|
return sboxes, nil
|
|
}
|
|
return nil, rows.Err()
|
|
}
|
|
}
|
|
return nil, err
|
|
}
|