c5ecca1e1d
Full scope: storagenode/{console,nodestats,notifications,reputation,storagenodedb}, web/storagenode These columns are deprecated. They used to be for the uptime reputation system which has been replaced by downtime tracking with audits. Change-Id: I151d6569577d89733ac97af21a1d885323522b21
75 lines
2.3 KiB
Go
75 lines
2.3 KiB
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package notifications
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"storj.io/common/storj"
|
|
"storj.io/common/uuid"
|
|
)
|
|
|
|
// DB tells how application works with notifications database.
|
|
//
|
|
// architecture: Database
|
|
type DB interface {
|
|
Insert(ctx context.Context, notification NewNotification) (Notification, error)
|
|
List(ctx context.Context, cursor Cursor) (Page, error)
|
|
Read(ctx context.Context, notificationID uuid.UUID) error
|
|
ReadAll(ctx context.Context) error
|
|
UnreadAmount(ctx context.Context) (int, error)
|
|
}
|
|
|
|
// Type is a numeric value of specific notification type.
|
|
type Type int
|
|
|
|
const (
|
|
// TypeCustom is a common notification type which doesn't describe node's core functionality.
|
|
// TODO: change type name when all notification types will be known.
|
|
TypeCustom Type = 0
|
|
// TypeAuditCheckFailure is a notification type which describes node's audit check failure.
|
|
TypeAuditCheckFailure Type = 1
|
|
// TypeDisqualification is a notification type which describes node's disqualification status.
|
|
TypeDisqualification Type = 2
|
|
// TypeSuspension is a notification type which describes node's suspension status.
|
|
TypeSuspension Type = 3
|
|
)
|
|
|
|
// NewNotification holds notification entity info which is being received from satellite or local client.
|
|
type NewNotification struct {
|
|
SenderID storj.NodeID
|
|
Type Type
|
|
Title string
|
|
Message string
|
|
}
|
|
|
|
// Notification holds notification entity info which is being retrieved from database.
|
|
type Notification struct {
|
|
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"`
|
|
}
|
|
|
|
// Cursor holds notification cursor entity which is used to create listed page from database.
|
|
type Cursor struct {
|
|
Limit uint
|
|
Page uint
|
|
}
|
|
|
|
// Page holds notification page entity which is used to show listed page of notifications on UI.
|
|
type Page struct {
|
|
Notifications []Notification `json:"notifications"`
|
|
|
|
Offset uint64 `json:"offset"`
|
|
Limit uint `json:"limit"`
|
|
CurrentPage uint `json:"currentPage"`
|
|
PageCount uint `json:"pageCount"`
|
|
TotalCount uint64 `json:"totalCount"`
|
|
}
|