mirror of
https://github.com/goharbor/harbor.git
synced 2024-09-30 06:18:02 +02:00
update implements of FilterTargets()
This commit is contained in:
parent
82b4781571
commit
cf7ee9a327
@ -206,12 +206,6 @@ func (t *TargetAPI) Post() {
|
|||||||
// Put ...
|
// Put ...
|
||||||
func (t *TargetAPI) Put() {
|
func (t *TargetAPI) Put() {
|
||||||
id := t.getIDFromURL()
|
id := t.getIDFromURL()
|
||||||
if id == 0 {
|
|
||||||
t.CustomAbort(http.StatusBadRequest, "id can not be empty or 0")
|
|
||||||
}
|
|
||||||
|
|
||||||
target := &models.RepTarget{}
|
|
||||||
t.DecodeJSONReqAndValidate(target)
|
|
||||||
|
|
||||||
originTarget, err := dao.GetRepTarget(id)
|
originTarget, err := dao.GetRepTarget(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -219,6 +213,13 @@ func (t *TargetAPI) Put() {
|
|||||||
t.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))
|
t.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if originTarget == nil {
|
||||||
|
t.CustomAbort(http.StatusNotFound, http.StatusText(http.StatusNotFound))
|
||||||
|
}
|
||||||
|
|
||||||
|
target := &models.RepTarget{}
|
||||||
|
t.DecodeJSONReqAndValidate(target)
|
||||||
|
|
||||||
if target.Name != originTarget.Name {
|
if target.Name != originTarget.Name {
|
||||||
ta, err := dao.GetRepTargetByName(target.Name)
|
ta, err := dao.GetRepTargetByName(target.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -246,9 +247,6 @@ func (t *TargetAPI) Put() {
|
|||||||
// Delete ...
|
// Delete ...
|
||||||
func (t *TargetAPI) Delete() {
|
func (t *TargetAPI) Delete() {
|
||||||
id := t.getIDFromURL()
|
id := t.getIDFromURL()
|
||||||
if id == 0 {
|
|
||||||
t.CustomAbort(http.StatusBadRequest, http.StatusText(http.StatusBadRequest))
|
|
||||||
}
|
|
||||||
|
|
||||||
target, err := dao.GetRepTarget(id)
|
target, err := dao.GetRepTarget(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -269,12 +267,12 @@ func (t *TargetAPI) Delete() {
|
|||||||
func (t *TargetAPI) getIDFromURL() int64 {
|
func (t *TargetAPI) getIDFromURL() int64 {
|
||||||
idStr := t.Ctx.Input.Param(":id")
|
idStr := t.Ctx.Input.Param(":id")
|
||||||
if len(idStr) == 0 {
|
if len(idStr) == 0 {
|
||||||
return 0
|
t.CustomAbort(http.StatusBadRequest, "invalid target ID")
|
||||||
}
|
}
|
||||||
|
|
||||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||||
if err != nil {
|
if err != nil || id <= 0 {
|
||||||
t.CustomAbort(http.StatusBadRequest, "invalid ID in request URL")
|
t.CustomAbort(http.StatusBadRequest, "invalid target ID")
|
||||||
}
|
}
|
||||||
|
|
||||||
return id
|
return id
|
||||||
|
Loading…
Reference in New Issue
Block a user