func (c *SpaceController) Update(ctx *app.UpdateSpaceContext) error {
	currentUser, err := login.ContextIdentity(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error()))
	}
	id, err := uuid.FromString(ctx.ID)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
	}

	err = validateUpdateSpace(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}

	return application.Transactional(c.db, func(appl application.Application) error {
		s, err := appl.Spaces().Load(ctx.Context, id)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}

		if !uuid.Equal(*currentUser, s.OwnerId) {
			log.Error(ctx, map[string]interface{}{"currentUser": *currentUser, "owner": s.OwnerId}, "Current user is not owner")
			return jsonapi.JSONErrorResponse(ctx, goa.NewErrorClass("forbidden", 403)("User is not the space owner"))
		}

		s.Version = *ctx.Payload.Data.Attributes.Version
		if ctx.Payload.Data.Attributes.Name != nil {
			s.Name = *ctx.Payload.Data.Attributes.Name
		}
		if ctx.Payload.Data.Attributes.Description != nil {
			s.Description = *ctx.Payload.Data.Attributes.Description
		}

		s, err = appl.Spaces().Save(ctx.Context, s)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}

		spaceData, err := ConvertSpaceFromModel(ctx.Context, c.db, ctx.RequestData, *s)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		response := app.SpaceSingle{
			Data: spaceData,
		}

		return ctx.OK(&response)
	})
}
// Update runs the update action.
Update runs the update action.
// Update runs the update action .
func (c *SpaceController) Update(ctx *app.UpdateSpaceContext) error {
	currentUser, err := login.ContextIdentity(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err.Error()))
	}
	id, err := uuid.FromString(ctx.ID)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
	}
	err = validateUpdateSpace(ctx)
	if err != nil {
		return jsonapi.JSONErrorResponse(ctx, err)
	}
	return application.Transactional(c.db, func(appl application.Application) error {
		s, err := appl.Spaces().Load(ctx.Context, id)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		if !uuid.Equal(*currentUser, s.OwnerId) {
			log.Error(ctx, map[string]interface{}{"currentUser": *currentUser, "owner": s.OwnerId}, "Current user is not owner")
			return jsonapi.JSONErrorResponse(ctx, goa.NewErrorClass("forbidden", 403)("User is not the space owner"))
		}
		s.Version = *ctx.Payload.Data.Attributes.Version
		if ctx.Payload.Data.Attributes.Name != nil {
			s.Name = *ctx.Payload.Data.Attributes.Name
		}
		if ctx.Payload.Data.Attributes.Description != nil {
			s.Description = *ctx.Payload.Data.Attributes.Description
		}
		s, err = appl.Spaces().Save(ctx.Context, s)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		spaceData, err := ConvertSpaceFromModel(ctx.Context, c.db, ctx.RequestData, *s)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, err)
		}
		response := app.SpaceSingle{
			Data: spaceData,
		}
		return ctx.OK(&response)
	})
}
func ( c * SpaceController ) Update ( ctx * app . UpdateSpaceContext ) error { currentUser , err := login . ContextIdentity ( ctx ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , goa . ErrUnauthorized ( err . Error ( ) ) ) } id , err := uuid . FromString ( ctx . ID ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , goa . ErrNotFound ( err . Error ( ) ) ) } err = validateUpdateSpace ( ctx ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , err ) } return application . Transactional ( c . db , func ( appl application . Application ) error { s , err := appl . Spaces ( ) . Load ( ctx . Context , id ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , err ) } if ! uuid . Equal ( * currentUser , s . OwnerId ) { log . Error ( ctx , map [ string ] interface { } { " " : * currentUser , " " : s . OwnerId } , " " ) return jsonapi . JSONErrorResponse ( ctx , goa . NewErrorClass ( " " , 403 ) ( " " ) ) } s . Version = * ctx . Payload . Data . Attributes . Version if ctx . Payload . Data . Attributes . Name != nil { s . Name = * ctx . Payload . Data . Attributes . Name } if ctx . Payload . Data . Attributes . Description != nil { s . Description = * ctx . Payload . Data . Attributes . Description } s , err = appl . Spaces ( ) . Save ( ctx . Context , s ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , err ) } spaceData , err := ConvertSpaceFromModel ( ctx . Context , c . db , ctx . RequestData , * s ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , err ) } response := app . SpaceSingle { Data : spaceData , } return ctx . OK ( & response ) } ) }
Update runs the update action.
Update runs the update action .