github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/cmd/srv-applet-mgr/apis/publisher/get.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  // Get Publisher by Publisher ID
    13  type GetPublisher struct {
    14  	httpx.MethodGet
    15  	PublisherID types.SFID `in:"path" name:"publisherID"`
    16  }
    17  
    18  func (r *GetPublisher) Path() string { return "/data/:publisherID" }
    19  
    20  func (r *GetPublisher) Output(ctx context.Context) (interface{}, error) {
    21  	ctx, err := middleware.MustCurrentAccountFromContext(ctx).
    22  		WithPublisherBySFID(ctx, r.PublisherID)
    23  	if err != nil {
    24  		return nil, err
    25  	}
    26  	return types.MustPublisherFromContext(ctx), nil
    27  }
    28  
    29  // List Publishers by Conditions
    30  type ListPublisher struct {
    31  	httpx.MethodGet
    32  	publisher.ListReq
    33  }
    34  
    35  func (r *ListPublisher) Output(ctx context.Context) (interface{}, error) {
    36  	ctx, err := middleware.MustCurrentAccountFromContext(ctx).
    37  		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 publisher.List(ctx, &r.ListReq)
    43  }