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

	return application.Transactional(c.db, func(appl application.Application) error {
		var fields = map[string]app.FieldDefinition{}
		for key, fd := range ctx.Payload.Data.Attributes.Fields {
			fields[key] = *fd
		}
		// 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)
		}
		modelFields, err := ConvertFieldDefinitionsToModel(fields)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		witTypeModel, err := appl.WorkItemTypes().Create(
			ctx.Context,
			*ctx.Payload.Data.Relationships.Space.Data.ID,
			ctx.Payload.Data.ID,
			ctx.Payload.Data.Attributes.ExtendedTypeName,
			ctx.Payload.Data.Attributes.Name,
			ctx.Payload.Data.Attributes.Description,
			ctx.Payload.Data.Attributes.Icon,
			modelFields)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		witData := ConvertWorkItemTypeFromModel(ctx.RequestData, witTypeModel)
		wit := &app.WorkItemTypeSingle{Data: &witData}
		ctx.ResponseData.Header().Set("Location", app.WorkitemtypeHref(*ctx.Payload.Data.Relationships.Space.Data.ID, wit.Data.ID))
		return ctx.Created(wit)
	})
}
// Create runs the create action.
Create runs the create action.
// Create runs the create action .
func (c *WorkitemtypeController) Create(ctx *app.CreateWorkitemtypeContext) error {
	spaceID, err := uuid.FromString(ctx.ID)
	if err != nil {
		return errors.NewNotFoundError("spaceID", ctx.ID)
	}
	return application.Transactional(c.db, func(appl application.Application) error {
		var fields = map[string]app.FieldDefinition{}
		for key, fd := range ctx.Payload.Data.Attributes.Fields {
			fields[key] = *fd
		}
		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)
		}
		modelFields, err := ConvertFieldDefinitionsToModel(fields)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		witTypeModel, err := appl.WorkItemTypes().Create(
			ctx.Context,
			*ctx.Payload.Data.Relationships.Space.Data.ID,
			ctx.Payload.Data.ID,
			ctx.Payload.Data.Attributes.ExtendedTypeName,
			ctx.Payload.Data.Attributes.Name,
			ctx.Payload.Data.Attributes.Description,
			ctx.Payload.Data.Attributes.Icon,
			modelFields)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		witData := ConvertWorkItemTypeFromModel(ctx.RequestData, witTypeModel)
		wit := &app.WorkItemTypeSingle{Data: &witData}
		ctx.ResponseData.Header().Set("Location", app.WorkitemtypeHref(*ctx.Payload.Data.Relationships.Space.Data.ID, wit.Data.ID))
		return ctx.Created(wit)
	})
}
func ( c * WorkitemtypeController ) Create ( ctx * app . CreateWorkitemtypeContext ) error { spaceID , err := uuid . FromString ( ctx . ID ) if err != nil { return errors . NewNotFoundError ( " " , ctx . ID ) } return application . Transactional ( c . db , func ( appl application . Application ) error { var fields = map [ string ] app . FieldDefinition { } for key , fd := range ctx . Payload . Data . Attributes . Fields { fields [ key ] = * fd } 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 ) } modelFields , err := ConvertFieldDefinitionsToModel ( fields ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , err ) } witTypeModel , err := appl . WorkItemTypes ( ) . Create ( ctx . Context , * ctx . Payload . Data . Relationships . Space . Data . ID , ctx . Payload . Data . ID , ctx . Payload . Data . Attributes . ExtendedTypeName , ctx . Payload . Data . Attributes . Name , ctx . Payload . Data . Attributes . Description , ctx . Payload . Data . Attributes . Icon , modelFields ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , err ) } witData := ConvertWorkItemTypeFromModel ( ctx . RequestData , witTypeModel ) wit := & app . WorkItemTypeSingle { Data : & witData } ctx . ResponseData . Header ( ) . Set ( " " , app . WorkitemtypeHref ( * ctx . Payload . Data . Relationships . Space . Data . ID , wit . Data . ID ) ) return ctx . Created ( wit ) } ) }
Create runs the create action.
Create runs the create action .
// Set the space to the Payload // We overwrite or use the space ID in the URL to set the space of this WI