示例#1
0
文件: scope.go 项目: jllopis/try6
// CreateScope handler creates a new scope for the tenant specified in the body
func CreateScope(sm store.Storer) echo.HandlerFunc {
	return func(ctx *echo.Context) error {
		var s try6.Scope
		err := json.NewDecoder(ctx.Request().Body).Decode(&s)
		if err != nil {
			return ctx.JSON(http.StatusBadRequest, &logMessage{Status: "error", Action: "create", Info: err.Error(), Table: "scopes"})
		}
		if s.TenantID == "" {
			return ctx.JSON(http.StatusBadRequest, &logMessage{Status: "error", Action: "create", Info: "tenant not specified", Table: "scopes"})
		}
		err = sm.SaveScope(&s)
		if err != nil {
			return ctx.JSON(http.StatusInternalServerError, &logMessage{Status: "error", Action: "create", Info: err.Error(), Table: "scopes"})
		}
		return ctx.JSON(http.StatusCreated, s)
	}
}