func (c *IterationController) Update(ctx *app.UpdateIterationContext) error {
	_, err := login.ContextIdentity(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error()))
	}
	id, 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 {
		itr, err := appl.Iterations().Load(ctx.Context, id)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		if ctx.Payload.Data.Attributes.Name != nil {
			itr.Name = *ctx.Payload.Data.Attributes.Name
		}
		if ctx.Payload.Data.Attributes.StartAt != nil {
			itr.StartAt = ctx.Payload.Data.Attributes.StartAt
		}
		if ctx.Payload.Data.Attributes.EndAt != nil {
			itr.EndAt = ctx.Payload.Data.Attributes.EndAt
		}
		if ctx.Payload.Data.Attributes.Description != nil {
			itr.Description = ctx.Payload.Data.Attributes.Description
		}
		if ctx.Payload.Data.Attributes.State != nil {
			if *ctx.Payload.Data.Attributes.State == iteration.IterationStateStart {
				res, err := appl.Iterations().CanStartIteration(ctx, itr)
				if res == false && err != nil {
					return jsonapi.JSONErrorResponse(ctx, err)
				}
			}
			itr.State = *ctx.Payload.Data.Attributes.State
		}
		itr, err = appl.Iterations().Save(ctx.Context, *itr)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		wiCounts, err := appl.WorkItems().GetCountsForIteration(ctx, itr.ID)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		response := app.IterationSingle{
			Data: ConvertIteration(ctx.RequestData, *itr, updateIterationsWithCounts(wiCounts)),
		}

		return ctx.OK(&response)
	})
}
// Update runs the update action.
Update runs the update action.
// Update runs the update action .
func (c *IterationController) Update(ctx *app.UpdateIterationContext) error {
	_, err := login.ContextIdentity(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error()))
	}
	id, 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 {
		itr, err := appl.Iterations().Load(ctx.Context, id)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		if ctx.Payload.Data.Attributes.Name != nil {
			itr.Name = *ctx.Payload.Data.Attributes.Name
		}
		if ctx.Payload.Data.Attributes.StartAt != nil {
			itr.StartAt = ctx.Payload.Data.Attributes.StartAt
		}
		if ctx.Payload.Data.Attributes.EndAt != nil {
			itr.EndAt = ctx.Payload.Data.Attributes.EndAt
		}
		if ctx.Payload.Data.Attributes.Description != nil {
			itr.Description = ctx.Payload.Data.Attributes.Description
		}
		if ctx.Payload.Data.Attributes.State != nil {
			if *ctx.Payload.Data.Attributes.State == iteration.IterationStateStart {
				res, err := appl.Iterations().CanStartIteration(ctx, itr)
				if res == false && err != nil {
					return jsonapi.JSONErrorResponse(ctx, err)
				}
			}
			itr.State = *ctx.Payload.Data.Attributes.State
		}
		itr, err = appl.Iterations().Save(ctx.Context, *itr)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		wiCounts, err := appl.WorkItems().GetCountsForIteration(ctx, itr.ID)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		response := app.IterationSingle{
			Data: ConvertIteration(ctx.RequestData, *itr, updateIterationsWithCounts(wiCounts)),
		}
		return ctx.OK(&response)
	})
}
func ( c * IterationController ) Update ( ctx * app . UpdateIterationContext ) error { _ , err := login . ContextIdentity ( ctx ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , goa . ErrUnauthorized ( err . Error ( ) ) ) } id , 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 { itr , err := appl . Iterations ( ) . Load ( ctx . Context , id ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , err ) } if ctx . Payload . Data . Attributes . Name != nil { itr . Name = * ctx . Payload . Data . Attributes . Name } if ctx . Payload . Data . Attributes . StartAt != nil { itr . StartAt = ctx . Payload . Data . Attributes . StartAt } if ctx . Payload . Data . Attributes . EndAt != nil { itr . EndAt = ctx . Payload . Data . Attributes . EndAt } if ctx . Payload . Data . Attributes . Description != nil { itr . Description = ctx . Payload . Data . Attributes . Description } if ctx . Payload . Data . Attributes . State != nil { if * ctx . Payload . Data . Attributes . State == iteration . IterationStateStart { res , err := appl . Iterations ( ) . CanStartIteration ( ctx , itr ) if res == false && err != nil { return jsonapi . JSONErrorResponse ( ctx , err ) } } itr . State = * ctx . Payload . Data . Attributes . State } itr , err = appl . Iterations ( ) . Save ( ctx . Context , * itr ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , err ) } wiCounts , err := appl . WorkItems ( ) . GetCountsForIteration ( ctx , itr . ID ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , err ) } response := app . IterationSingle { Data : ConvertIteration ( ctx . RequestData , * itr , updateIterationsWithCounts ( wiCounts ) ) , } return ctx . OK ( & response ) } ) }
Update runs the update action.
Update runs the update action .