surechen commented on a change in pull request #50: SCB-1558 support query 
history by key and fix wrong API doc
URL: https://github.com/apache/servicecomb-kie/pull/50#discussion_r341961771
 
 

 ##########
 File path: server/service/mongo/history/service.go
 ##########
 @@ -20,15 +20,30 @@ package history
 import (
        "context"
        "github.com/apache/servicecomb-kie/pkg/model"
+       "github.com/apache/servicecomb-kie/server/service"
        "go.mongodb.org/mongo-driver/bson"
+       "go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 //Service is the implementation
 type Service struct {
 }
 
-//GetHistoryByLabelID get all history by label id
-func (s *Service) GetHistoryByLabelID(ctx context.Context, labelID string) 
([]*model.LabelRevisionDoc, error) {
-       filter := bson.M{"label_id": labelID}
+//GetHistory get all history by label id
+func (s *Service) GetHistory(ctx context.Context, labelID string, options 
...service.FindOption) ([]*model.LabelRevisionDoc, error) {
+       var filter primitive.M
+       opts := service.FindOptions{}
+       for _, o := range options {
+               o(&opts)
+       }
+       if opts.Key != "" {
+               filter = bson.M{
+                       "label_id": labelID,
+                       "data.key": opts.Key,
+               }
+
+       } else {
+               filter = bson.M{"label_id": labelID}
+       }
        return getHistoryByLabelID(ctx, filter)
 
 Review comment:
   Whether there is defensive code, such as setting the maximum number of 
queries returned?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to