28 lines
702 B
Go
28 lines
702 B
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
|
|
"connectrpc.com/connect"
|
|
"github.com/tigorlazuardi/bluemage/go/gen/models"
|
|
"github.com/tigorlazuardi/bluemage/go/pkg/errs"
|
|
"github.com/tigorlazuardi/bluemage/go/pkg/log"
|
|
)
|
|
|
|
func (api *API) GetDevice(ctx context.Context, slug string) (device *models.Device, err error) {
|
|
ctx, coll := log.WithQueryCollector(ctx)
|
|
device, err = models.FindDevice(ctx, api.Executor, slug)
|
|
if err != nil {
|
|
if err.Error() == "sql: no rows in result set" {
|
|
return device, errs.Wrapw(err, "device not found",
|
|
"slug", slug,
|
|
"query", coll,
|
|
).Code(connect.CodeNotFound)
|
|
}
|
|
|
|
return device, errs.Wrapw(err, "failed to find device", "slug", slug)
|
|
}
|
|
|
|
return device, nil
|
|
}
|