remove the useless pointer of NextPage field; check namespace notfound error
Signed-off-by: liangchenye <liangchenye@huawei.com>
This commit is contained in:
parent
27e5e42340
commit
1a863a06cf
@ -277,7 +277,7 @@ type NamespaceEnvelope struct {
|
|||||||
type VulnerabilityEnvelope struct {
|
type VulnerabilityEnvelope struct {
|
||||||
Vulnerability *Vulnerability `json:"Vulnerability,omitempty"`
|
Vulnerability *Vulnerability `json:"Vulnerability,omitempty"`
|
||||||
Vulnerabilities *[]Vulnerability `json:"Vulnerabilities,omitempty"`
|
Vulnerabilities *[]Vulnerability `json:"Vulnerabilities,omitempty"`
|
||||||
NextPage *string `json:"NextPage,omitempty"`
|
NextPage string `json:"NextPage,omitempty"`
|
||||||
Error *Error `json:"Error,omitempty"`
|
Error *Error `json:"Error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,8 +212,17 @@ func getVulnerabilities(w http.ResponseWriter, r *http.Request, p httprouter.Par
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dbVulns, nextPage, err := ctx.Store.ListVulnerabilities(p.ByName("namespaceName"), limit, page)
|
namespace := p.ByName("namespaceName")
|
||||||
if err != nil {
|
if namespace == "" {
|
||||||
|
writeResponse(w, r, http.StatusBadRequest, VulnerabilityEnvelope{Error: &Error{"namespace should not be empty"}})
|
||||||
|
return getNotificationRoute, http.StatusBadRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
dbVulns, nextPage, err := ctx.Store.ListVulnerabilities(namespace, limit, page)
|
||||||
|
if err == cerrors.ErrNotFound {
|
||||||
|
writeResponse(w, r, http.StatusNotFound, VulnerabilityEnvelope{Error: &Error{err.Error()}})
|
||||||
|
return getVulnerabilityRoute, http.StatusNotFound
|
||||||
|
} else if err != nil {
|
||||||
writeResponse(w, r, http.StatusInternalServerError, VulnerabilityEnvelope{Error: &Error{err.Error()}})
|
writeResponse(w, r, http.StatusInternalServerError, VulnerabilityEnvelope{Error: &Error{err.Error()}})
|
||||||
return getVulnerabilitiesRoute, http.StatusInternalServerError
|
return getVulnerabilitiesRoute, http.StatusInternalServerError
|
||||||
}
|
}
|
||||||
@ -234,7 +243,7 @@ func getVulnerabilities(w http.ResponseWriter, r *http.Request, p httprouter.Par
|
|||||||
nextPageStr = string(nextPageBytes)
|
nextPageStr = string(nextPageBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
writeResponse(w, r, http.StatusOK, VulnerabilityEnvelope{Vulnerabilities: &vulns, NextPage: &nextPageStr})
|
writeResponse(w, r, http.StatusOK, VulnerabilityEnvelope{Vulnerabilities: &vulns, NextPage: nextPageStr})
|
||||||
return getVulnerabilitiesRoute, http.StatusOK
|
return getVulnerabilitiesRoute, http.StatusOK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,8 @@ const (
|
|||||||
UNION
|
UNION
|
||||||
SELECT id FROM new_namespace`
|
SELECT id FROM new_namespace`
|
||||||
|
|
||||||
listNamespace = `SELECT id, name FROM Namespace`
|
searchNamespace = `SELECT id FROM Namespace WHERE name = $1`
|
||||||
|
listNamespace = `SELECT id, name FROM Namespace`
|
||||||
|
|
||||||
// feature.go
|
// feature.go
|
||||||
soiFeature = `
|
soiFeature = `
|
||||||
|
@ -31,6 +31,15 @@ import (
|
|||||||
func (pgSQL *pgSQL) ListVulnerabilities(namespaceName string, limit int, startID int) ([]database.Vulnerability, int, error) {
|
func (pgSQL *pgSQL) ListVulnerabilities(namespaceName string, limit int, startID int) ([]database.Vulnerability, int, error) {
|
||||||
defer observeQueryTime("listVulnerabilities", "all", time.Now())
|
defer observeQueryTime("listVulnerabilities", "all", time.Now())
|
||||||
|
|
||||||
|
// Query Namespace.
|
||||||
|
var id int
|
||||||
|
err := pgSQL.QueryRow(searchNamespace, namespaceName).Scan(&id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, -1, handleError("searchNamespace", err)
|
||||||
|
} else if id == 0 {
|
||||||
|
return nil, -1, cerrors.ErrNotFound
|
||||||
|
}
|
||||||
|
|
||||||
// Query.
|
// Query.
|
||||||
query := searchVulnerabilityBase + searchVulnerabilityByNamespace
|
query := searchVulnerabilityBase + searchVulnerabilityByNamespace
|
||||||
rows, err := pgSQL.Query(query, namespaceName, startID, limit+1)
|
rows, err := pgSQL.Query(query, namespaceName, startID, limit+1)
|
||||||
@ -71,7 +80,6 @@ func (pgSQL *pgSQL) ListVulnerabilities(namespaceName string, limit int, startID
|
|||||||
return nil, -1, handleError("searchVulnerabilityByNamespace.Rows()", err)
|
return nil, -1, handleError("searchVulnerabilityByNamespace.Rows()", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(nextID)
|
|
||||||
return vulns, nextID, nil
|
return vulns, nextID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user