The default item list should be empty list,not null

This commit make sure that the "items" in response of project level
CVE_whitelist is not null, even when it's null in the DB the API will
return an empty list

Signed-off-by: Daniel Jiang <jiangd@vmware.com>
This commit is contained in:
Daniel Jiang 2019-09-04 17:59:56 +08:00
parent 250a53cad7
commit 76a79869df

View File

@ -41,6 +41,7 @@ type defaultManager struct{}
func (d *defaultManager) CreateEmpty(projectID int64) error { func (d *defaultManager) CreateEmpty(projectID int64) error {
l := models.CVEWhitelist{ l := models.CVEWhitelist{
ProjectID: projectID, ProjectID: projectID,
Items: []models.CVEWhitelistItem{},
} }
_, err := dao.CreateCVEWhitelist(l) _, err := dao.CreateCVEWhitelist(l)
if err != nil { if err != nil {
@ -66,6 +67,9 @@ func (d *defaultManager) Get(projectID int64) (*models.CVEWhitelist, error) {
log.Debugf("No CVE whitelist found for project %d, returning empty list.", projectID) log.Debugf("No CVE whitelist found for project %d, returning empty list.", projectID)
return &models.CVEWhitelist{ProjectID: projectID, Items: []models.CVEWhitelistItem{}}, nil return &models.CVEWhitelist{ProjectID: projectID, Items: []models.CVEWhitelistItem{}}, nil
} }
if wl.Items == nil {
wl.Items = []models.CVEWhitelistItem{}
}
return wl, err return wl, err
} }