Add update username method

This commit is contained in:
Marco Realacci 2022-11-18 17:18:46 +01:00
parent 626b7fa3e9
commit 7c2c993dc3
10 changed files with 82 additions and 9 deletions

View file

@ -40,7 +40,7 @@ import (
type AppDatabase interface {
UserExists(uid string) (bool, error)
GetUserID(name string) (string, error)
SetName(name string) error
UpdateUsername(uid, name string) error
CreateUser(name string) (string, error)
FollowUser(uid string, follow string) error
UnfollowUser(uid string, unfollow string) error

View file

@ -11,7 +11,7 @@ import (
// Check if user exists
func (db *appdbimpl) UserExists(uid string) (bool, error) {
var name string
err := db.c.QueryRow(`SELECT "name" FROM "users" WHERE "uid" = ?`, name).Scan(&name)
err := db.c.QueryRow(`SELECT "name" FROM "users" WHERE "uid" = ?`, uid).Scan(&name)
if db_errors.EmptySet(err) {
return false, nil
@ -38,6 +38,12 @@ func (db *appdbimpl) CreateUser(name string) (string, error) {
return uid.String(), err
}
// Update username
func (db *appdbimpl) UpdateUsername(uid string, name string) error {
_, err := db.c.Exec(`UPDATE "users" SET "name" = ? WHERE "uid" = ?`, name, uid)
return err
}
// Follow a user
func (db *appdbimpl) FollowUser(uid string, follow string) error {
_, err := db.c.Exec(`INSERT INTO "follows" ("follower", "followed") VALUES (?, ?)`, uid, follow)