github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/mw/app/coin/description/update.go (about) 1 package description 2 3 import ( 4 "context" 5 "fmt" 6 7 descriptioncrud "github.com/NpoolPlatform/chain-middleware/pkg/crud/app/coin/description" 8 npool "github.com/NpoolPlatform/message/npool/chain/mw/v1/app/coin/description" 9 10 "github.com/NpoolPlatform/chain-middleware/pkg/db" 11 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent" 12 ) 13 14 func (h *Handler) UpdateCoinDescription(ctx context.Context) (*npool.CoinDescription, 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 := descriptioncrud.UpdateSet( 21 cli.CoinDescription.UpdateOneID(*h.ID), 22 &descriptioncrud.Req{ 23 Title: h.Title, 24 Message: h.Message, 25 }, 26 ).Save(_ctx); err != nil { 27 return err 28 } 29 return nil 30 }) 31 if err != nil { 32 return nil, err 33 } 34 return h.GetCoinDescription(ctx) 35 }