fix(api): correct mapping of metadata queries (#7609)

This commit is contained in:
Silvan 2024-03-21 15:56:58 +01:00 committed by GitHub
parent 517398bba6
commit 6eb982e368
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 10 deletions

View File

@ -21,7 +21,7 @@ func BulkSetMetadataToDomain(req *auth.BulkSetMyMetadataRequest) []*domain.Metad
func ListUserMetadataToQuery(req *auth.ListMyMetadataRequest) (*query.UserMetadataSearchQueries, error) {
offset, limit, asc := object.ListQueryToModel(req.Query)
queries, err := metadata.MetadataQueriesToQuery(req.Queries)
queries, err := metadata.UserMetadataQueriesToQuery(req.Queries)
if err != nil {
return nil, err
}

View File

@ -110,7 +110,7 @@ func BulkSetOrgMetadataToDomain(req *mgmt_pb.BulkSetOrgMetadataRequest) []*domai
func ListOrgMetadataToDomain(req *mgmt_pb.ListOrgMetadataRequest) (*query.OrgMetadataSearchQueries, error) {
offset, limit, asc := object.ListQueryToModel(req.Query)
queries, err := metadata.MetadataQueriesToQuery(req.Queries)
queries, err := metadata.OrgMetadataQueriesToQuery(req.Queries)
if err != nil {
return nil, err
}

View File

@ -76,7 +76,7 @@ func BulkSetUserMetadataToDomain(req *mgmt_pb.BulkSetUserMetadataRequest) []*dom
func ListUserMetadataToDomain(req *mgmt_pb.ListUserMetadataRequest) (*query.UserMetadataSearchQueries, error) {
offset, limit, asc := object.ListQueryToModel(req.Query)
queries, err := metadata.MetadataQueriesToQuery(req.Queries)
queries, err := metadata.UserMetadataQueriesToQuery(req.Queries)
if err != nil {
return nil, err
}

View File

@ -49,10 +49,10 @@ func OrgMetadataToPb(data *query.OrgMetadata) *meta_pb.Metadata {
}
}
func MetadataQueriesToQuery(queries []*meta_pb.MetadataQuery) (_ []query.SearchQuery, err error) {
func OrgMetadataQueriesToQuery(queries []*meta_pb.MetadataQuery) (_ []query.SearchQuery, err error) {
q := make([]query.SearchQuery, len(queries))
for i, query := range queries {
q[i], err = MetadataQueryToQuery(query)
q[i], err = OrgMetadataQueryToQuery(query)
if err != nil {
return nil, err
}
@ -60,15 +60,31 @@ func MetadataQueriesToQuery(queries []*meta_pb.MetadataQuery) (_ []query.SearchQ
return q, nil
}
func MetadataQueryToQuery(query *meta_pb.MetadataQuery) (query.SearchQuery, error) {
switch q := query.Query.(type) {
func OrgMetadataQueryToQuery(metadataQuery *meta_pb.MetadataQuery) (query.SearchQuery, error) {
switch q := metadataQuery.Query.(type) {
case *meta_pb.MetadataQuery_KeyQuery:
return MetadataKeyQueryToQuery(q.KeyQuery)
return query.NewOrgMetadataKeySearchQuery(q.KeyQuery.Key, object.TextMethodToQuery(q.KeyQuery.Method))
default:
return nil, zerrors.ThrowInvalidArgument(nil, "METAD-fdg23", "List.Query.Invalid")
}
}
func MetadataKeyQueryToQuery(q *meta_pb.MetadataKeyQuery) (query.SearchQuery, error) {
return query.NewOrgMetadataKeySearchQuery(q.Key, object.TextMethodToQuery(q.Method))
func UserMetadataQueriesToQuery(queries []*meta_pb.MetadataQuery) (_ []query.SearchQuery, err error) {
q := make([]query.SearchQuery, len(queries))
for i, query := range queries {
q[i], err = UserMetadataQueryToQuery(query)
if err != nil {
return nil, err
}
}
return q, nil
}
func UserMetadataQueryToQuery(metadataQuery *meta_pb.MetadataQuery) (query.SearchQuery, error) {
switch q := metadataQuery.Query.(type) {
case *meta_pb.MetadataQuery_KeyQuery:
return query.NewUserMetadataKeySearchQuery(q.KeyQuery.Key, object.TextMethodToQuery(q.KeyQuery.Method))
default:
return nil, zerrors.ThrowInvalidArgument(nil, "METAD-Vn7qy", "List.Query.Invalid")
}
}