-
Notifications
You must be signed in to change notification settings - Fork 394
/
notifications.go
74 lines (63 loc) · 2.27 KB
/
notifications.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// 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"`
}