github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/cmd/srv-applet-mgr/apis/publisher/pos.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 ) 10 11 // Create Publisher 12 type CreatePublisher struct { 13 httpx.MethodPost 14 publisher.CreateReq `in:"body"` 15 } 16 17 func (r *CreatePublisher) Output(ctx context.Context) (interface{}, error) { 18 acc := middleware.MustCurrentAccountFromContext(ctx) 19 ctx, err := acc.WithProjectContextByName(acc.WithAccount(ctx), middleware.MustProjectName(ctx)) 20 if err != nil { 21 return nil, err 22 } 23 24 return publisher.Create(ctx, &r.CreateReq) 25 } 26 27 type CreateAnonymousPublisher struct { 28 httpx.MethodPost 29 } 30 31 func (r *CreateAnonymousPublisher) Path() string { return "/anonymous" } 32 33 func (r *CreateAnonymousPublisher) Output(ctx context.Context) (interface{}, error) { 34 acc := middleware.MustCurrentAccountFromContext(ctx) 35 prjName := middleware.MustProjectName(ctx) 36 ctx, err := acc.WithProjectContextByName(acc.WithAccount(ctx), prjName) 37 if err != nil { 38 return nil, err 39 } 40 41 return publisher.CreateAnonymousPublisher(ctx) 42 } 43 44 type UpsertPublisher struct { 45 httpx.MethodPost 46 publisher.CreateReq `in:"body"` 47 } 48 49 func (r *UpsertPublisher) Path() string { return "/upsert" } 50 51 func (r *UpsertPublisher) Output(ctx context.Context) (interface{}, error) { 52 acc := middleware.MustCurrentAccountFromContext(ctx) 53 ctx, err := acc.WithProjectContextByName(acc.WithAccount(ctx), middleware.MustProjectName(ctx)) 54 if err != nil { 55 return nil, err 56 } 57 58 return publisher.Upsert(ctx, &r.CreateReq) 59 }