Similarityoung commented on code in PR #1429:
URL: https://github.com/apache/dubbo-admin/pull/1429#discussion_r2901919233


##########
pkg/console/model/service.go:
##########
@@ -120,3 +122,121 @@ func (s *BaseServiceReq) Query(c *gin.Context) error {
 func (s *BaseServiceReq) ServiceKey() string {
        return s.ServiceName + constants.ColonSeparator + s.Version + 
constants.ColonSeparator + s.Group
 }
+
+type ServiceMethodsReq struct {
+       ServiceName     string `form:"serviceName" json:"serviceName"`
+       Group           string `form:"group" json:"group"`
+       Version         string `form:"version" json:"version"`
+       Mesh            string `form:"mesh" json:"mesh"`
+       ProviderAppName string `form:"providerAppName" json:"providerAppName"`
+}
+
+func (s *ServiceMethodsReq) Query(c *gin.Context) error {
+       s.ServiceName = strings.TrimSpace(c.Query("serviceName"))
+       if s.ServiceName == "" {
+               return fmt.Errorf("service name is empty")
+       }
+       s.Mesh = strings.TrimSpace(c.Query("mesh"))
+       if s.Mesh == "" {
+               return fmt.Errorf("mesh is empty")
+       }
+       s.Group = strings.TrimSpace(c.Query("group"))
+       s.Version = strings.TrimSpace(c.Query("version"))
+       s.ProviderAppName = strings.TrimSpace(c.Query("providerAppName"))
+       return nil
+}
+
+type ServiceMethodDetailReq struct {
+       ServiceMethodsReq
+
+       MethodName string `form:"methodName" json:"methodName"`
+       Signature  string `form:"signature" json:"signature"`
+}
+
+func (s *ServiceMethodDetailReq) Query(c *gin.Context) error {
+       if err := s.ServiceMethodsReq.Query(c); err != nil {
+               return err
+       }
+       s.MethodName = strings.TrimSpace(c.Query("methodName"))
+       if s.MethodName == "" {
+               return fmt.Errorf("method name is empty")
+       }
+       s.Signature = strings.TrimSpace(c.Query("signature"))
+       return nil
+}
+
+type ServiceMethodSummaryResp struct {
+       MethodName     string   `json:"methodName"`
+       ParameterTypes []string `json:"parameterTypes"`
+       Signature      string   `json:"signature,omitempty"`
+}
+
+type ServiceMethodParameter struct {
+       Name string `json:"name"`
+       Type string `json:"type"`
+}
+
+type ServiceMethodDetailResp struct {
+       MethodName     string                   `json:"methodName"`
+       Signature      string                   `json:"signature,omitempty"`
+       ParameterTypes []string                 `json:"parameterTypes"`
+       Parameters     []ServiceMethodParameter `json:"parameters"`
+       ReturnType     string                   `json:"returnType"`
+       Types          []ServiceMethodTypeResp  `json:"types"`
+}
+
+type ServiceMethodTypeResp struct {
+       Type       string            `json:"type"`
+       Properties map[string]string `json:"properties"`
+       Items      []string          `json:"items"`
+       Enums      []string          `json:"enums"`
+}
+
+const DefaultServiceGenericInvokeTimeoutMs int64 = 3000
+
+type ServiceGenericInvokeReq struct {
+       Mesh            string            `json:"mesh"`
+       ServiceName     string            `json:"serviceName"`
+       MethodName      string            `json:"methodName"`
+       Signature       string            `json:"signature"`
+       Args            []json.RawMessage `json:"args"`
+       Group           string            `json:"group"`
+       Version         string            `json:"version"`
+       ProviderAppName string            `json:"providerAppName"`
+       TimeoutMs       int64             `json:"timeoutMs"`
+       Attachments     map[string]string `json:"attachments"`
+}
+
+func (s *ServiceGenericInvokeReq) Validate() error {
+       s.Mesh = strings.TrimSpace(s.Mesh)

Review Comment:
   fix



##########
pkg/console/service/service.go:
##########
@@ -160,6 +162,421 @@ func ToServiceSearchRespByConsumer(res 
*meshresource.ServiceConsumerMetadataReso
        }
 }
 
+type serviceMethodCandidate struct {
+       detail    *model.ServiceMethodDetailResp
+       signature string
+       method    *meshproto.Method
+}
+
+func GetServiceMethodNames(ctx consolectx.Context, req 
model.ServiceMethodsReq) ([]model.ServiceMethodSummaryResp, error) {
+       metadataList, err := listServiceProviderMetadata(ctx, req)
+       if err != nil {
+               return nil, err
+       }
+
+       return buildServiceMethodSummaries(metadataList), nil
+}
+
+func GetServiceMethodDetail(ctx consolectx.Context, req 
model.ServiceMethodDetailReq) (*model.ServiceMethodDetailResp, error) {
+       metadataList, err := listServiceProviderMetadata(ctx, 
req.ServiceMethodsReq)
+       if err != nil {
+               return nil, err
+       }
+
+       candidate, err := 
resolveStructuredServiceMethodCandidate(buildServiceMethodCandidates(metadataList),
 req)
+       if err != nil {
+               return nil, err
+       }
+
+       detail := cloneServiceMethodDetailResp(candidate.detail)
+       detail.Types = buildServiceMethodRelatedTypes(metadataList, 
candidate.method)
+       return detail, nil
+}
+
+func listServiceProviderMetadata(ctx consolectx.Context, req 
model.ServiceMethodsReq) ([]*meshresource.ServiceProviderMetadataResource, 
error) {
+       indexes := map[string]string{
+               index.ByMeshIndex:                  req.Mesh,
+               index.ByServiceProviderServiceName: req.ServiceName,
+       }
+       if req.ProviderAppName != "" {
+               indexes[index.ByServiceProviderAppName] = req.ProviderAppName
+       }
+
+       metadataList, err := 
manager.ListByIndexes[*meshresource.ServiceProviderMetadataResource](
+               ctx.ResourceManager(),
+               meshresource.ServiceProviderMetadataKind,
+               indexes,
+       )
+       if err != nil {
+               return nil, err
+       }
+
+       filtered := make([]*meshresource.ServiceProviderMetadataResource, 0, 
len(metadataList))
+       for _, metadata := range metadataList {
+               if !matchesServiceMethodsReq(metadata, req) {
+                       continue
+               }
+               filtered = append(filtered, metadata)
+       }
+
+       return filtered, nil
+}
+
+func matchesServiceMethodsReq(metadata 
*meshresource.ServiceProviderMetadataResource, req model.ServiceMethodsReq) 
bool {

Review Comment:
   fix



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to