Browse Source

graph2, model: Added Comment type to Change.

module-madness-pointers
Gisle Aune 6 years ago
parent
commit
06fbfc90c5
  1. 2
      graph2/schema/types/Change.gql
  2. 4
      models/change-model.go
  3. 6
      models/change.go
  4. 2
      models/changekeys/many_test.go
  5. 5
      models/changekeys/one_test.go
  6. 4
      models/changes/submit.go

2
graph2/schema/types/Change.gql

@ -27,7 +27,7 @@ type Change {
objects: [ChangeObject!]! objects: [ChangeObject!]!
} }
union ChangeObject = Character | Channel | Log | Post | Story | Tag | Chapter
union ChangeObject = Character | Channel | Log | Post | Story | Tag | Chapter | Comment
""" """
A change key is a key associated with a change, used for filtering A change key is a key associated with a change, used for filtering

4
models/change-model.go

@ -24,12 +24,14 @@ const (
ChangeModelTag ChangeModel = "Tag" ChangeModelTag ChangeModel = "Tag"
// ChangeModelChapter is a value of ChangeModel // ChangeModelChapter is a value of ChangeModel
ChangeModelChapter ChangeModel = "Chapter" ChangeModelChapter ChangeModel = "Chapter"
// ChangeModelComment is a value of ChangeModel
ChangeModelComment ChangeModel = "Comment"
) )
// IsValid returns true if the underlying string is one of the correct values. // IsValid returns true if the underlying string is one of the correct values.
func (e ChangeModel) IsValid() bool { func (e ChangeModel) IsValid() bool {
switch e { switch e {
case ChangeModelCharacter, ChangeModelChannel, ChangeModelLog, ChangeModelPost, ChangeModelStory, ChangeModelTag, ChangeModelChapter:
case ChangeModelCharacter, ChangeModelChannel, ChangeModelLog, ChangeModelPost, ChangeModelStory, ChangeModelTag, ChangeModelChapter, ChangeModelComment:
return true return true
} }
return false return false

6
models/change.go

@ -19,6 +19,7 @@ type Change struct {
Stories []Story `bson:"stories"` Stories []Story `bson:"stories"`
Tags []Tag `bson:"tags"` Tags []Tag `bson:"tags"`
Chapters []Chapter `bson:"chapters"` Chapters []Chapter `bson:"chapters"`
Comments []Comment `bson:"comments"`
} }
// ChangeKey is a key for a change that can be used when subscribing to them. // ChangeKey is a key for a change that can be used when subscribing to them.
@ -29,7 +30,7 @@ type ChangeKey struct {
// Objects makes a combined, mixed array of all the models stored in this change. // Objects makes a combined, mixed array of all the models stored in this change.
func (change *Change) Objects() []interface{} { func (change *Change) Objects() []interface{} {
data := make([]interface{}, 0, len(change.Logs)+len(change.Characters)+len(change.Channels)+len(change.Posts)+len(change.Stories)+len(change.Tags)+len(change.Chapters))
data := make([]interface{}, 0, len(change.Logs)+len(change.Characters)+len(change.Channels)+len(change.Posts)+len(change.Stories)+len(change.Tags)+len(change.Chapters)+len(change.Comments))
for _, log := range change.Logs { for _, log := range change.Logs {
data = append(data, log) data = append(data, log)
@ -52,6 +53,9 @@ func (change *Change) Objects() []interface{} {
for _, chapter := range change.Chapters { for _, chapter := range change.Chapters {
data = append(data, chapter) data = append(data, chapter)
} }
for _, comment := range change.Comments {
data = append(data, comment)
}
return data return data
} }

2
models/changekeys/many_test.go

@ -22,6 +22,7 @@ func TestMany(t *testing.T) {
}, },
}, },
models.Post{ID: "P5"}, models.Post{ID: "P5"},
models.Comment{ID: "SCC1234"},
} }
expectations := []models.ChangeKey{ expectations := []models.ChangeKey{
@ -33,6 +34,7 @@ func TestMany(t *testing.T) {
{Model: "Character", ID: "C17"}, {Model: "Character", ID: "C17"},
{Model: "Channel", ID: "#Stuff"}, {Model: "Channel", ID: "#Stuff"},
{Model: "Post", ID: "P5"}, {Model: "Post", ID: "P5"},
{Model: "Comment", ID: "SCC1234"},
} }
results := changekeys.Many(data...) results := changekeys.Many(data...)

5
models/changekeys/one_test.go

@ -28,6 +28,11 @@ func TestOne(t *testing.T) {
models.Log{ID: "2018-10-23_210303325_RedrockAgency", ShortID: "L807"}, models.Log{ID: "2018-10-23_210303325_RedrockAgency", ShortID: "L807"},
models.ChangeKey{Model: "Log", ID: "2018-10-23_210303325_RedrockAgency"}, models.ChangeKey{Model: "Log", ID: "2018-10-23_210303325_RedrockAgency"},
}, },
{
"Comment_SCC1234",
models.Comment{ID: "SCC1234"},
models.ChangeKey{Model: "Comment", ID: "SCC1234"},
},
} }
for _, row := range table { for _, row := range table {

4
models/changes/submit.go

@ -81,6 +81,10 @@ func Submit(model, op, author string, listed bool, keys []models.ChangeKey, obje
change.Chapters = append(change.Chapters, object) change.Chapters = append(change.Chapters, object)
case []models.Chapter: case []models.Chapter:
change.Chapters = append(change.Chapters, object...) change.Chapters = append(change.Chapters, object...)
case models.Comment:
change.Comments = append(change.Comments, object)
case []models.Comment:
change.Comments = append(change.Comments, object...)
default: default:
log.Printf("Warning: unrecognized object in change: %#+v", object) log.Printf("Warning: unrecognized object in change: %#+v", object)
} }

Loading…
Cancel
Save