PSQL UpdateAccount

This commit is contained in:
2023-04-26 00:11:46 +02:00
parent 57e5a73c2f
commit 478d031275
2 changed files with 104 additions and 2 deletions

View File

@@ -137,8 +137,35 @@ func (psql PostgresqlStorage) CreateAccount(account Account) error {
return nil
}
func (PostgresqlStorage) UpdateAccount(account Account) error {
return fmt.Errorf("")
func (psql PostgresqlStorage) UpdateAccount(account Account) error {
updateAccountStmt := "update accounts set namespace=$1, data=$2, metadata=$3 where id= $4"
dataAccountJson, err := json.Marshal(account.Data)
if err != nil {
return err
}
metadataAccountJson, err := json.Marshal(account.Metadata)
if err != nil {
return err
}
_, err = psql.DbConnection.Exec(updateAccountStmt, account.Namespace, dataAccountJson, metadataAccountJson, account.ID)
if err != nil {
return err
}
updateAccountAuthStmt := "update account_auth set username = $1, password = $2, email = $3, email_validation = $4 ,phone_number = $5,phone_number_validation = $6 where account_id = $7"
emailValidationJson, err := json.Marshal(account.Authentication.Local.EmailValidation)
if err != nil {
return err
}
phoneValidationJson, err := json.Marshal(account.Authentication.Local.PhoneNumberValidation)
if err != nil {
return err
}
_, err = psql.DbConnection.Exec(updateAccountAuthStmt, account.Authentication.Local.Username, account.Authentication.Local.Password, account.Authentication.Local.Email,
emailValidationJson, account.Authentication.Local.PhoneNumber, phoneValidationJson, account.ID)
if err != nil {
return err
}
return nil
}
func isUUIDv4(str string) bool {