Redmage/api/devices_exist.go

20 lines
507 B
Go
Raw Normal View History

2024-05-08 19:32:14 +07:00
package api
import (
2024-05-27 14:59:28 +07:00
"context"
2024-05-08 19:32:14 +07:00
"github.com/tigorlazuardi/redmage/models"
"github.com/tigorlazuardi/redmage/pkg/errs"
)
func (api *API) DevicesExist(ctx context.Context, slug string) (exist bool, err error) {
ctx, span := tracer.Start(ctx, "API.DevicesExist")
defer span.End()
exist, err = models.Devices.Query(ctx, api.db, models.SelectWhere.Devices.Slug.EQ(slug)).Exists()
if err != nil {
return false, errs.Wrapw(err, "failed to check device existence", "slug", slug)
}
return exist, nil
}