github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/cmd/srv-applet-mgr/apis/applet/get.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 // ListApplet list applets with condition under project permission 13 type ListApplet struct { 14 httpx.MethodGet 15 applet.ListReq 16 } 17 18 func (r *ListApplet) Path() string { return "/datalist" } 19 20 func (r *ListApplet) Output(ctx context.Context) (interface{}, error) { 21 ca := middleware.MustCurrentAccountFromContext(ctx) 22 ctx, err := ca.WithProjectContextByName(ctx, middleware.MustProjectName(ctx)) 23 if err != nil { 24 return nil, err 25 } 26 27 r.ProjectID = types.MustProjectFromContext(ctx).ProjectID 28 return applet.List(ctx, &r.ListReq) 29 } 30 31 // GetApplet get applet by applet id 32 type GetApplet struct { 33 httpx.MethodGet 34 AppletID types.SFID `in:"path" name:"appletID"` 35 } 36 37 func (r *GetApplet) Path() string { return "/data/:appletID" } 38 39 func (r *GetApplet) Output(ctx context.Context) (interface{}, error) { 40 ctx, err := middleware.MustCurrentAccountFromContext(ctx). 41 WithAppletContextBySFID(ctx, r.AppletID) 42 if err != nil { 43 return nil, err 44 } 45 46 return types.MustAppletFromContext(ctx), nil 47 }