github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/cmd/srv-applet-mgr/apis/strategy/del.go (about)

     1  package strategy
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/middleware"
     7  	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
     8  	"github.com/machinefi/w3bstream/pkg/modules/strategy"
     9  	"github.com/machinefi/w3bstream/pkg/types"
    10  )
    11  
    12  type RemoveStrategy struct {
    13  	httpx.MethodDelete
    14  	StrategyID types.SFID `in:"path" name:"strategyID"`
    15  }
    16  
    17  func (r *RemoveStrategy) Path() string { return "/data/:strategyID" }
    18  
    19  func (r *RemoveStrategy) Output(ctx context.Context) (interface{}, error) {
    20  	ctx, err := middleware.MustCurrentAccountFromContext(ctx).
    21  		WithStrategyBySFID(ctx, r.StrategyID)
    22  	if err != nil {
    23  		return nil, err
    24  	}
    25  
    26  	return nil, strategy.RemoveBySFID(ctx, r.StrategyID)
    27  }
    28  
    29  type BatchRemoveStrategy struct {
    30  	httpx.MethodDelete
    31  	strategy.CondArgs
    32  }
    33  
    34  func (r *BatchRemoveStrategy) Output(ctx context.Context) (interface{}, error) {
    35  	ctx, err := middleware.MustCurrentAccountFromContext(ctx).
    36  		WithProjectContextByName(ctx, middleware.MustProjectName(ctx))
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  
    41  	r.ProjectID = types.MustProjectFromContext(ctx).ProjectID
    42  	return nil, strategy.Remove(ctx, &r.CondArgs)
    43  }