-
Notifications
You must be signed in to change notification settings - Fork 1
/
new_discussion_replied_meta.go
69 lines (58 loc) · 2.3 KB
/
new_discussion_replied_meta.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
package models
import (
"database/sql/driver"
"encoding/json"
"errors"
"github.com/google/uuid"
)
// NewDiscussionRepliedActivityMeta represents the notification data that is relevant to a new Discussion Reply
type NewDiscussionRepliedActivityMeta struct {
ActivityMetaBaseStruct
discussionRelation
modelPlanRelation
ReplyID uuid.UUID `json:"replyID"`
Content string `json:"content"`
}
// newNewDiscussionRepliedActivityMeta creates a New NewDiscussionRepliedActivityMeta
func newNewDiscussionRepliedActivityMeta(modelPlanID uuid.UUID, discussionID uuid.UUID, replyID uuid.UUID, content string) *NewDiscussionRepliedActivityMeta {
version := 0 //iterate this if this type ever updates
return &NewDiscussionRepliedActivityMeta{
ActivityMetaBaseStruct: NewActivityMetaBaseStruct(ActivityNewDiscussionReply, version),
discussionRelation: NewDiscussionRelation(discussionID),
modelPlanRelation: NewModelPlanRelation(modelPlanID),
ReplyID: replyID,
Content: content,
}
}
// NewNewDiscussionRepliedActivity creates a New New Discussion Replied type of Activity
func NewNewDiscussionRepliedActivity(actorID uuid.UUID, modelPlanID uuid.UUID, discussionID uuid.UUID, replyID uuid.UUID, content string) *Activity {
return &Activity{
baseStruct: NewBaseStruct(actorID),
ActorID: actorID,
EntityID: discussionID,
ActivityType: ActivityNewDiscussionReply,
MetaData: newNewDiscussionRepliedActivityMeta(modelPlanID, discussionID, replyID, content),
}
}
// Future Enhancement: --> Refactor these all to have a generic scan / value
// Value allows us to satisfy the valuer interface so we can write to the database
// We need to do a specific implementation instead of relying on the implementation of the embedded struct, as that will only serialize the common data
func (d NewDiscussionRepliedActivityMeta) Value() (driver.Value, error) {
j, err := json.Marshal(d)
return j, err
}
// Scan implements the scanner interface so we can translate the JSONb from the db to an object in GO
func (d *NewDiscussionRepliedActivityMeta) Scan(src interface{}) error {
if src == nil {
return nil
}
source, ok := src.([]byte)
if !ok {
return errors.New("type assertion .([]byte) failed")
}
err := json.Unmarshal(source, d)
if err != nil {
return err
}
return nil
}