Skip to content

Commit

Permalink
fixed the models JSONQuery method
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Dec 4, 2023
1 parent eeea3c0 commit 2bf06f7
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions repository/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,20 @@ func (a Asset) JSONQuery() (*datatypes.JSONQueryExpression, error) {
}

jsonQuery := datatypes.JSONQuery("content")
switch a.Type {
case string(oam.FQDN):
assetData := asset.(domain.FQDN)
return jsonQuery.Equals(assetData.Name, "name"), nil
case string(oam.IPAddress):
assetData := asset.(network.IPAddress)
return jsonQuery.Equals(assetData.Address.String(), "address"), nil
case string(oam.ASN):
assetData := asset.(network.AutonomousSystem)
return jsonQuery.Equals(assetData.Number, "number"), nil
case string(oam.Netblock):
assetData := asset.(network.Netblock)
return jsonQuery.Equals(assetData.Cidr.String(), "cidr"), nil
case string(oam.RIROrg):
assetData := asset.(network.RIROrganization)
return jsonQuery.Equals(assetData.Name, "name"), nil
default:
return nil, fmt.Errorf("unknown asset type: %s", a.Type)
switch v := asset.(type) {
case *domain.FQDN:
return jsonQuery.Equals(v.Name, "name"), nil
case *network.IPAddress:
return jsonQuery.Equals(v.Address.String(), "address"), nil
case *network.AutonomousSystem:
return jsonQuery.Equals(v.Number, "number"), nil
case *network.Netblock:
return jsonQuery.Equals(v.Cidr.String(), "cidr"), nil
case *network.RIROrganization:
return jsonQuery.Equals(v.Name, "name"), nil
}

return nil, fmt.Errorf("unknown asset type: %s", a.Type)
}

// Relation represents a relationship between two assets stored in the database.
Expand Down

0 comments on commit 2bf06f7

Please sign in to comment.