func (c *AreaController) CreateChild(ctx *app.CreateChildAreaContext) error {
	_, err := login.ContextIdentity(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error()))
	}
	parentID, err := uuid.FromString(ctx.ID)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
	}
	return application.Transactional(c.db, func(appl application.Application) error {
		parent, err := appl.Areas().Load(ctx, parentID)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
		}

		reqArea := ctx.Payload.Data
		if reqArea.Attributes.Name == nil {
			return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("data.attributes.name", nil).Expected("not nil"))
		}

		childPath := append(parent.Path, parent.ID)
		newArea := area.Area{
			SpaceID: parent.SpaceID,
			Path:    childPath,
			Name:    *reqArea.Attributes.Name,
		}

		err = appl.Areas().Create(ctx, &newArea)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}

		res := &app.AreaSingle{
			Data: ConvertArea(appl, ctx.RequestData, newArea, addResolvedPath),
		}
		ctx.ResponseData.Header().Set("Location", rest.AbsoluteURL(ctx.RequestData, app.AreaHref(res.Data.ID)))
		return ctx.Created(res)
	})
}
// CreateChild runs the create-child action.
CreateChild runs the create-child action.
// CreateChild runs the create - child action .
func (c *AreaController) CreateChild(ctx *app.CreateChildAreaContext) error {
	_, err := login.ContextIdentity(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error()))
	}
	parentID, err := uuid.FromString(ctx.ID)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
	}
	return application.Transactional(c.db, func(appl application.Application) error {
		parent, err := appl.Areas().Load(ctx, parentID)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
		}
		reqArea := ctx.Payload.Data
		if reqArea.Attributes.Name == nil {
			return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("data.attributes.name", nil).Expected("not nil"))
		}
		childPath := append(parent.Path, parent.ID)
		newArea := area.Area{
			SpaceID: parent.SpaceID,
			Path:    childPath,
			Name:    *reqArea.Attributes.Name,
		}
		err = appl.Areas().Create(ctx, &newArea)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		res := &app.AreaSingle{
			Data: ConvertArea(appl, ctx.RequestData, newArea, addResolvedPath),
		}
		ctx.ResponseData.Header().Set("Location", rest.AbsoluteURL(ctx.RequestData, app.AreaHref(res.Data.ID)))
		return ctx.Created(res)
	})
}
func ( c * AreaController ) CreateChild ( ctx * app . CreateChildAreaContext ) error { _ , err := login . ContextIdentity ( ctx ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , goa . ErrUnauthorized ( err . Error ( ) ) ) } parentID , err := uuid . FromString ( ctx . ID ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , goa . ErrNotFound ( err . Error ( ) ) ) } return application . Transactional ( c . db , func ( appl application . Application ) error { parent , err := appl . Areas ( ) . Load ( ctx , parentID ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , goa . ErrNotFound ( err . Error ( ) ) ) } reqArea := ctx . Payload . Data if reqArea . Attributes . Name == nil { return jsonapi . JSONErrorResponse ( ctx , errors . NewBadParameterError ( " " , nil ) . Expected ( " " ) ) } childPath := append ( parent . Path , parent . ID ) newArea := area . Area { SpaceID : parent . SpaceID , Path : childPath , Name : * reqArea . Attributes . Name , } err = appl . Areas ( ) . Create ( ctx , & newArea ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , err ) } res := & app . AreaSingle { Data : ConvertArea ( appl , ctx . RequestData , newArea , addResolvedPath ) , } ctx . ResponseData . Header ( ) . Set ( " " , rest . AbsoluteURL ( ctx . RequestData , app . AreaHref ( res . Data . ID ) ) ) return ctx . Created ( res ) } ) }
CreateChild runs the create-child action.
CreateChild runs the create - child action .