X-Git-Url: https://code.octet-stream.net/broadcaster/blobdiff_plain/04483e823a42650816c2edbb276709145b9068db..6f8503e889dc1f45eddd987ee44e6338712de4fe:/server/database.go diff --git a/server/database.go b/server/database.go index 1312208..06e5968 100644 --- a/server/database.go +++ b/server/database.go @@ -79,6 +79,15 @@ func (d *Database) GetUser(username string) (User, error) { return user, nil } +func (d *Database) GetUserById(id int) (User, error) { + var user User + err := d.sqldb.QueryRow("SELECT id, username, password_hash, is_admin FROM users WHERE id = ?", id).Scan(&user.Id, &user.Username, &user.PasswordHash, &user.IsAdmin) + if err != nil { + return User{}, errors.New("no user with that id") + } + return user, nil +} + func (d *Database) GetUsers() []User { ret := make([]User, 0) rows, err := d.sqldb.Query("SELECT id, username, password_hash, is_admin FROM users ORDER BY username ASC")