Skip to content

Commit

Permalink
Merge branch 'sprint/30' of https://gitlab.zcorp.cc/pangu/qucheng int…
Browse files Browse the repository at this point in the history
…o sprint/30
  • Loading branch information
wangjianhua committed Oct 21, 2022
2 parents ed755e3 + c288f4b commit 8517bd8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 7 additions & 5 deletions backend/internal/app/router/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,13 @@ func RemoveSnippet(c *gin.Context) {
return
}

err = service.Snippets(ctx, body.Cluster).Remove(body.Name, body.Namespace)
if err != nil {
logger.WithError(err).Error("failed to remove snippet")
renderError(c, http.StatusInternalServerError, err)
return
if service.Snippets(ctx, body.Cluster).Has(body.Name, body.Namespace) {
err = service.Snippets(ctx, body.Cluster).Remove(body.Name, body.Namespace)
if err != nil {
logger.WithError(err).Error("failed to remove snippet")
renderError(c, http.StatusInternalServerError, err)
return
}
}

renderSuccess(c, http.StatusOK)
Expand Down
5 changes: 5 additions & 0 deletions backend/internal/app/service/snippet/manage.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func (m *Manager) Get(name, namespace string) (*Snippet, error) {
return s, err
}

func (m *Manager) Has(name, namespace string) bool {
_, err := m.ks.Store.GetConfigMap(namespace, name)
return err == nil
}

func (m *Manager) Create(name, namespace, category string, values map[string]interface{}, autoImport bool) error {
content, err := yaml.Marshal(values)
if err != nil {
Expand Down

0 comments on commit 8517bd8

Please sign in to comment.