func (c *WorkItemLinkTypeController) Create(ctx *app.CreateWorkItemLinkTypeContext) error {
	spaceID, err := uuid.FromString(ctx.ID)
	if err != nil {
		return errors.NewNotFoundError("spaceID", ctx.ID)
	}

	// WorkItemLinkTypeController_Create: start_implement
	// Convert payload from app to model representation
	appLinkType := app.WorkItemLinkTypeSingle{
		Data: ctx.Payload.Data,
	}
	// Set the space to the Payload
	if ctx.Payload.Data != nil && ctx.Payload.Data.Relationships != nil {
		// We overwrite or use the space ID in the URL to set the space of this WI
		spaceSelfURL := rest.AbsoluteURL(ctx.RequestData, app.SpaceHref(spaceID.String()))
		ctx.Payload.Data.Relationships.Space = app.NewSpaceRelation(spaceID, spaceSelfURL)
	}
	modelLinkType, err := ConvertWorkItemLinkTypeToModel(appLinkType)
	if err != nil {
		jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(err.Error()))
		return ctx.BadRequest(jerrors)
	}
	modelLinkType.SpaceID = spaceID
	currentUserIdentityID, err := login.ContextIdentity(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, errors.NewUnauthorizedError(err.Error()))
	}
	return application.Transactional(c.db, func(appl application.Application) error {
		createdModelLinkType, err := appl.WorkItemLinkTypes().Create(ctx.Context, modelLinkType.Name, modelLinkType.Description, modelLinkType.SourceTypeID, modelLinkType.TargetTypeID, modelLinkType.ForwardName, modelLinkType.ReverseName, modelLinkType.Topology, modelLinkType.LinkCategoryID, modelLinkType.SpaceID)
		if err != nil {
			jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
			return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
		}
		appLinkType := ConvertWorkItemLinkTypeFromModel(ctx.RequestData, *createdModelLinkType)
		// Enrich
		hrefFunc := func(obj interface{}) string {
			return fmt.Sprintf(app.WorkItemLinkTypeHref(createdModelLinkType.SpaceID, "%v"), obj)
		}
		linkCtx := newWorkItemLinkContext(ctx.Context, appl, c.db, ctx.RequestData, ctx.ResponseData, hrefFunc, currentUserIdentityID)
		err = enrichLinkTypeSingle(linkCtx, &appLinkType)
		if err != nil {
			jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrInternal("Failed to enrich link type: %s", err.Error()))
			return ctx.InternalServerError(jerrors)
		}
		ctx.ResponseData.Header().Set("Location", app.WorkItemLinkTypeHref(createdModelLinkType.SpaceID, appLinkType.Data.ID))
		return ctx.Created(&appLinkType)
	})
	// WorkItemLinkTypeController_Create: end_implement
}
// Create runs the create action.
Create runs the create action.
// Create runs the create action .
func (c *WorkItemLinkTypeController) Create(ctx *app.CreateWorkItemLinkTypeContext) error {
	spaceID, err := uuid.FromString(ctx.ID)
	if err != nil {
		return errors.NewNotFoundError("spaceID", ctx.ID)
	}
	appLinkType := app.WorkItemLinkTypeSingle{
		Data: ctx.Payload.Data,
	}
	if ctx.Payload.Data != nil && ctx.Payload.Data.Relationships != nil {
		spaceSelfURL := rest.AbsoluteURL(ctx.RequestData, app.SpaceHref(spaceID.String()))
		ctx.Payload.Data.Relationships.Space = app.NewSpaceRelation(spaceID, spaceSelfURL)
	}
	modelLinkType, err := ConvertWorkItemLinkTypeToModel(appLinkType)
	if err != nil {
		jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest(err.Error()))
		return ctx.BadRequest(jerrors)
	}
	modelLinkType.SpaceID = spaceID
	currentUserIdentityID, err := login.ContextIdentity(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, errors.NewUnauthorizedError(err.Error()))
	}
	return application.Transactional(c.db, func(appl application.Application) error {
		createdModelLinkType, err := appl.WorkItemLinkTypes().Create(ctx.Context, modelLinkType.Name, modelLinkType.Description, modelLinkType.SourceTypeID, modelLinkType.TargetTypeID, modelLinkType.ForwardName, modelLinkType.ReverseName, modelLinkType.Topology, modelLinkType.LinkCategoryID, modelLinkType.SpaceID)
		if err != nil {
			jerrors, httpStatusCode := jsonapi.ErrorToJSONAPIErrors(err)
			return ctx.ResponseData.Service.Send(ctx.Context, httpStatusCode, jerrors)
		}
		appLinkType := ConvertWorkItemLinkTypeFromModel(ctx.RequestData, *createdModelLinkType)
		hrefFunc := func(obj interface{}) string {
			return fmt.Sprintf(app.WorkItemLinkTypeHref(createdModelLinkType.SpaceID, "%v"), obj)
		}
		linkCtx := newWorkItemLinkContext(ctx.Context, appl, c.db, ctx.RequestData, ctx.ResponseData, hrefFunc, currentUserIdentityID)
		err = enrichLinkTypeSingle(linkCtx, &appLinkType)
		if err != nil {
			jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrInternal("Failed to enrich link type: %s", err.Error()))
			return ctx.InternalServerError(jerrors)
		}
		ctx.ResponseData.Header().Set("Location", app.WorkItemLinkTypeHref(createdModelLinkType.SpaceID, appLinkType.Data.ID))
		return ctx.Created(&appLinkType)
	})
}
func ( c * WorkItemLinkTypeController ) Create ( ctx * app . CreateWorkItemLinkTypeContext ) error { spaceID , err := uuid . FromString ( ctx . ID ) if err != nil { return errors . NewNotFoundError ( " " , ctx . ID ) } appLinkType := app . WorkItemLinkTypeSingle { Data : ctx . Payload . Data , } if ctx . Payload . Data != nil && ctx . Payload . Data . Relationships != nil { spaceSelfURL := rest . AbsoluteURL ( ctx . RequestData , app . SpaceHref ( spaceID . String ( ) ) ) ctx . Payload . Data . Relationships . Space = app . NewSpaceRelation ( spaceID , spaceSelfURL ) } modelLinkType , err := ConvertWorkItemLinkTypeToModel ( appLinkType ) if err != nil { jerrors , _ := jsonapi . ErrorToJSONAPIErrors ( goa . ErrBadRequest ( err . Error ( ) ) ) return ctx . BadRequest ( jerrors ) } modelLinkType . SpaceID = spaceID currentUserIdentityID , err := login . ContextIdentity ( ctx ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , errors . NewUnauthorizedError ( err . Error ( ) ) ) } return application . Transactional ( c . db , func ( appl application . Application ) error { createdModelLinkType , err := appl . WorkItemLinkTypes ( ) . Create ( ctx . Context , modelLinkType . Name , modelLinkType . Description , modelLinkType . SourceTypeID , modelLinkType . TargetTypeID , modelLinkType . ForwardName , modelLinkType . ReverseName , modelLinkType . Topology , modelLinkType . LinkCategoryID , modelLinkType . SpaceID ) if err != nil { jerrors , httpStatusCode := jsonapi . ErrorToJSONAPIErrors ( err ) return ctx . ResponseData . Service . Send ( ctx . Context , httpStatusCode , jerrors ) } appLinkType := ConvertWorkItemLinkTypeFromModel ( ctx . RequestData , * createdModelLinkType ) hrefFunc := func ( obj interface { } ) string { return fmt . Sprintf ( app . WorkItemLinkTypeHref ( createdModelLinkType . SpaceID , " " ) , obj ) } linkCtx := newWorkItemLinkContext ( ctx . Context , appl , c . db , ctx . RequestData , ctx . ResponseData , hrefFunc , currentUserIdentityID ) err = enrichLinkTypeSingle ( linkCtx , & appLinkType ) if err != nil { jerrors , _ := jsonapi . ErrorToJSONAPIErrors ( goa . ErrInternal ( " " , err . Error ( ) ) ) return ctx . InternalServerError ( jerrors ) } ctx . ResponseData . Header ( ) . Set ( " " , app . WorkItemLinkTypeHref ( createdModelLinkType . SpaceID , appLinkType . Data . ID ) ) return ctx . Created ( & appLinkType ) } ) }
Create runs the create action.
Create runs the create action .
// WorkItemLinkTypeController_Create: start_implement // Convert payload from app to model representation // Set the space to the Payload // We overwrite or use the space ID in the URL to set the space of this WI // Enrich // WorkItemLinkTypeController_Create: end_implement