func (c *IterationController) CreateChild(ctx *app.CreateChildIterationContext) error {
	_, err := login.ContextIdentity(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error()))
	}
	parentID, err := uuid.FromString(ctx.IterationID)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
	}

	return application.Transactional(c.db, func(appl application.Application) error {

		parent, err := appl.Iterations().Load(ctx, parentID)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
		}

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

		childPath := append(parent.Path, parent.ID)

		newItr := iteration.Iteration{
			SpaceID: parent.SpaceID,
			Path:    childPath,
			Name:    *reqIter.Attributes.Name,
			StartAt: reqIter.Attributes.StartAt,
			EndAt:   reqIter.Attributes.EndAt,
		}

		err = appl.Iterations().Create(ctx, &newItr)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		// For create, count will always be zero hence no need to query
		// by passing empty map, updateIterationsWithCounts will be able to put zero values
		wiCounts := make(map[string]workitem.WICountsPerIteration)
		var responseData *app.Iteration
		if newItr.Path.IsEmpty() == false {
			allParentsUUIDs := newItr.Path
			iterations, error := appl.Iterations().LoadMultiple(ctx, allParentsUUIDs)
			if error != nil {
				return jsonapi.JSONErrorResponse(ctx, err)
			}
			itrMap := make(iterationIDMap)
			for _, itr := range iterations {
				itrMap[itr.ID] = itr
			}
			responseData = ConvertIteration(ctx.RequestData, newItr, parentPathResolver(itrMap), updateIterationsWithCounts(wiCounts))
		} else {
			responseData = ConvertIteration(ctx.RequestData, newItr, updateIterationsWithCounts(wiCounts))
		}
		res := &app.IterationSingle{
			Data: responseData,
		}
		ctx.ResponseData.Header().Set("Location", rest.AbsoluteURL(ctx.RequestData, app.IterationHref(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 *IterationController) CreateChild(ctx *app.CreateChildIterationContext) error {
	_, err := login.ContextIdentity(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error()))
	}
	parentID, err := uuid.FromString(ctx.IterationID)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
	}
	return application.Transactional(c.db, func(appl application.Application) error {
		parent, err := appl.Iterations().Load(ctx, parentID)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
		}
		reqIter := ctx.Payload.Data
		if reqIter.Attributes.Name == nil {
			return jsonapi.JSONErrorResponse(ctx, errors.NewBadParameterError("data.attributes.name", nil).Expected("not nil"))
		}
		childPath := append(parent.Path, parent.ID)
		newItr := iteration.Iteration{
			SpaceID: parent.SpaceID,
			Path:    childPath,
			Name:    *reqIter.Attributes.Name,
			StartAt: reqIter.Attributes.StartAt,
			EndAt:   reqIter.Attributes.EndAt,
		}
		err = appl.Iterations().Create(ctx, &newItr)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		wiCounts := make(map[string]workitem.WICountsPerIteration)
		var responseData *app.Iteration
		if newItr.Path.IsEmpty() == false {
			allParentsUUIDs := newItr.Path
			iterations, error := appl.Iterations().LoadMultiple(ctx, allParentsUUIDs)
			if error != nil {
				return jsonapi.JSONErrorResponse(ctx, err)
			}
			itrMap := make(iterationIDMap)
			for _, itr := range iterations {
				itrMap[itr.ID] = itr
			}
			responseData = ConvertIteration(ctx.RequestData, newItr, parentPathResolver(itrMap), updateIterationsWithCounts(wiCounts))
		} else {
			responseData = ConvertIteration(ctx.RequestData, newItr, updateIterationsWithCounts(wiCounts))
		}
		res := &app.IterationSingle{
			Data: responseData,
		}
		ctx.ResponseData.Header().Set("Location", rest.AbsoluteURL(ctx.RequestData, app.IterationHref(res.Data.ID)))
		return ctx.Created(res)
	})
}
func ( c * IterationController ) CreateChild ( ctx * app . CreateChildIterationContext ) error { _ , err := login . ContextIdentity ( ctx ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , goa . ErrUnauthorized ( err . Error ( ) ) ) } parentID , err := uuid . FromString ( ctx . IterationID ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , goa . ErrNotFound ( err . Error ( ) ) ) } return application . Transactional ( c . db , func ( appl application . Application ) error { parent , err := appl . Iterations ( ) . Load ( ctx , parentID ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , goa . ErrNotFound ( err . Error ( ) ) ) } reqIter := ctx . Payload . Data if reqIter . Attributes . Name == nil { return jsonapi . JSONErrorResponse ( ctx , errors . NewBadParameterError ( " " , nil ) . Expected ( " " ) ) } childPath := append ( parent . Path , parent . ID ) newItr := iteration . Iteration { SpaceID : parent . SpaceID , Path : childPath , Name : * reqIter . Attributes . Name , StartAt : reqIter . Attributes . StartAt , EndAt : reqIter . Attributes . EndAt , } err = appl . Iterations ( ) . Create ( ctx , & newItr ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , err ) } wiCounts := make ( map [ string ] workitem . WICountsPerIteration ) var responseData * app . Iteration if newItr . Path . IsEmpty ( ) == false { allParentsUUIDs := newItr . Path iterations , error := appl . Iterations ( ) . LoadMultiple ( ctx , allParentsUUIDs ) if error != nil { return jsonapi . JSONErrorResponse ( ctx , err ) } itrMap := make ( iterationIDMap ) for _ , itr := range iterations { itrMap [ itr . ID ] = itr } responseData = ConvertIteration ( ctx . RequestData , newItr , parentPathResolver ( itrMap ) , updateIterationsWithCounts ( wiCounts ) ) } else { responseData = ConvertIteration ( ctx . RequestData , newItr , updateIterationsWithCounts ( wiCounts ) ) } res := & app . IterationSingle { Data : responseData , } ctx . ResponseData . Header ( ) . Set ( " " , rest . AbsoluteURL ( ctx . RequestData , app . IterationHref ( res . Data . ID ) ) ) return ctx . Created ( res ) } ) }
CreateChild runs the create-child action.
CreateChild runs the create - child action .
// For create, count will always be zero hence no need to query // by passing empty map, updateIterationsWithCounts will be able to put zero values