Bluemage/go/api/devices_get_by_slug.go

23 lines
586 B
Go
Raw Normal View History

2024-08-05 23:06:32 +07:00
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", "device", device).Code(connect.CodeNotFound)
}
return device, errs.Wrapw(err, "failed to find device", "device", device)
}
return device, nil
}