anonstore

package
v11.1.4-modfix Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDeviceLimitReached = fmt.Errorf("device limit reached")

Functions

This section is empty.

Types

type AnonDBStore

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

func ProvideAnonDBStore

func ProvideAnonDBStore(sqlStore db.DB, deviceLimit int64) *AnonDBStore

func (*AnonDBStore) CountDevices

func (s *AnonDBStore) CountDevices(ctx context.Context, from time.Time, to time.Time) (int64, error)

func (*AnonDBStore) CreateOrUpdateDevice

func (s *AnonDBStore) CreateOrUpdateDevice(ctx context.Context, device *Device) error

func (*AnonDBStore) DeleteDevice

func (s *AnonDBStore) DeleteDevice(ctx context.Context, deviceID string) error

func (*AnonDBStore) DeleteDevicesOlderThan

func (s *AnonDBStore) DeleteDevicesOlderThan(ctx context.Context, olderThan time.Time) error

deleteOldDevices deletes all devices that have no been updated since the given time.

func (*AnonDBStore) ListDevices

func (s *AnonDBStore) ListDevices(ctx context.Context, from *time.Time, to *time.Time) ([]*Device, error)

func (*AnonDBStore) SearchDevices

func (s *AnonDBStore) SearchDevices(ctx context.Context, query *SearchDeviceQuery) (*SearchDeviceQueryResult, error)

type AnonStore

type AnonStore interface {
	// ListDevices returns all devices that have been updated between the given times.
	ListDevices(ctx context.Context, from *time.Time, to *time.Time) ([]*Device, error)
	// CreateOrUpdateDevice creates or updates a device.
	CreateOrUpdateDevice(ctx context.Context, device *Device) error
	// CountDevices returns the number of devices that have been updated between the given times.
	CountDevices(ctx context.Context, from time.Time, to time.Time) (int64, error)
	// DeleteDevice deletes a device by its ID.
	DeleteDevice(ctx context.Context, deviceID string) error
	// DeleteDevicesOlderThan deletes all devices that have no been updated since the given time.
	DeleteDevicesOlderThan(ctx context.Context, olderThan time.Time) error
	// SearchDevices searches for devices within the 30 days active.
	SearchDevices(ctx context.Context, query *SearchDeviceQuery) (*SearchDeviceQueryResult, error)
}

type Device

type Device struct {
	ID        int64     `json:"-" xorm:"id" db:"id"`
	DeviceID  string    `json:"deviceId" xorm:"device_id" db:"device_id"`
	ClientIP  string    `json:"clientIp" xorm:"client_ip" db:"client_ip"`
	UserAgent string    `json:"userAgent" xorm:"user_agent" db:"user_agent"`
	CreatedAt time.Time `json:"createdAt" xorm:"created_at" db:"created_at"`
	UpdatedAt time.Time `json:"updatedAt" xorm:"updated_at" db:"updated_at"`
}

func (*Device) CacheKey

func (a *Device) CacheKey() string

type DeviceSearchHitDTO

type DeviceSearchHitDTO struct {
	DeviceID   string    `json:"deviceId" xorm:"device_id" db:"device_id"`
	ClientIP   string    `json:"clientIp" xorm:"client_ip" db:"client_ip"`
	UserAgent  string    `json:"userAgent" xorm:"user_agent" db:"user_agent"`
	CreatedAt  time.Time `json:"createdAt" xorm:"created_at" db:"created_at"`
	UpdatedAt  time.Time `json:"updatedAt" xorm:"updated_at" db:"updated_at"`
	LastSeenAt time.Time `json:"lastSeenAt"`
}

type FakeAnonStore

type FakeAnonStore struct {
}

func (*FakeAnonStore) CountDevices

func (s *FakeAnonStore) CountDevices(ctx context.Context, from time.Time, to time.Time) (int64, error)

func (*FakeAnonStore) CreateOrUpdateDevice

func (s *FakeAnonStore) CreateOrUpdateDevice(ctx context.Context, device *Device) error

func (*FakeAnonStore) ListDevices

func (s *FakeAnonStore) ListDevices(ctx context.Context, from *time.Time, to *time.Time) ([]*Device, error)

func (*FakeAnonStore) SearchDevices

type SearchDeviceQuery

type SearchDeviceQuery struct {
	Query    string
	Page     int
	Limit    int
	From     time.Time
	To       time.Time
	SortOpts []model.SortOption
}

type SearchDeviceQueryResult

type SearchDeviceQueryResult struct {
	TotalCount int64                 `json:"totalCount"`
	Devices    []*DeviceSearchHitDTO `json:"devices"`
	Page       int                   `json:"page"`
	PerPage    int                   `json:"perPage"`
}

Jump to

Keyboard shortcuts

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