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