handlers.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package dispatcher
  15. import (
  16. "context"
  17. "net/http"
  18. "yunion.io/x/jsonutils"
  19. "yunion.io/x/pkg/util/printutils"
  20. "yunion.io/x/onecloud/pkg/appsrv"
  21. )
  22. type IMiddlewareFilter interface {
  23. Filter(appsrv.FilterHandler) appsrv.FilterHandler
  24. }
  25. type SResourceContext struct {
  26. Type string
  27. Id string
  28. }
  29. type IModelDispatchHandler interface {
  30. IMiddlewareFilter
  31. Keyword() string
  32. KeywordPlural() string
  33. ContextKeywordPlurals() [][]string
  34. List(ctx context.Context, query jsonutils.JSONObject, ctxIds []SResourceContext) (*printutils.ListResult, error)
  35. Get(ctx context.Context, idstr string, query jsonutils.JSONObject, isHead bool) (jsonutils.JSONObject, error)
  36. GetSpecific(ctx context.Context, idstr string, spec string, query jsonutils.JSONObject) (jsonutils.JSONObject, error)
  37. Create(ctx context.Context, query jsonutils.JSONObject, data jsonutils.JSONObject, ctxIds []SResourceContext) (jsonutils.JSONObject, error)
  38. BatchCreate(ctx context.Context, query jsonutils.JSONObject, data jsonutils.JSONObject, count int, ctxIds []SResourceContext) ([]printutils.SubmitResult, error)
  39. PerformClassAction(ctx context.Context, action string, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error)
  40. PerformAction(ctx context.Context, idstr string, action string, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error)
  41. // UpdateClass(ctx context.Context, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error)
  42. Update(ctx context.Context, idstr string, query jsonutils.JSONObject, data jsonutils.JSONObject, ctxIds []SResourceContext) (jsonutils.JSONObject, error)
  43. UpdateSpec(ctx context.Context, idstr string, spec string, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error)
  44. // DeleteClass(ctx context.Context, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error)
  45. Delete(ctx context.Context, idstr string, query jsonutils.JSONObject, data jsonutils.JSONObject, ctxIds []SResourceContext) (jsonutils.JSONObject, error)
  46. DeleteSpec(ctx context.Context, idstr string, spec string, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error)
  47. CustomizeHandlerInfo(info *appsrv.SHandlerInfo)
  48. FetchCreateHeaderData(ctx context.Context, header http.Header) (jsonutils.JSONObject, error)
  49. FetchUpdateHeaderData(ctx context.Context, header http.Header) (jsonutils.JSONObject, error)
  50. }
  51. type IJointModelDispatchHandler interface {
  52. IMiddlewareFilter
  53. Keyword() string
  54. KeywordPlural() string
  55. MasterKeywordPlural() string
  56. SlaveKeywordPlural() string
  57. List(ctx context.Context, query jsonutils.JSONObject, ctxIds []SResourceContext) (*printutils.ListResult, error)
  58. ListMasterDescendent(ctx context.Context, idStr string, query jsonutils.JSONObject) (*printutils.ListResult, error)
  59. ListSlaveDescendent(ctx context.Context, idStr string, query jsonutils.JSONObject) (*printutils.ListResult, error)
  60. Get(ctx context.Context, id1 string, id2 string, query jsonutils.JSONObject) (jsonutils.JSONObject, error)
  61. Attach(ctx context.Context, id1 string, id2 string, query jsonutils.JSONObject, body jsonutils.JSONObject) (jsonutils.JSONObject, error)
  62. Update(ctx context.Context, id1 string, id2 string, query jsonutils.JSONObject, body jsonutils.JSONObject) (jsonutils.JSONObject, error)
  63. Detach(ctx context.Context, id1 string, id2 string, query jsonutils.JSONObject, body jsonutils.JSONObject) (jsonutils.JSONObject, error)
  64. }