-
Notifications
You must be signed in to change notification settings - Fork 12
/
groups.go
111 lines (84 loc) · 3.68 KB
/
groups.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package things
import (
"context"
"errors"
"time"
)
var (
// ErrAssignGroupThing indicates failure to assign thing to a group.
ErrAssignGroupThing = errors.New("failed to assign thing to a group")
// ErrUnassignGroupThing indicates failure to unassign thing from a group.
ErrUnassignGroupThing = errors.New("failed to unassign thing from a group")
// ErrThingAlreadyAssigned indicates that thing is already assigned.
ErrThingAlreadyAssigned = errors.New("thing is already assigned")
// ErrRetrieveGroupThings indicates failure to retrieve group things.
ErrRetrieveGroupThings = errors.New("failed to retrieve group things")
// ErrRetrieveGroupThingsByChannel indicates failure to retrieve group things by channel.
ErrRetrieveGroupThingsByChannel = errors.New("failed to retrieve group things by channel")
// ErrAssignGroupChannel indicates failure to assign channel to a group.
ErrAssignGroupChannel = errors.New("failed to assign channel to a group")
// ErrUnassignGroupChannel indicates failure to unassign channel from a group.
ErrUnassignGroupChannel = errors.New("failed to unassign channel from a group")
// ErrChannelAlreadyAssigned indicates that thing is already assigned.
ErrChannelAlreadyAssigned = errors.New("channel is already assigned")
// ErrRetrieveGroupChannels indicates failure to retrieve group channels.
ErrRetrieveGroupChannels = errors.New("failed to retrieve group channels")
)
// Identity contains ID and Email.
type Identity struct {
ID string
Email string
}
// GroupMetadata defines the Metadata type.
type GroupMetadata map[string]interface{}
// Group represents the group information.
type Group struct {
ID string
OwnerID string
Name string
Description string
Metadata GroupMetadata
CreatedAt time.Time
UpdatedAt time.Time
}
// GroupPage contains page related metadata as well as list of groups that
// belong to this page.
type GroupPage struct {
PageMetadata
Groups []Group
}
// GroupThingsPage contains page related metadata as well as list of members that
// belong to this page.
type GroupThingsPage struct {
PageMetadata
Things []Thing
}
type GroupChannelsPage struct {
PageMetadata
Channels []Channel
}
// GroupRepository specifies a group persistence API.
type GroupRepository interface {
// Save group
Save(ctx context.Context, g Group) (Group, error)
// Update a group
Update(ctx context.Context, g Group) (Group, error)
// Remove a groups
Remove(ctx context.Context, groupIDs ...string) error
// RetrieveByID retrieves group by its id
RetrieveByID(ctx context.Context, id string) (Group, error)
// RetrieveByIDs retrieves groups by their ids
RetrieveByIDs(ctx context.Context, groupIDs []string) (GroupPage, error)
// RetrieveByOwner retrieves all groups.
RetrieveByOwner(ctx context.Context, ownerID string, pm PageMetadata) (GroupPage, error)
// RetrieveGroupThings retrieves page of things that are assigned to a group identified by groupID.
RetrieveGroupThings(ctx context.Context, groupID string, pm PageMetadata) (GroupThingsPage, error)
// RetrieveGroupThingsByChannel retrieves page of disconnected things by channel that are assigned to a group same as channel.
RetrieveGroupThingsByChannel(ctx context.Context, grID, chID string, pm PageMetadata) (GroupThingsPage, error)
// RetrieveGroupChannels retrieves page of channels that are assigned to a group identified by groupID.
RetrieveGroupChannels(ctx context.Context, groupID string, pm PageMetadata) (GroupChannelsPage, error)
// RetrieveAll retrieves all groups.
RetrieveAll(ctx context.Context) ([]Group, error)
// RetrieveByAdmin retrieves all groups with pagination.
RetrieveByAdmin(ctx context.Context, pm PageMetadata) (GroupPage, error)
}