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

     1  package publisher
     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/publisher"
     9  	"github.com/machinefi/w3bstream/pkg/types"
    10  )
    11  
    12  // Remove Publisher by Publisher ID
    13  type RemovePublisher struct {
    14  	httpx.MethodDelete
    15  	PublisherID types.SFID `in:"path" name:"publisherID"`
    16  }
    17  
    18  func (r *RemovePublisher) Path() string { return "/data/:publisherID" }
    19  
    20  func (r *RemovePublisher) Output(ctx context.Context) (interface{}, error) {
    21  	acc := middleware.MustCurrentAccountFromContext(ctx)
    22  	ctx, err := acc.WithPublisherBySFID(ctx, r.PublisherID)
    23  	if err != nil {
    24  		return nil, err
    25  	}
    26  	return nil, publisher.RemoveBySFID(ctx, &acc.Account, types.MustProjectFromContext(ctx), r.PublisherID)
    27  }
    28  
    29  // Remove Publisher by Given Conditions
    30  type BatchRemovePublisher struct {
    31  	httpx.MethodDelete
    32  	publisher.CondArgs
    33  }
    34  
    35  func (r *BatchRemovePublisher) Output(ctx context.Context) (interface{}, error) {
    36  	acc := middleware.MustCurrentAccountFromContext(ctx)
    37  	ctx, err := acc.WithProjectContextByName(ctx, middleware.MustProjectName(ctx))
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  	r.ProjectIDs = []types.SFID{types.MustProjectFromContext(ctx).ProjectID}
    42  	return nil, publisher.Remove(ctx, &acc.Account, &r.CondArgs)
    43  }