api: add FeatureFromDatabaseModel
This also handles replacing the DB identifier for a maximum version with the string "None".
This commit is contained in:
parent
883be8769f
commit
c504d2ed0e
@ -129,11 +129,7 @@ func VulnerabilityFromDatabaseModel(dbVuln database.Vulnerability, withFixedIn b
|
|||||||
|
|
||||||
if withFixedIn {
|
if withFixedIn {
|
||||||
for _, dbFeatureVersion := range dbVuln.FixedIn {
|
for _, dbFeatureVersion := range dbVuln.FixedIn {
|
||||||
vuln.FixedIn = append(vuln.FixedIn, Feature{
|
vuln.FixedIn = append(vuln.FixedIn, FeatureFromDatabaseModel(dbFeatureVersion))
|
||||||
Name: dbFeatureVersion.Feature.Name,
|
|
||||||
Namespace: dbFeatureVersion.Feature.Namespace.Name,
|
|
||||||
Version: dbFeatureVersion.Version.String(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,10 +143,29 @@ type Feature struct {
|
|||||||
Vulnerabilities []Vulnerability `json:"Vulnerabilities,omitempty"`
|
Vulnerabilities []Vulnerability `json:"Vulnerabilities,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FeatureFromDatabaseModel(dbFeatureVersion database.FeatureVersion) Feature {
|
||||||
|
versionStr := dbFeatureVersion.Version.String()
|
||||||
|
if versionStr == types.MaxVersion.String() {
|
||||||
|
versionStr = "None"
|
||||||
|
}
|
||||||
|
|
||||||
|
return Feature{
|
||||||
|
Name: dbFeatureVersion.Feature.Name,
|
||||||
|
Namespace: dbFeatureVersion.Feature.Namespace.Name,
|
||||||
|
Version: versionStr,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (f Feature) DatabaseModel() (database.FeatureVersion, error) {
|
func (f Feature) DatabaseModel() (database.FeatureVersion, error) {
|
||||||
version, err := types.NewVersion(f.Version)
|
var version types.Version
|
||||||
if err != nil {
|
if f.Version == "None" {
|
||||||
return database.FeatureVersion{}, err
|
version = types.MaxVersion
|
||||||
|
} else {
|
||||||
|
var err error
|
||||||
|
version, err = types.NewVersion(f.Version)
|
||||||
|
if err != nil {
|
||||||
|
return database.FeatureVersion{}, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return database.FeatureVersion{
|
return database.FeatureVersion{
|
||||||
|
Loading…
Reference in New Issue
Block a user