Documentation
¶
Index ¶
- Variables
- func Module() fx.Option
- type Config
- type Repository
- func (r *Repository) Cleanup(ctx context.Context, until time.Time) (int64, error)
- func (r *Repository) Exists(filters ...SelectFilter) (bool, error)
- func (r *Repository) Get(filter ...SelectFilter) (models.Device, error)
- func (r *Repository) Insert(device *models.Device) error
- func (r *Repository) Remove(filter ...SelectFilter) error
- func (r *Repository) Select(filter ...SelectFilter) ([]models.Device, error)
- func (r *Repository) SetLastSeen(ctx context.Context, id string, lastSeen time.Time) error
- func (r *Repository) UpdatePushToken(id, token string) error
- type SelectFilter
- type Service
- func (s *Service) Exists(userID string, filter ...SelectFilter) (bool, error)
- func (s *Service) Get(userID string, filter ...SelectFilter) (models.Device, error)
- func (s *Service) GetAny(userID string, deviceID string, duration time.Duration) (*models.Device, error)
- func (s *Service) GetByToken(token string) (models.Device, error)
- func (s *Service) Insert(userID string, device *models.Device) error
- func (s *Service) Remove(userID string, filter ...SelectFilter) error
- func (s *Service) Select(userID string, filter ...SelectFilter) ([]models.Device, error)
- func (s *Service) SetLastSeen(ctx context.Context, batch map[string]time.Time) error
- func (s *Service) UpdatePushToken(id string, token string) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("record not found") ErrInvalidFilter = errors.New("invalid filter") ErrMoreThanOne = errors.New("more than one record") )
var (
ErrInvalidUser = errors.New("invalid user")
)
Functions ¶
Types ¶
type Repository ¶ added in v1.34.0
type Repository struct {
// contains filtered or unexported fields
}
func NewRepository ¶ added in v1.34.0
func NewRepository(db *gorm.DB) *Repository
func (*Repository) Exists ¶ added in v1.34.0
func (r *Repository) Exists(filters ...SelectFilter) (bool, error)
Exists checks if there exists a device with the given filters.
If the device does not exist, it returns false and nil error. If there is an error during the query, it returns false and the error. Otherwise, it returns true and nil error.
func (*Repository) Get ¶ added in v1.34.0
func (r *Repository) Get(filter ...SelectFilter) (models.Device, error)
func (*Repository) Insert ¶ added in v1.34.0
func (r *Repository) Insert(device *models.Device) error
func (*Repository) Remove ¶ added in v1.34.0
func (r *Repository) Remove(filter ...SelectFilter) error
func (*Repository) Select ¶ added in v1.34.0
func (r *Repository) Select(filter ...SelectFilter) ([]models.Device, error)
func (*Repository) SetLastSeen ¶ added in v1.34.0
func (*Repository) UpdatePushToken ¶ added in v1.34.0
func (r *Repository) UpdatePushToken(id, token string) error
type SelectFilter ¶
type SelectFilter func(*selectFilter)
func ActiveWithin ¶ added in v1.25.0
func ActiveWithin(duration time.Duration) 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 (*Service) Exists ¶ added in v1.22.0
func (s *Service) Exists(userID string, filter ...SelectFilter) (bool, error)
Exists checks if there exists a device that matches the provided filters.
If the device does not exist, it returns false and nil error. If there is an error during the query, it returns false and the error. Otherwise, it returns true and nil error.
func (*Service) Get ¶
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
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) 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 ¶
Select returns a list of devices for a specific user that match the provided filters.