apollo-backend/internal/domain/device.go

46 lines
1.5 KiB
Go
Raw Permalink Normal View History

2021-07-24 20:17:54 +00:00
package domain
2021-10-12 14:18:40 +00:00
import (
"context"
2022-03-28 21:05:01 +00:00
"time"
2021-10-12 14:18:40 +00:00
validation "github.com/go-ozzo/ozzo-validation/v4"
)
2021-07-24 20:17:54 +00:00
2021-09-11 14:53:19 +00:00
const (
DeviceReceiptCheckPeriodDuration = 4 * time.Hour
2022-03-28 21:05:01 +00:00
DeviceActiveAfterReceitCheckDuration = 30 * 24 * time.Hour // ~1 month
DeviceGracePeriodAfterReceiptExpiry = 30 * 24 * time.Hour // ~1 month
2021-09-11 14:53:19 +00:00
)
2021-07-24 20:17:54 +00:00
type Device struct {
2022-03-28 21:05:01 +00:00
ID int64
APNSToken string
Sandbox bool
ExpiresAt time.Time
GracePeriodExpiresAt time.Time
2021-07-24 20:17:54 +00:00
}
2021-10-12 14:18:40 +00:00
func (dev *Device) Validate() error {
return validation.ValidateStruct(dev,
validation.Field(&dev.APNSToken, validation.Required, validation.Length(64, 200)),
)
}
2021-07-24 20:17:54 +00:00
type DeviceRepository interface {
2021-09-25 16:56:01 +00:00
GetByID(ctx context.Context, id int64) (Device, error)
2021-07-24 20:17:54 +00:00
GetByAPNSToken(ctx context.Context, token string) (Device, error)
2022-03-12 17:50:05 +00:00
GetInboxNotifiableByAccountID(ctx context.Context, id int64) ([]Device, error)
GetWatcherNotifiableByAccountID(ctx context.Context, id int64) ([]Device, error)
2021-08-14 17:42:28 +00:00
GetByAccountID(ctx context.Context, id int64) ([]Device, error)
2021-07-26 16:34:26 +00:00
CreateOrUpdate(ctx context.Context, dev *Device) error
2021-07-24 20:17:54 +00:00
Update(ctx context.Context, dev *Device) error
Create(ctx context.Context, dev *Device) error
Delete(ctx context.Context, token string) error
SetNotifiable(ctx context.Context, dev *Device, acct *Account, inbox, watcher, global bool) error
GetNotifiable(ctx context.Context, dev *Device, acct *Account) (bool, bool, bool, error)
2021-08-14 16:08:17 +00:00
2022-03-28 21:05:01 +00:00
PruneStale(ctx context.Context, expiry time.Time) (int64, error)
2021-07-24 20:17:54 +00:00
}