mirror of
https://github.com/rancher/norman.git
synced 2025-09-07 18:20:17 +00:00
Return deleted object on delete if possible
This commit is contained in:
@@ -8,13 +8,20 @@ import (
|
|||||||
|
|
||||||
func DeleteHandler(request *types.APIContext) error {
|
func DeleteHandler(request *types.APIContext) error {
|
||||||
store := request.Schema.Store
|
store := request.Schema.Store
|
||||||
if store != nil {
|
if store == nil {
|
||||||
err := store.Delete(request, request.Schema, request.ID)
|
request.WriteResponse(http.StatusNoContent, nil)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
obj, err := store.Delete(request, request.Schema, request.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
if obj == nil {
|
||||||
request.WriteResponse(http.StatusNoContent, nil)
|
request.WriteResponse(http.StatusNoContent, nil)
|
||||||
|
} else {
|
||||||
|
request.WriteResponse(http.StatusOK, obj)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -65,10 +65,10 @@ func (c *Store) ByID(apiContext *types.APIContext, schema *types.Schema, id stri
|
|||||||
return store.ByID(apiContext, schema, id)
|
return store.ByID(apiContext, schema, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) error {
|
func (c *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
|
||||||
store, ok := c.schemaStores[key(schema)]
|
store, ok := c.schemaStores[key(schema)]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return store.Delete(apiContext, schema, id)
|
return store.Delete(apiContext, schema, id)
|
||||||
}
|
}
|
||||||
|
@@ -7,8 +7,8 @@ import (
|
|||||||
type Store struct {
|
type Store struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) error {
|
func (e *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
|
||||||
return nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Store) ByID(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
|
func (e *Store) ByID(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
|
||||||
|
@@ -192,7 +192,7 @@ func (p *Store) Update(apiContext *types.APIContext, schema *types.Schema, data
|
|||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) error {
|
func (p *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
|
||||||
namespace, id := splitID(id)
|
namespace, id := splitID(id)
|
||||||
|
|
||||||
prop := metav1.DeletePropagationForeground
|
prop := metav1.DeletePropagationForeground
|
||||||
@@ -202,7 +202,16 @@ func (p *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id st
|
|||||||
}).
|
}).
|
||||||
Name(id)
|
Name(id)
|
||||||
|
|
||||||
return req.Do().Error()
|
err := req.Do().Error()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
obj, err := p.ByID(apiContext, schema, id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return obj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Store) singleResult(schema *types.Schema, req *rest.Request) (string, map[string]interface{}, error) {
|
func (p *Store) singleResult(schema *types.Schema, req *rest.Request) (string, map[string]interface{}, error) {
|
||||||
|
@@ -100,6 +100,6 @@ func (t *TransformingStore) Update(apiContext *types.APIContext, schema *types.S
|
|||||||
return t.Transformer(apiContext, data)
|
return t.Transformer(apiContext, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TransformingStore) Delete(apiContext *types.APIContext, schema *types.Schema, id string) error {
|
func (t *TransformingStore) Delete(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
|
||||||
return t.Store.Delete(apiContext, schema, id)
|
return t.Store.Delete(apiContext, schema, id)
|
||||||
}
|
}
|
||||||
|
@@ -90,9 +90,9 @@ func (s *StoreWrapper) Update(apiContext *types.APIContext, schema *types.Schema
|
|||||||
}, data), nil
|
}, data), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StoreWrapper) Delete(apiContext *types.APIContext, schema *types.Schema, id string) error {
|
func (s *StoreWrapper) Delete(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
|
||||||
if err := validateGet(apiContext, schema, id); err != nil {
|
if err := validateGet(apiContext, schema, id); err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.store.Delete(apiContext, schema, id)
|
return s.store.Delete(apiContext, schema, id)
|
||||||
|
@@ -156,6 +156,6 @@ type Store interface {
|
|||||||
List(apiContext *APIContext, schema *Schema, opt QueryOptions) ([]map[string]interface{}, error)
|
List(apiContext *APIContext, schema *Schema, opt QueryOptions) ([]map[string]interface{}, error)
|
||||||
Create(apiContext *APIContext, schema *Schema, data map[string]interface{}) (map[string]interface{}, error)
|
Create(apiContext *APIContext, schema *Schema, data map[string]interface{}) (map[string]interface{}, error)
|
||||||
Update(apiContext *APIContext, schema *Schema, data map[string]interface{}, id string) (map[string]interface{}, error)
|
Update(apiContext *APIContext, schema *Schema, data map[string]interface{}, id string) (map[string]interface{}, error)
|
||||||
Delete(apiContext *APIContext, schema *Schema, id string) error
|
Delete(apiContext *APIContext, schema *Schema, id string) (map[string]interface{}, error)
|
||||||
Watch(apiContext *APIContext, schema *Schema, opt QueryOptions) (chan map[string]interface{}, error)
|
Watch(apiContext *APIContext, schema *Schema, opt QueryOptions) (chan map[string]interface{}, error)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user