github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/mw/coin/currency/feed/update.go (about) 1 package currencyfeed 2 3 import ( 4 "context" 5 "fmt" 6 7 currencyfeedcrud "github.com/NpoolPlatform/chain-middleware/pkg/crud/coin/currency/feed" 8 npool "github.com/NpoolPlatform/message/npool/chain/mw/v1/coin/currency/feed" 9 10 "github.com/NpoolPlatform/chain-middleware/pkg/db" 11 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent" 12 ) 13 14 func (h *Handler) UpdateFeed(ctx context.Context) (*npool.Feed, error) { 15 if h.ID == nil { 16 return nil, fmt.Errorf("invalid id") 17 } 18 19 err := db.WithClient(ctx, func(_ctx context.Context, cli *ent.Client) error { 20 if _, err := currencyfeedcrud.UpdateSet( 21 cli.CurrencyFeed.UpdateOneID(*h.ID), 22 ¤cyfeedcrud.Req{ 23 FeedCoinName: h.FeedCoinName, 24 Disabled: h.Disabled, 25 }, 26 ).Save(_ctx); err != nil { 27 return err 28 } 29 return nil 30 }) 31 if err != nil { 32 return nil, err 33 } 34 35 return h.GetFeed(ctx) 36 }