Skip to content

Commit

Permalink
update suername api
Browse files Browse the repository at this point in the history
  • Loading branch information
nnn-gif committed Aug 22, 2024
1 parent 28b4279 commit 91eab39
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
9 changes: 6 additions & 3 deletions cmd/http/oraclebuilder/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type RemoveWalletInput struct {
type UpdateAccessInput struct {
WalletPublicKey string `form:"wallet_public_key"`
AccessLevel string `form:"access_level" binding:"required,oneof=read read_write"`
UserName string `form:"username"`
}

type ViewInput struct {
Expand Down Expand Up @@ -88,17 +89,19 @@ func (ob *Env) AddWallet(context *gin.Context) {
}

func (ob *Env) UpdateAccess(context *gin.Context) {
requestId := context.GetString(REQUEST_ID)

var input UpdateAccessInput
if err := context.ShouldBind(&input); err != nil {
context.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
//TODO check permission, remove self key, check should not be self, min one key has to me read_write
log.Errorln("input", input)
log.Infoln("Request ID: %s, UpdateAccess input err %v ", requestId, input)

err := ob.RelDB.UpdateAccessLevel(input.AccessLevel, input.WalletPublicKey)
err := ob.RelDB.UpdateAccessLevel(input.UserName, input.AccessLevel, input.WalletPublicKey)
if err != nil {
log.Errorln("UpdateAccessLevel", err)
log.Errorf("Request ID: %s, UpdateAccessLevel %v ", requestId, err)

context.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
Expand Down
9 changes: 6 additions & 3 deletions pkg/model/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ func (reldb *RelDB) AddWalletKeys(owner, username, accessLevel string, publicKey
return nil
}

func (reldb *RelDB) UpdateAccessLevel(accessLevel, publicKey string) error {
func (reldb *RelDB) UpdateAccessLevel(username, accessLevel, publicKey string) error {
var err error

tx, err := reldb.postgresClient.BeginTx(context.Background(), pgx.TxOptions{})
Expand All @@ -1178,9 +1178,12 @@ func (reldb *RelDB) UpdateAccessLevel(accessLevel, publicKey string) error {

_, err = tx.Exec(context.Background(), `
UPDATE wallet_public_keys
SET access_level = $1
SET access_level = $1,
username = $3
WHERE public_key = $2
`, accessLevel, publicKey)
AND ($1 IS NOT NULL AND $1 != '' OR $3 IS NOT NULL AND $3 != '');
`, accessLevel, publicKey, username)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/relDB.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ type RelDatastore interface {

CreateCustomer(email string, customerPlan int, paymentStatus string, paymentSource string, numberOfDataFeeds int, walletPublicKeys []string) error
AddWalletKeys(owner, username, accessLevel string, publicKey []string) error
UpdateAccessLevel(accessLevel, publicKey string) error
UpdateAccessLevel(username, accessLevel, publicKey string) error
RemoveWalletKeys(publicKey []string) error
GetCustomerIDByWalletPublicKey(publicKey string) (int, error)
GetCustomerByPublicKey(publicKey string) (*Customer, error)
Expand Down

0 comments on commit 91eab39

Please sign in to comment.