Skip to content

Commit f285b00

Browse files
add client return entity on Update
1 parent 018df33 commit f285b00

7 files changed

Lines changed: 29 additions & 45 deletions

File tree

client/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Client interface {
3030
ListPublicKeys(ctx context.Context, tagMatcher string) ([]PublicKey, error)
3131
ListPublicKeysLinkedToAccount(ctx context.Context, accountId AccountId, expired bool) ([]PublicKey, error)
3232

33-
UpdatePublicKey(ctx context.Context, id PublicKeyId, comment string, tags tags.Tags) error
33+
UpdatePublicKey(ctx context.Context, id PublicKeyId, comment string, tags tags.Tags) (PublicKey, error)
3434

3535
DeletePublicKeys(ctx context.Context, ids ...PublicKeyId) error
3636

@@ -46,7 +46,7 @@ type Client interface {
4646
ListAccountsDirty(ctx context.Context) ([]Account, error)
4747
ListAccountsLinkedToPublicKey(ctx context.Context, publicKeyId PublicKeyId, expired bool) ([]Account, error)
4848

49-
UpdateAccount(ctx context.Context, id AccountId, username string, host string, port int, deploymentMethod string, deploymentSecret string) error
49+
UpdateAccount(ctx context.Context, id AccountId, username string, host string, port int, deploymentMethod string, deploymentSecret string) (Account, error)
5050

5151
DeleteAccounts(ctx context.Context, ids ...AccountId) error
5252

@@ -63,7 +63,7 @@ type Client interface {
6363
ListLinksForAccount(ctx context.Context, accountId AccountId, expired bool) ([]Link, error)
6464
ListLinksForPublicKey(ctx context.Context, publicKeyId PublicKeyId, expired bool) ([]Link, error)
6565

66-
UpdateLink(ctx context.Context, id LinkId, accountId AccountId, tagMatcher string, expiresAt time.Time) error
66+
UpdateLink(ctx context.Context, id LinkId, accountId AccountId, tagMatcher string, expiresAt time.Time) (Link, error)
6767

6868
DeleteLinks(ctx context.Context, ids ...LinkId) error
6969

client/mock/client.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type ClientOverwrites struct {
2828
GetPublicKeys func(ctx context.Context, ids ...client.PublicKeyId) ([]client.PublicKey, error)
2929
ListPublicKeys func(ctx context.Context, tagMatcher string) ([]client.PublicKey, error)
3030
ListPublicKeysLinkedToAccount func(ctx context.Context, accountId client.AccountId, expired bool) ([]client.PublicKey, error)
31-
UpdatePublicKey func(ctx context.Context, id client.PublicKeyId, comment string, tags tags.Tags) error
31+
UpdatePublicKey func(ctx context.Context, id client.PublicKeyId, comment string, tags tags.Tags) (client.PublicKey, error)
3232
DeletePublicKeys func(ctx context.Context, ids ...client.PublicKeyId) error
3333

3434
// --- Account Management ---
@@ -38,7 +38,7 @@ type ClientOverwrites struct {
3838
ListAccounts func(ctx context.Context) ([]client.Account, error)
3939
ListAccountsDirty func(ctx context.Context) ([]client.Account, error)
4040
ListAccountsLinkedToPublicKey func(ctx context.Context, publicKeyId client.PublicKeyId, expired bool) ([]client.Account, error)
41-
UpdateAccount func(ctx context.Context, id client.AccountId, username string, host string, port int, deploymentMethod string, deploymentSecret string) error
41+
UpdateAccount func(ctx context.Context, id client.AccountId, username string, host string, port int, deploymentMethod string, deploymentSecret string) (client.Account, error)
4242
DeleteAccounts func(ctx context.Context, ids ...client.AccountId) error
4343
IsAccountDirty func(ctx context.Context, account client.Account) (bool, error)
4444

@@ -48,7 +48,7 @@ type ClientOverwrites struct {
4848
GetLinks func(ctx context.Context, ids ...client.LinkId) ([]client.Link, error)
4949
ListLinksForAccount func(ctx context.Context, accountId client.AccountId, expired bool) ([]client.Link, error)
5050
ListLinksForPublicKey func(ctx context.Context, publicKeyId client.PublicKeyId, expired bool) ([]client.Link, error)
51-
UpdateLink func(ctx context.Context, id client.LinkId, accountId client.AccountId, tagMatcher string, expiresAt time.Time) error
51+
UpdateLink func(ctx context.Context, id client.LinkId, accountId client.AccountId, tagMatcher string, expiresAt time.Time) (client.Link, error)
5252
DeleteLinks func(ctx context.Context, ids ...client.LinkId) error
5353

5454
// --- Deploy & Verify ---
@@ -215,11 +215,11 @@ func (m *Client) ListPublicKeysLinkedToAccount(ctx context.Context, accountId cl
215215
panic("Client.ListPublicKeysLinkedToAccount not implemented")
216216
}
217217

218-
func (m *Client) UpdatePublicKey(ctx context.Context, id client.PublicKeyId, comment string, tags tags.Tags) error {
218+
func (m *Client) UpdatePublicKey(ctx context.Context, id client.PublicKeyId, comment string, tags tags.Tags) (client.PublicKey, error) {
219219
if m.Pre != nil {
220220
err := m.Pre("UpdatePublicKey", map[string]any{"ctx": ctx, "id": id, "comment": comment, "tags": tags})
221221
if err != nil {
222-
return err
222+
return client.PublicKey{}, err
223223
}
224224
}
225225
if m.Overwrites.UpdatePublicKey != nil {
@@ -340,14 +340,14 @@ func (m *Client) ListAccountsLinkedToPublicKey(ctx context.Context, publicKeyId
340340
panic("Client.ListAccountsLinkedToPublicKey not implemented")
341341
}
342342

343-
func (m *Client) UpdateAccount(ctx context.Context, id client.AccountId, username string, host string, port int, deploymentMethod string, deploymentSecret string) error {
343+
func (m *Client) UpdateAccount(ctx context.Context, id client.AccountId, username string, host string, port int, deploymentMethod string, deploymentSecret string) (client.Account, error) {
344344
if m.Pre != nil {
345345
err := m.Pre("UpdateAccount", map[string]any{
346346
"ctx": ctx, "id": id, "username": username, "host": host, "port": port,
347347
"deploymentMethod": deploymentMethod, "deploymentSecret": deploymentSecret,
348348
})
349349
if err != nil {
350-
return err
350+
return client.Account{}, err
351351
}
352352
}
353353
if m.Overwrites.UpdateAccount != nil {
@@ -465,11 +465,11 @@ func (m *Client) ListLinksForPublicKey(ctx context.Context, publicKeyId client.P
465465
panic("Client.ListLinksForPublicKey not implemented")
466466
}
467467

468-
func (m *Client) UpdateLink(ctx context.Context, id client.LinkId, accountId client.AccountId, tagMatcher string, expiresAt time.Time) error {
468+
func (m *Client) UpdateLink(ctx context.Context, id client.LinkId, accountId client.AccountId, tagMatcher string, expiresAt time.Time) (client.Link, error) {
469469
if m.Pre != nil {
470470
err := m.Pre("UpdateLink", map[string]any{"ctx": ctx, "id": id, "accountId": accountId, "tagMatcher": tagMatcher, "expiresAt": expiresAt})
471471
if err != nil {
472-
return err
472+
return client.Link{}, err
473473
}
474474
}
475475
if m.Overwrites.UpdateLink != nil {

client/testui/client.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,27 +138,27 @@ func (c *Client) ListPublicKeysLinkedToAccount(ctx context.Context, accountId cl
138138
return slicest.Flatten(publicKeyss), nil
139139
}
140140

141-
func (c *Client) UpdateLink(ctx context.Context, id client.LinkId, accountId client.AccountId, tagMatcher string, expiresAt time.Time) error {
141+
func (c *Client) UpdateLink(ctx context.Context, id client.LinkId, accountId client.AccountId, tagMatcher string, expiresAt time.Time) (client.Link, error) {
142142
if i, ok := slices.BinarySearchFunc(c.links, id, func(link client.Link, id client.LinkId) int {
143143
return int(link.Id - id)
144144
}); ok {
145145
c.links[i].AccountId = accountId
146146
c.links[i].TagMatcher = tagMatcher
147147
c.links[i].ExpiresAt = expiresAt
148-
return nil
148+
return c.links[i], nil
149149
}
150-
return fmt.Errorf("account with id %v not found", id)
150+
return client.Link{}, fmt.Errorf("account with id %v not found", id)
151151
}
152152

153-
func (c *Client) UpdatePublicKey(ctx context.Context, id client.PublicKeyId, comment string, tags tags.Tags) error {
153+
func (c *Client) UpdatePublicKey(ctx context.Context, id client.PublicKeyId, comment string, tags tags.Tags) (client.PublicKey, error) {
154154
if i, ok := slices.BinarySearchFunc(c.publicKeys, id, func(publicKey client.PublicKey, id client.PublicKeyId) int {
155155
return int(publicKey.Id - id)
156156
}); ok {
157157
c.publicKeys[i].Comment = comment
158158
c.publicKeys[i].Tags = tags
159-
return nil
159+
return c.publicKeys[i], nil
160160
}
161-
return fmt.Errorf("public key with id %v not found", id)
161+
return client.PublicKey{}, fmt.Errorf("public key with id %v not found", id)
162162
}
163163

164164
func (c *Client) DeletePublicKeys(ctx context.Context, ids ...client.PublicKeyId) error {
@@ -231,7 +231,7 @@ func (c *Client) ListAccountsDirty(ctx context.Context) ([]client.Account, error
231231
})
232232
}
233233

234-
func (c *Client) UpdateAccount(ctx context.Context, id client.AccountId, username string, host string, port int, deploymentMethod string, deploymentSecret string) error {
234+
func (c *Client) UpdateAccount(ctx context.Context, id client.AccountId, username string, host string, port int, deploymentMethod string, deploymentSecret string) (client.Account, error) {
235235
if i, ok := slices.BinarySearchFunc(c.accounts, id, func(account client.Account, id client.AccountId) int {
236236
return int(account.Id - id)
237237
}); ok {
@@ -241,9 +241,9 @@ func (c *Client) UpdateAccount(ctx context.Context, id client.AccountId, usernam
241241
c.accounts[i].Port = port
242242
c.accounts[i].DeployMethod = deploymentMethod
243243
c.accounts[i].DeploySecret = deploymentSecret
244-
return nil
244+
return c.accounts[i], nil
245245
}
246-
return fmt.Errorf("account with id %v not found", id)
246+
return client.Account{}, fmt.Errorf("account with id %v not found", id)
247247
}
248248

249249
func (c *Client) DeleteAccounts(ctx context.Context, ids ...client.AccountId) error {

ui/tui/models/views/account/crud.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,15 @@ func NewCrud(c client.Client, rc router.Controll) *crud.Crud[recordT, recordCrea
146146
return err
147147
}
148148

149-
if err := c.UpdateAccount(
149+
account, err := c.UpdateAccount(
150150
ctx,
151151
id,
152152
recordUpdate.Username,
153153
recordUpdate.Host,
154154
port,
155155
recordUpdate.DeployMethod,
156156
recordUpdate.DeploySecret,
157-
); err != nil {
158-
return err
159-
}
160-
161-
account, err := c.GetAccount(ctx, id)
157+
)
162158
if err != nil {
163159
return err
164160
}

ui/tui/models/views/linkaccount/crud.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,13 @@ func NewCrud(c client.Client, rc router.Controll, account client.Account) *crud.
114114
return err
115115
}
116116

117-
if err := c.UpdateLink(
117+
link, err := c.UpdateLink(
118118
ctx,
119119
id,
120120
account.Id,
121121
expr.String(),
122122
expiresAt,
123-
); err != nil {
124-
return err
125-
}
126-
127-
link, err := c.GetLink(ctx, id)
123+
)
128124
if err != nil {
129125
return err
130126
}

ui/tui/models/views/linkpublickey/crud.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,13 @@ func NewCrud(c client.Client, rc router.Controll, publicKey client.PublicKey) *c
147147
return err
148148
}
149149

150-
if err := c.UpdateLink(
150+
link, err := c.UpdateLink(
151151
ctx,
152152
id,
153153
account.Id,
154154
expr.String(),
155155
expiresAt,
156-
); err != nil {
157-
return err
158-
}
159-
160-
link, err := c.GetLink(ctx, id)
156+
)
161157
if err != nil {
162158
return err
163159
}

ui/tui/models/views/publickey/crud.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,12 @@ func NewCrud(c client.Client, rc router.Controll) *crud.Crud[recordT, recordCrea
133133
func(ctx context.Context, id recordIdT, recordCreate recordUpdateT) (recordT, error) {
134134
var record recordT
135135
err := c.WithTransaction(ctx, func(c client.Client) error {
136-
if err := c.UpdatePublicKey(
136+
publicKey, err := c.UpdatePublicKey(
137137
ctx,
138138
id,
139139
recordCreate.Comment,
140140
tags.Parse(recordCreate.Tags),
141-
); err != nil {
142-
return err
143-
}
144-
145-
publicKey, err := c.GetPublicKey(ctx, id)
141+
)
146142
if err != nil {
147143
return err
148144
}

0 commit comments

Comments
 (0)