Skip to content

Commit 54cd0ca

Browse files
committed
Added update function to Deposit resource
1 parent fbb1d6a commit 54cd0ca

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Given a version number MAJOR.MINOR.PATCH, increment:
1313

1414

1515
## [Unreleased]
16+
### Added
17+
- update function to Deposit resource
1618

1719
## [0.4.2] - 2023-12-15
1820
### Changed

README.md

+33
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,39 @@ func main() {
14451445

14461446
```
14471447

1448+
## Update a Deposit
1449+
1450+
Update a deposit by passing its id to be partially or fully reversed.
1451+
1452+
```golang
1453+
package main
1454+
1455+
import (
1456+
"fmt"
1457+
"github.com/starkbank/sdk-go/starkbank"
1458+
Deposit "github.com/starkbank/sdk-go/starkbank/deposit"
1459+
"github.com/starkbank/sdk-go/tests/utils"
1460+
)
1461+
1462+
func main() {
1463+
1464+
starkbank.User = utils.ExampleProject
1465+
1466+
var patchData = map[string]interface{}{}
1467+
patchData["amount"] = 0
1468+
1469+
deposit, err := Deposit.Update("5155165527080960", patchData, nil)
1470+
if err.Errors != nil {
1471+
for _, e := range err.Errors {
1472+
panic(fmt.Sprintf("code: %s, message: %s", e.Code, e.Message))
1473+
}
1474+
}
1475+
1476+
fmt.Println(deposit)
1477+
}
1478+
1479+
```
1480+
14481481
## Query deposit logs
14491482

14501483
Logs are pretty important to understand the life cycle of a deposit.

starkbank/deposit/deposit.go

+24
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,27 @@ func Page(params map[string]interface{}, user user.User) ([]Deposit, string, Err
135135
}
136136
return deposit, cursor, err
137137
}
138+
139+
func Update(id string, patchData map[string]interface{}, user user.User) (Deposit, Error.StarkErrors) {
140+
// Update Deposit entity
141+
//
142+
// Update the Deposit by passing its id to be partially or fully reversed.
143+
//
144+
// Parameters (required):
145+
// - patchData [map[string]interface{}]: map containing the attributes to be updated. ex: map[string]interface{}{"amount": 9090}
146+
// Parameters (optional):
147+
// - amount [string]: The new amount of the Deposit. If the amount = 0 the Deposit will be fully reversed
148+
//
149+
// Parameters (optional):
150+
// - user [Organization/Project struct, default nil]: Organization or Project struct. Not necessary if starkbank.User was set before function call
151+
//
152+
// Return:
153+
// - Target Deposit with updated attributes
154+
update, err := utils.Patch(resource, id, patchData, user)
155+
unmarshalError := json.Unmarshal(update, &object)
156+
if unmarshalError != nil {
157+
return object, err
158+
}
159+
return object, err
160+
}
161+

tests/sdk/deposit_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,33 @@ func TestDepositQuery(t *testing.T) {
5050
assert.Equal(t, 201, i)
5151
}
5252

53+
func TestDepositUpdate(t *testing.T) {
54+
55+
starkbank.User = Utils.ExampleProject
56+
57+
var depositList []Deposit.Deposit
58+
var params = map[string]interface{}{}
59+
params["limit"] = 1
60+
params["status"] = "created"
61+
62+
deposits := Deposit.Query(params, nil)
63+
for deposit := range deposits {
64+
depositList = append(depositList, deposit)
65+
}
66+
67+
var patchData = map[string]interface{}{}
68+
patchData["amount"] = 0
69+
70+
updated, err := Deposit.Update(depositList[rand.Intn(len(depositList))].Id, patchData, nil)
71+
if err.Errors != nil {
72+
for _, e := range err.Errors {
73+
panic(fmt.Sprintf("code: %s, message: %s", e.Code, e.Message))
74+
}
75+
}
76+
77+
assert.Equal(t, updated.Amount, patchData["amount"])
78+
}
79+
5380
func TestDepositPage(t *testing.T) {
5481

5582
starkbank.User = Utils.ExampleProject

0 commit comments

Comments
 (0)