Merge branch 'master' into itsscb/issue85
This commit is contained in:
commit
6f1081589e
@ -3,40 +3,40 @@ package db
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UpdateAccountInfoTxParams struct {
|
type UpdateAccountTxParams struct {
|
||||||
AccountID uint64 `json:"account_id"`
|
UpdateAccountParams
|
||||||
Changer string `json:"changer"`
|
AfterUpdate func(Account) error
|
||||||
Firstname sql.NullString `json:"firstname"`
|
|
||||||
Lastname sql.NullString `json:"lastname"`
|
|
||||||
Birthday sql.NullTime `json:"birthday"`
|
|
||||||
Phone sql.NullString `json:"phone"`
|
|
||||||
City sql.NullString `json:"city"`
|
|
||||||
Zip sql.NullString `json:"zip"`
|
|
||||||
Street sql.NullString `json:"street"`
|
|
||||||
Country sql.NullString `json:"country"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateAccountInfoTxResult struct {
|
type UpdateAccountTxResult struct {
|
||||||
AccountInfo AccountInfo `json:"account_info"`
|
Account Account `json:"account"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *SQLStore) UpdateAccountInfoTx(ctx context.Context, arg UpdateAccountInfoTxParams) (AccountInfo, error) {
|
func (store *SQLStore) UpdateAccountTx(ctx context.Context, arg UpdateAccountTxParams) (Account, error) {
|
||||||
var result UpdateAccountInfoTxResult
|
var result UpdateAccountTxResult
|
||||||
|
var err error
|
||||||
|
|
||||||
// if arg.Passwordhash.Valid {
|
uid, _ := uuid.NewUUID()
|
||||||
// arg.Passwordhash.String, err = util.HashPassword(arg.Passwordhash.String)
|
|
||||||
// if err != nil {
|
|
||||||
// return Account{}, nil
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
err := store.execTx(ctx, func(q *Queries) error {
|
arg.SecretKey = sql.NullString{
|
||||||
|
Valid: uid.String() != "",
|
||||||
|
String: uid.String(),
|
||||||
|
}
|
||||||
|
|
||||||
|
err = store.execTx(ctx, func(q *Queries) error {
|
||||||
var err error
|
var err error
|
||||||
result.AccountInfo, err = q.UpdateAccountInfo(ctx, UpdateAccountInfoParams(arg))
|
|
||||||
return err
|
result.Account, err = q.UpdateAccount(ctx, arg.UpdateAccountParams)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return arg.AfterUpdate(result.Account)
|
||||||
})
|
})
|
||||||
|
|
||||||
return result.AccountInfo, err
|
return result.Account, err
|
||||||
}
|
}
|
||||||
|
42
bff/db/sqlc/tx_update_account_info.go
Normal file
42
bff/db/sqlc/tx_update_account_info.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdateAccountInfoTxParams struct {
|
||||||
|
AccountID uint64 `json:"account_id"`
|
||||||
|
Changer string `json:"changer"`
|
||||||
|
Firstname sql.NullString `json:"firstname"`
|
||||||
|
Lastname sql.NullString `json:"lastname"`
|
||||||
|
Birthday sql.NullTime `json:"birthday"`
|
||||||
|
Phone sql.NullString `json:"phone"`
|
||||||
|
City sql.NullString `json:"city"`
|
||||||
|
Zip sql.NullString `json:"zip"`
|
||||||
|
Street sql.NullString `json:"street"`
|
||||||
|
Country sql.NullString `json:"country"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateAccountInfoTxResult struct {
|
||||||
|
AccountInfo AccountInfo `json:"account_info"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (store *SQLStore) UpdateAccountInfoTx(ctx context.Context, arg UpdateAccountInfoTxParams) (AccountInfo, error) {
|
||||||
|
var result UpdateAccountInfoTxResult
|
||||||
|
|
||||||
|
// if arg.Passwordhash.Valid {
|
||||||
|
// arg.Passwordhash.String, err = util.HashPassword(arg.Passwordhash.String)
|
||||||
|
// if err != nil {
|
||||||
|
// return Account{}, nil
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
err := store.execTx(ctx, func(q *Queries) error {
|
||||||
|
var err error
|
||||||
|
result.AccountInfo, err = q.UpdateAccountInfo(ctx, UpdateAccountInfoParams(arg))
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
|
||||||
|
return result.AccountInfo, err
|
||||||
|
}
|
@ -1,42 +0,0 @@
|
|||||||
package db
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"database/sql"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
)
|
|
||||||
|
|
||||||
type UpdateAccountTxParams struct {
|
|
||||||
UpdateAccountParams
|
|
||||||
AfterUpdate func(Account) error
|
|
||||||
}
|
|
||||||
|
|
||||||
type UpdateAccountTxResult struct {
|
|
||||||
Account Account `json:"account"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStore) UpdateAccountTx(ctx context.Context, arg UpdateAccountTxParams) (Account, error) {
|
|
||||||
var result UpdateAccountTxResult
|
|
||||||
var err error
|
|
||||||
|
|
||||||
uid, _ := uuid.NewUUID()
|
|
||||||
|
|
||||||
arg.SecretKey = sql.NullString{
|
|
||||||
Valid: uid.String() != "",
|
|
||||||
String: uid.String(),
|
|
||||||
}
|
|
||||||
|
|
||||||
err = store.execTx(ctx, func(q *Queries) error {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
result.Account, err = q.UpdateAccount(ctx, arg.UpdateAccountParams)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return arg.AfterUpdate(result.Account)
|
|
||||||
})
|
|
||||||
|
|
||||||
return result.Account, err
|
|
||||||
}
|
|
@ -36,6 +36,13 @@ func (server *Server) CreateAccount(ctx context.Context, req *pb.CreateAccountRe
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if server.config.Environment == "development" {
|
||||||
|
arg.AfterCreate = func(a db.Account) error {
|
||||||
|
slog.Info("create_account (verify_account)", slog.String("secret_key", a.SecretKey.String))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
account, err := server.store.CreateAccountTx(ctx, arg)
|
account, err := server.store.CreateAccountTx(ctx, arg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("create_account (db)", slog.String("invoked_by", req.GetEmail()), slog.String("error", err.Error()))
|
slog.Error("create_account (db)", slog.String("invoked_by", req.GetEmail()), slog.String("error", err.Error()))
|
||||||
|
@ -62,8 +62,15 @@ func (server *Server) UpdateAccount(ctx context.Context, req *pb.UpdateAccountRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
if req.Email != nil {
|
if req.Email != nil {
|
||||||
arg.AfterUpdate = func(a db.Account) error {
|
if server.config.Environment == "development" {
|
||||||
return server.mailSender.SendEmail("Verify your E-Mail Address", fmt.Sprintf("Hello %s,</br></br>please verify your E-Mail Addres by clicking on the following link:</br><a href=\"http://localhost:8080/v1/verify_email/%d/%s\">Verification Link</a></br></br></br>Your Team of DF", req.GetEmail(), a.ID, a.SecretKey.String), []string{req.GetEmail()}, nil, nil, nil)
|
arg.AfterUpdate = func(a db.Account) error {
|
||||||
|
slog.Info("update_account (verify_account)", slog.String("secret_key", a.SecretKey.String))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
arg.AfterUpdate = func(a db.Account) error {
|
||||||
|
return server.mailSender.SendEmail("Verify your E-Mail Address", fmt.Sprintf("Hello %s,</br></br>please verify your E-Mail Addres by clicking on the following link:</br><a href=\"http://localhost:8080/v1/verify_email/%d/%s\">Verification Link</a></br></br></br>Your Team of DF", req.GetEmail(), a.ID, a.SecretKey.String), []string{req.GetEmail()}, nil, nil, nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user