support multiple appIds
This commit is contained in:
parent
b4d7e3284e
commit
92b432a906
|
@ -113,7 +113,7 @@ type OperationQuery struct {
|
|||
Address string
|
||||
SourceChainIDs []vaa.ChainID
|
||||
TargetChainIDs []vaa.ChainID
|
||||
AppID []string
|
||||
AppIDs []string
|
||||
ExclusiveAppId bool
|
||||
}
|
||||
|
||||
|
@ -138,41 +138,19 @@ func buildQueryOperationsByChain(sourceChainIDs, targetChainIDs []vaa.ChainID) b
|
|||
return bson.D{{Key: "$match", Value: bson.M{"$and": allMatch}}}
|
||||
}
|
||||
|
||||
func buildQueryOperationsByAppID(appIDs []string, exclusive bool) []bson.D {
|
||||
var result []bson.D
|
||||
|
||||
/*
|
||||
if appID == "" {
|
||||
result = append(result, bson.D{{Key: "$match", Value: bson.M{}}})
|
||||
return result
|
||||
}
|
||||
*/
|
||||
|
||||
if exclusive {
|
||||
if len(appIDs) == 1 {
|
||||
result = append(result, bson.D{{Key: "$match", Value: bson.M{
|
||||
"$and": bson.A{
|
||||
bson.M{"rawStandardizedProperties.appIds": bson.M{"$eq": appIDs}},
|
||||
bson.M{"rawStandardizedProperties.appIds": bson.M{"$size": 1}},
|
||||
}}}})
|
||||
} else {
|
||||
a := bson.A{}
|
||||
for _, appID := range appIDs {
|
||||
cond := bson.M{
|
||||
"$and": bson.A{
|
||||
bson.M{"rawStandardizedProperties.appIds": bson.M{"$eq": appID}},
|
||||
bson.M{"rawStandardizedProperties.appIds": bson.M{"$size": 1}},
|
||||
}}
|
||||
a = append(a, cond)
|
||||
}
|
||||
result = append(result, bson.D{{Key: "$match", Value: bson.M{
|
||||
"$or": a}}})
|
||||
}
|
||||
|
||||
} else {
|
||||
result = append(result, bson.D{{Key: "$match", Value: bson.M{"rawStandardizedProperties.appIds": bson.M{"$in": appIDs}}}})
|
||||
func buildQueryOperationsByAppID(appIDs []string, exclusive bool) bson.D {
|
||||
if !exclusive {
|
||||
return bson.D{{Key: "$match", Value: bson.M{"rawStandardizedProperties.appIds": bson.M{"$in": appIDs}}}}
|
||||
}
|
||||
return result
|
||||
matchAppID := bson.A{}
|
||||
for _, appID := range appIDs {
|
||||
cond := bson.M{"$and": bson.A{
|
||||
bson.M{"rawStandardizedProperties.appIds": bson.M{"$eq": appID}},
|
||||
bson.M{"rawStandardizedProperties.appIds": bson.M{"$size": 1}},
|
||||
}}
|
||||
matchAppID = append(matchAppID, cond)
|
||||
}
|
||||
return bson.D{{Key: "$match", Value: bson.M{"$or": matchAppID}}}
|
||||
}
|
||||
|
||||
// findOperationsIdByAddress returns all operations filtered by address.
|
||||
|
@ -258,9 +236,9 @@ func (r *Repository) FindByChainAndAppId(ctx context.Context, query OperationQue
|
|||
pipeline = append(pipeline, matchBySourceTargetChain)
|
||||
}
|
||||
|
||||
if len(query.AppID) > 0 {
|
||||
matchByAppId := buildQueryOperationsByAppID(query.AppID, query.ExclusiveAppId)
|
||||
pipeline = append(pipeline, matchByAppId...)
|
||||
if len(query.AppIDs) > 0 {
|
||||
matchByAppId := buildQueryOperationsByAppID(query.AppIDs, query.ExclusiveAppId)
|
||||
pipeline = append(pipeline, matchByAppId)
|
||||
}
|
||||
|
||||
pipeline = append(pipeline, bson.D{{Key: "$sort", Value: bson.D{
|
||||
|
|
|
@ -36,7 +36,7 @@ type OperationFilter struct {
|
|||
Address string
|
||||
SourceChainIDs []vaa.ChainID
|
||||
TargetChainIDs []vaa.ChainID
|
||||
AppID []string
|
||||
AppIDs []string
|
||||
ExclusiveAppId bool
|
||||
Pagination pagination.Pagination
|
||||
}
|
||||
|
@ -54,11 +54,11 @@ func (s *Service) FindAll(ctx context.Context, filter OperationFilter) ([]*Opera
|
|||
Pagination: filter.Pagination,
|
||||
SourceChainIDs: filter.SourceChainIDs,
|
||||
TargetChainIDs: filter.TargetChainIDs,
|
||||
AppID: filter.AppID,
|
||||
AppIDs: filter.AppIDs,
|
||||
ExclusiveAppId: filter.ExclusiveAppId,
|
||||
}
|
||||
|
||||
if len(operationQuery.AppID) != 0 || len(operationQuery.SourceChainIDs) > 0 || len(operationQuery.TargetChainIDs) > 0 {
|
||||
if len(operationQuery.AppIDs) != 0 || len(operationQuery.SourceChainIDs) > 0 || len(operationQuery.TargetChainIDs) > 0 {
|
||||
return s.repo.FindByChainAndAppId(ctx, operationQuery)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package operations
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/wormhole-foundation/wormhole-explorer/api/handlers/operations"
|
||||
"github.com/wormhole-foundation/wormhole-explorer/api/middleware"
|
||||
"github.com/wormhole-foundation/wormhole-explorer/api/response"
|
||||
"go.uber.org/zap"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Controller is the controller for the operation resource.
|
||||
|
@ -76,8 +75,11 @@ func (c *Controller) FindAll(ctx *fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
|
||||
//appID := middleware.ExtractAppId(ctx, c.logger)
|
||||
appID := strings.Split(ctx.Query("appId"), ",")
|
||||
var appIDs []string
|
||||
appIDQueryParam := ctx.Query("appId")
|
||||
if appIDQueryParam != "" {
|
||||
appIDs = strings.Split(appIDQueryParam, ",")
|
||||
}
|
||||
|
||||
exclusiveAppId, err := middleware.ExtractExclusiveAppId(ctx)
|
||||
if err != nil {
|
||||
|
@ -85,7 +87,7 @@ func (c *Controller) FindAll(ctx *fiber.Ctx) error {
|
|||
}
|
||||
|
||||
searchBySourceTargetChain := len(sourceChain) != 0 || targetChain != nil
|
||||
searchByAppId := len(appID) != 0
|
||||
searchByAppId := len(appIDs) != 0
|
||||
|
||||
if (searchByAddress || searchByTxHash) && (searchBySourceTargetChain || searchByAppId) {
|
||||
return response.NewInvalidParamError(ctx, "address/txHash cannot be combined with sourceChain/targetChain/appId query filter", nil)
|
||||
|
@ -96,7 +98,7 @@ func (c *Controller) FindAll(ctx *fiber.Ctx) error {
|
|||
Address: address,
|
||||
SourceChainIDs: sourceChain,
|
||||
TargetChainIDs: targetChain,
|
||||
AppID: appID,
|
||||
AppIDs: appIDs,
|
||||
ExclusiveAppId: exclusiveAppId,
|
||||
Pagination: *pagination,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue