devices

package
v1.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound      = gorm.ErrRecordNotFound
	ErrInvalidFilter = errors.New("invalid filter")
	ErrMoreThanOne   = errors.New("more than one record")
)
View Source
var (
	ErrInvalidUser = errors.New("invalid user")
)
View Source
var Module = fx.Module(
	"devices",
	fx.Decorate(func(log *zap.Logger) *zap.Logger {
		return log.Named("devices")
	}),
	fx.Provide(
		newDevicesRepository,
		fx.Private,
	),
	fx.Provide(func(p ServiceParams) FxResult {
		svc := NewService(p)
		return FxResult{
			Service:   svc,
			AsCleaner: svc,
		}
	}),
)

Functions

This section is empty.

Types

type Config

type Config struct {
	UnusedLifetime time.Duration
}

type FxResult

type FxResult struct {
	fx.Out

	Service   *Service
	AsCleaner cleaner.Cleanable `group:"cleaners"`
}

type SelectFilter

type SelectFilter func(*selectFilter)

func WithID

func WithID(id string) SelectFilter

func WithToken

func WithToken(token string) SelectFilter

func WithUserID

func WithUserID(userID string) SelectFilter

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(params ServiceParams) *Service

func (*Service) Clean

func (s *Service) Clean(ctx context.Context) error

func (*Service) Get

func (s *Service) Get(userID string, filter ...SelectFilter) (models.Device, error)

Get returns a single device based on the provided filters for a specific user. It ensures that the filter includes the user's ID. If no device matches the criteria, it returns ErrNotFound. If more than one device matches, it returns ErrMoreThanOne.

func (*Service) GetByToken added in v1.18.0

func (s *Service) GetByToken(token string) (models.Device, error)

GetByToken returns a device by token.

This method is used to retrieve a device by its auth token. If the device does not exist, it returns ErrNotFound.

func (*Service) Insert

func (s *Service) Insert(userID string, device *models.Device) error

func (*Service) Remove added in v1.18.0

func (s *Service) Remove(userID string, filter ...SelectFilter) error

Remove removes devices for a specific user that match the provided filters. It ensures that the filter includes the user's ID.

func (*Service) Select

func (s *Service) Select(userID string, filter ...SelectFilter) ([]models.Device, error)

Select returns a list of devices for a specific user that match the provided filters.

func (*Service) UpdateLastSeen

func (s *Service) UpdateLastSeen(deviceId string) error

func (*Service) UpdatePushToken added in v1.18.0

func (s *Service) UpdatePushToken(deviceId string, token string) error

type ServiceParams

type ServiceParams struct {
	fx.In

	Config Config

	Devices *repository

	IDGen db.IDGen

	Logger *zap.Logger
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL