Add /user/{userId} (#24)
Closes #9 Reviewed-on: #24
This commit was merged in pull request #24.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gitea.seeseepuff.be/seeseemelk/mysqlite"
|
||||
"log"
|
||||
)
|
||||
@@ -42,3 +43,17 @@ func (db *Db) GetUsers() ([]User, error) {
|
||||
}
|
||||
return users, nil
|
||||
}
|
||||
|
||||
func (db *Db) GetUser(id int) (*User, error) {
|
||||
user := &User{}
|
||||
|
||||
err := db.db.Query("select id, name from users where id = ?").
|
||||
Bind(id).ScanSingle(&user.ID, &user.Name)
|
||||
if errors.Is(err, mysqlite.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user