Bluemage/go/api/subreddits_update.go

34 lines
895 B
Go
Raw Normal View History

package api
import (
"context"
"github.com/tigorlazuardi/bluemage/go/gen/models"
"github.com/tigorlazuardi/bluemage/go/pkg/errs"
"github.com/tigorlazuardi/bluemage/go/pkg/log"
"github.com/tigorlazuardi/bluemage/go/pkg/telemetry"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
func (api *API) UpdateSubreddit(ctx context.Context, name string, set *models.SubredditSetter) (err error) {
ctx, span := tracer.Start(ctx, "UpdateSubreddit", trace.WithAttributes(attribute.String("name", name)))
defer func() { telemetry.EndWithStatus(span, err) }()
ctx, coll := log.WithQueryCollector(ctx)
api.lockf(func() {
err = models.Subreddits.Update(ctx, api.Executor, set, &models.Subreddit{Name: name})
})
if err != nil {
err = errs.Wrapw(
err, "failed to update subreddit",
"name", name,
"set", set,
"query", coll,
)
return err
}
return nil
}