1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-26 00:39:41 +02:00

feat(dataservices): unify access methods and abstract away redundant code [EE-5628] (#9115)

This commit is contained in:
andres-portainer 2023-06-22 18:28:07 -03:00 committed by GitHub
parent 4c6bbe9a2f
commit 4cc96b4b30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
171 changed files with 714 additions and 1590 deletions

View file

@ -39,7 +39,7 @@ func (handler *Handler) customTemplateCreate(w http.ResponseWriter, r *http.Requ
customTemplate.CreatedByUserID = tokenData.ID
customTemplates, err := handler.DataStore.CustomTemplate().CustomTemplates()
customTemplates, err := handler.DataStore.CustomTemplate().ReadAll()
if err != nil {
return httperror.InternalServerError("Unable to retrieve custom templates from the database", err)
}

View file

@ -38,7 +38,7 @@ func (handler *Handler) customTemplateDelete(w http.ResponseWriter, r *http.Requ
return httperror.InternalServerError("Unable to retrieve info from request context", err)
}
customTemplate, err := handler.DataStore.CustomTemplate().CustomTemplate(portainer.CustomTemplateID(customTemplateID))
customTemplate, err := handler.DataStore.CustomTemplate().Read(portainer.CustomTemplateID(customTemplateID))
if handler.DataStore.IsErrObjectNotFound(err) {
return httperror.NotFound("Unable to find a custom template with the specified identifier inside the database", err)
} else if err != nil {
@ -55,7 +55,7 @@ func (handler *Handler) customTemplateDelete(w http.ResponseWriter, r *http.Requ
return httperror.Forbidden("Access denied to resource", httperrors.ErrResourceAccessDenied)
}
err = handler.DataStore.CustomTemplate().DeleteCustomTemplate(portainer.CustomTemplateID(customTemplateID))
err = handler.DataStore.CustomTemplate().Delete(portainer.CustomTemplateID(customTemplateID))
if err != nil {
return httperror.InternalServerError("Unable to remove the custom template from the database", err)
}
@ -66,7 +66,7 @@ func (handler *Handler) customTemplateDelete(w http.ResponseWriter, r *http.Requ
}
if resourceControl != nil {
err = handler.DataStore.ResourceControl().DeleteResourceControl(resourceControl.ID)
err = handler.DataStore.ResourceControl().Delete(resourceControl.ID)
if err != nil {
return httperror.InternalServerError("Unable to remove the associated resource control from the database", err)
}

View file

@ -33,7 +33,7 @@ func (handler *Handler) customTemplateFile(w http.ResponseWriter, r *http.Reques
return httperror.BadRequest("Invalid custom template identifier route variable", err)
}
customTemplate, err := handler.DataStore.CustomTemplate().CustomTemplate(portainer.CustomTemplateID(customTemplateID))
customTemplate, err := handler.DataStore.CustomTemplate().Read(portainer.CustomTemplateID(customTemplateID))
if handler.DataStore.IsErrObjectNotFound(err) {
return httperror.NotFound("Unable to find a custom template with the specified identifier inside the database", err)
} else if err != nil {

View file

@ -34,7 +34,7 @@ func (handler *Handler) customTemplateGitFetch(w http.ResponseWriter, r *http.Re
return httperror.BadRequest("Invalid Custom template identifier route variable", err)
}
customTemplate, err := handler.DataStore.CustomTemplate().CustomTemplate(portainer.CustomTemplateID(customTemplateID))
customTemplate, err := handler.DataStore.CustomTemplate().Read(portainer.CustomTemplateID(customTemplateID))
if handler.DataStore.IsErrObjectNotFound(err) {
return httperror.NotFound("Unable to find a custom template with the specified identifier inside the database", err)
} else if err != nil {
@ -78,7 +78,7 @@ func (handler *Handler) customTemplateGitFetch(w http.ResponseWriter, r *http.Re
if customTemplate.GitConfig.ConfigHash != commitHash {
customTemplate.GitConfig.ConfigHash = commitHash
err = handler.DataStore.CustomTemplate().UpdateCustomTemplate(customTemplate.ID, customTemplate)
err = handler.DataStore.CustomTemplate().Update(customTemplate.ID, customTemplate)
if err != nil {
return httperror.InternalServerError("Unable to persist custom template changes inside the database", err)
}

View file

@ -32,7 +32,7 @@ func (handler *Handler) customTemplateInspect(w http.ResponseWriter, r *http.Req
return httperror.BadRequest("Invalid Custom template identifier route variable", err)
}
customTemplate, err := handler.DataStore.CustomTemplate().CustomTemplate(portainer.CustomTemplateID(customTemplateID))
customTemplate, err := handler.DataStore.CustomTemplate().Read(portainer.CustomTemplateID(customTemplateID))
if handler.DataStore.IsErrObjectNotFound(err) {
return httperror.NotFound("Unable to find a custom template with the specified identifier inside the database", err)
} else if err != nil {

View file

@ -30,12 +30,12 @@ func (handler *Handler) customTemplateList(w http.ResponseWriter, r *http.Reques
return httperror.BadRequest("Invalid Custom template type", err)
}
customTemplates, err := handler.DataStore.CustomTemplate().CustomTemplates()
customTemplates, err := handler.DataStore.CustomTemplate().ReadAll()
if err != nil {
return httperror.InternalServerError("Unable to retrieve custom templates from the database", err)
}
resourceControls, err := handler.DataStore.ResourceControl().ResourceControls()
resourceControls, err := handler.DataStore.ResourceControl().ReadAll()
if err != nil {
return httperror.InternalServerError("Unable to retrieve resource controls from the database", err)
}
@ -48,7 +48,7 @@ func (handler *Handler) customTemplateList(w http.ResponseWriter, r *http.Reques
}
if !securityContext.IsAdmin {
user, err := handler.DataStore.User().User(securityContext.UserID)
user, err := handler.DataStore.User().Read(securityContext.UserID)
if err != nil {
return httperror.InternalServerError("Unable to retrieve user information from the database", err)
}

View file

@ -125,7 +125,7 @@ func (handler *Handler) customTemplateUpdate(w http.ResponseWriter, r *http.Requ
return httperror.BadRequest("Invalid request payload", err)
}
customTemplates, err := handler.DataStore.CustomTemplate().CustomTemplates()
customTemplates, err := handler.DataStore.CustomTemplate().ReadAll()
if err != nil {
return httperror.InternalServerError("Unable to retrieve custom templates from the database", err)
}
@ -136,7 +136,7 @@ func (handler *Handler) customTemplateUpdate(w http.ResponseWriter, r *http.Requ
}
}
customTemplate, err := handler.DataStore.CustomTemplate().CustomTemplate(portainer.CustomTemplateID(customTemplateID))
customTemplate, err := handler.DataStore.CustomTemplate().Read(portainer.CustomTemplateID(customTemplateID))
if handler.DataStore.IsErrObjectNotFound(err) {
return httperror.NotFound("Unable to find a custom template with the specified identifier inside the database", err)
} else if err != nil {
@ -214,7 +214,7 @@ func (handler *Handler) customTemplateUpdate(w http.ResponseWriter, r *http.Requ
}
}
err = handler.DataStore.CustomTemplate().UpdateCustomTemplate(customTemplate.ID, customTemplate)
err = handler.DataStore.CustomTemplate().Update(customTemplate.ID, customTemplate)
if err != nil {
return httperror.InternalServerError("Unable to persist custom template changes inside the database", err)
}