func (r *GormRepository) Save(ctx context.Context, p *Space) (*Space, error) {
	pr := Space{}
	tx := r.db.Where("id=?", p.ID).First(&pr)
	oldVersion := p.Version
	p.Version++
	if tx.RecordNotFound() {
		// treating this as a not found error: the fact that we're using number internal is implementation detail
		return nil, errors.NewNotFoundError("space", p.ID.String())
	}
	if err := tx.Error; err != nil {
		return nil, errors.NewInternalError(err.Error())
	}
	tx = tx.Where("Version = ?", oldVersion).Save(p)
	if err := tx.Error; err != nil {
		if gormsupport.IsCheckViolation(tx.Error, "spaces_name_check") {
			return nil, errors.NewBadParameterError("Name", p.Name).Expected("not empty")
		}
		if gormsupport.IsUniqueViolation(tx.Error, "spaces_name_idx") {
			return nil, errors.NewBadParameterError("Name", p.Name).Expected("unique")
		}
		return nil, errors.NewInternalError(err.Error())
	}
	if tx.RowsAffected == 0 {
		return nil, errors.NewVersionConflictError("version conflict")
	}

	log.Info(ctx, map[string]interface{}{
		"space_id": p.ID,
	}, "space updated successfully")
	return p, nil
}
// Save updates the given space in the db. Version must be the same as the one in the stored version
// returns NotFoundError, BadParameterError, VersionConflictError or InternalError
Save updates the given space in the db. Version must be the same as the one in the stored version
returns NotFoundError, BadParameterError, VersionConflictError or InternalError
// Save updates the given space in the db . Version must be the same as the one in the stored version // returns NotFoundError BadParameterError VersionConflictError or InternalError
func (r *GormRepository) Save(ctx context.Context, p *Space) (*Space, error) {
	pr := Space{}
	tx := r.db.Where("id=?", p.ID).First(&pr)
	oldVersion := p.Version
	p.Version++
	if tx.RecordNotFound() {
		return nil, errors.NewNotFoundError("space", p.ID.String())
	}
	if err := tx.Error; err != nil {
		return nil, errors.NewInternalError(err.Error())
	}
	tx = tx.Where("Version = ?", oldVersion).Save(p)
	if err := tx.Error; err != nil {
		if gormsupport.IsCheckViolation(tx.Error, "spaces_name_check") {
			return nil, errors.NewBadParameterError("Name", p.Name).Expected("not empty")
		}
		if gormsupport.IsUniqueViolation(tx.Error, "spaces_name_idx") {
			return nil, errors.NewBadParameterError("Name", p.Name).Expected("unique")
		}
		return nil, errors.NewInternalError(err.Error())
	}
	if tx.RowsAffected == 0 {
		return nil, errors.NewVersionConflictError("version conflict")
	}
	log.Info(ctx, map[string]interface{}{
		"space_id": p.ID,
	}, "space updated successfully")
	return p, nil
}
func ( r * GormRepository ) Save ( ctx context . Context , p * Space ) ( * Space , error ) { pr := Space { } tx := r . db . Where ( " " , p . ID ) . First ( & pr ) oldVersion := p . Version p . Version ++ if tx . RecordNotFound ( ) { return nil , errors . NewNotFoundError ( " " , p . ID . String ( ) ) } if err := tx . Error ; err != nil { return nil , errors . NewInternalError ( err . Error ( ) ) } tx = tx . Where ( " " , oldVersion ) . Save ( p ) if err := tx . Error ; err != nil { if gormsupport . IsCheckViolation ( tx . Error , " " ) { return nil , errors . NewBadParameterError ( " " , p . Name ) . Expected ( " " ) } if gormsupport . IsUniqueViolation ( tx . Error , " " ) { return nil , errors . NewBadParameterError ( " " , p . Name ) . Expected ( " " ) } return nil , errors . NewInternalError ( err . Error ( ) ) } if tx . RowsAffected == 0 { return nil , errors . NewVersionConflictError ( " " ) } log . Info ( ctx , map [ string ] interface { } { " " : p . ID , } , " " ) return p , nil }
Save updates the given space in the db.
Save updates the given space in the db .
// treating this as a not found error: the fact that we're using number internal is implementation detail