mirror of
https://github.com/Floriansylvain/GoAntiSqlPOC.git
synced 2026-08-19 11:43:24 +02:00
feat: update methods & improved demo
This commit is contained in:
+10
-1
@@ -25,7 +25,6 @@ var (
|
||||
)
|
||||
|
||||
func CreateUser(name, email, password string) (*User, error) {
|
||||
// Enforce uniqueness
|
||||
if _, err := findUserIDByEmail(email); err == nil {
|
||||
return nil, ErrEmailExists
|
||||
}
|
||||
@@ -113,3 +112,13 @@ func ListUsers() ([]*User, error) {
|
||||
})
|
||||
return users, err
|
||||
}
|
||||
|
||||
func UpdateUser(u *User) error {
|
||||
data, err := json.Marshal(u)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return GetDB().Update(func(txn *badger.Txn) error {
|
||||
return txn.Set([]byte(userPrefix+u.ID), data)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user