2019-12-16 17:59:01 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package notifications
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
|
|
|
|
|
|
|
"storj.io/storj/pkg/storj"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DB tells how application works with notifications database.
|
|
|
|
//
|
|
|
|
// architecture: Database
|
|
|
|
type DB interface {
|
|
|
|
Insert(ctx context.Context, notification NewNotification) (Notification, error)
|
2019-12-17 15:38:55 +00:00
|
|
|
List(ctx context.Context, cursor Cursor) (Page, error)
|
2019-12-16 17:59:01 +00:00
|
|
|
Read(ctx context.Context, notificationID uuid.UUID) error
|
|
|
|
ReadAll(ctx context.Context) error
|
|
|
|
}
|
|
|
|
|
2019-12-17 15:38:55 +00:00
|
|
|
// Type is a numeric value of specific notification type.
|
|
|
|
type Type int
|
2019-12-16 17:59:01 +00:00
|
|
|
|
|
|
|
const (
|
2019-12-17 15:38:55 +00:00
|
|
|
// TypeCustom is a common notification type which doesn't describe node's core functionality.
|
2019-12-16 17:59:01 +00:00
|
|
|
// TODO: change type name when all notification types will be known
|
2019-12-17 15:38:55 +00:00
|
|
|
TypeCustom Type = 0
|
|
|
|
// TypeAuditCheckFailure is a notification type which describes node's audit check failure.
|
|
|
|
TypeAuditCheckFailure Type = 1
|
|
|
|
// TypeUptimeCheckFailure is a notification type which describes node's uptime check failure.
|
|
|
|
TypeUptimeCheckFailure Type = 2
|
|
|
|
// TypeDisqualification is a notification type which describes node's disqualification status.
|
|
|
|
TypeDisqualification Type = 3
|
2019-12-16 17:59:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewNotification holds notification entity info which is being received from satellite or local client.
|
|
|
|
type NewNotification struct {
|
|
|
|
SenderID storj.NodeID
|
2019-12-17 15:38:55 +00:00
|
|
|
Type Type
|
2019-12-16 17:59:01 +00:00
|
|
|
Title string
|
|
|
|
Message string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notification holds notification entity info which is being retrieved from database.
|
|
|
|
type Notification struct {
|
2019-12-17 15:38:55 +00:00
|
|
|
ID uuid.UUID `json:"id"`
|
|
|
|
SenderID storj.NodeID `json:"senderID"`
|
|
|
|
Type Type `json:"type"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
ReadAt *time.Time `json:"readAt"`
|
|
|
|
CreatedAt time.Time `json:"createdAt"`
|
2019-12-16 17:59:01 +00:00
|
|
|
}
|
|
|
|
|
2019-12-17 15:38:55 +00:00
|
|
|
// Cursor holds notification cursor entity which is used to create listed page from database.
|
|
|
|
type Cursor struct {
|
2019-12-16 17:59:01 +00:00
|
|
|
Limit uint
|
|
|
|
Page uint
|
|
|
|
}
|
|
|
|
|
2019-12-17 15:38:55 +00:00
|
|
|
// Page holds notification page entity which is used to show listed page of notifications on UI.
|
|
|
|
type Page struct {
|
|
|
|
Notifications []Notification `json:"notifications"`
|
2019-12-16 17:59:01 +00:00
|
|
|
|
2019-12-17 15:38:55 +00:00
|
|
|
Offset uint64 `json:"offset"`
|
|
|
|
Limit uint `json:"limit"`
|
|
|
|
CurrentPage uint `json:"currentPage"`
|
|
|
|
PageCount uint `json:"pageCount"`
|
|
|
|
TotalCount uint64 `json:"totalCount"`
|
2019-12-16 17:59:01 +00:00
|
|
|
}
|