2017-11-21 13:46:30 -07:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2018-02-14 10:53:32 -07:00
|
|
|
"github.com/rancher/norman/httperror"
|
2017-11-21 13:46:30 -07:00
|
|
|
"github.com/rancher/norman/types"
|
|
|
|
)
|
|
|
|
|
2018-01-30 16:49:37 -07:00
|
|
|
func CreateHandler(apiContext *types.APIContext, next types.RequestHandler) error {
|
2017-11-21 13:46:30 -07:00
|
|
|
var err error
|
|
|
|
|
2017-12-11 20:58:43 -07:00
|
|
|
data, err := ParseAndValidateBody(apiContext, true)
|
2017-11-21 13:46:30 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
store := apiContext.Schema.Store
|
2018-02-14 10:53:32 -07:00
|
|
|
if store == nil {
|
|
|
|
return httperror.NewAPIError(httperror.NotFound, "no store found")
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err = store.Create(apiContext, apiContext.Schema, data)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2017-11-21 13:46:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
apiContext.WriteResponse(http.StatusCreated, data)
|
|
|
|
return nil
|
|
|
|
}
|