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

     1  package applet
     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/applet"
     9  	"github.com/machinefi/w3bstream/pkg/types"
    10  )
    11  
    12  // RemoveApplet remove applet by applet id
    13  type RemoveApplet struct {
    14  	httpx.MethodDelete
    15  	AppletID types.SFID `in:"path" name:"appletID"`
    16  }
    17  
    18  func (r *RemoveApplet) Path() string { return "/data/:appletID" }
    19  
    20  func (r *RemoveApplet) Output(ctx context.Context) (interface{}, error) {
    21  	ctx, err := middleware.MustCurrentAccountFromContext(ctx).
    22  		WithAppletContextBySFID(ctx, r.AppletID)
    23  	if err != nil {
    24  		return nil, err
    25  	}
    26  
    27  	return nil, applet.RemoveBySFID(ctx, r.AppletID)
    28  }
    29  
    30  // BatchRemoveApplet remove applets with condition under project permission
    31  type BatchRemoveApplet struct {
    32  	httpx.MethodDelete
    33  	applet.CondArgs
    34  }
    35  
    36  func (r *BatchRemoveApplet) Output(ctx context.Context) (interface{}, error) {
    37  	ctx, err := middleware.MustCurrentAccountFromContext(ctx).
    38  		WithProjectContextByName(ctx, middleware.MustProjectName(ctx))
    39  	if err != nil {
    40  		return nil, err
    41  	}
    42  	r.ProjectID = types.MustProjectFromContext(ctx).ProjectID
    43  	return nil, applet.Remove(ctx, &r.CondArgs)
    44  }