JSON API new spec with deref
This commit is contained in:
@@ -12,13 +12,14 @@ const (
|
||||
)
|
||||
|
||||
type One struct {
|
||||
Name string `bson:"_id,omitempty"`
|
||||
Type string `bson:"type,omitempty"`
|
||||
Title string `bson:"title,omitempty"`
|
||||
Image string `bson:"image,omitempty"`
|
||||
Text string `bson:"text,omitempty"`
|
||||
Modified int64 `bson:"modified,omitempty"`
|
||||
Connections []Peer `bson:"connections,omitempty"`
|
||||
Name string `bson:"_id,omitempty" json:"name,omitempty"`
|
||||
Type string `bson:"type,omitempty" json:"type,omitempty"`
|
||||
Title string `bson:"title,omitempty" json:"title,omitempty"`
|
||||
Image string `bson:"image,omitempty" json:"image,omitempty"`
|
||||
Text string `bson:"text,omitempty" json:"text,omitempty"`
|
||||
Relationship string `bson:"relationship,omitempty" json:"relationship,omitempty"`
|
||||
Modified int64 `bson:"modified,omitempty" json:"modified,omitempty"`
|
||||
Connections []One `bson:"connections,omitempty" json:"connections,omitempty"`
|
||||
}
|
||||
|
||||
func (o One) Query() One {
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package entity
|
||||
|
||||
type Peer struct {
|
||||
Name string `bson:"_id,omitempty"`
|
||||
Relationship string `bson:"relationship,omitempty"`
|
||||
}
|
||||
@@ -43,3 +43,7 @@ func (g Graph) Insert(ctx context.Context, one entity.One) error {
|
||||
func (g Graph) Update(ctx context.Context, one entity.One, modify interface{}) error {
|
||||
return g.mongo.Update(ctx, one, modify)
|
||||
}
|
||||
|
||||
func (g Graph) Delete(ctx context.Context, filter interface{}) error {
|
||||
return g.mongo.Delete(ctx, filter)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func TestIntegration(t *testing.T) {
|
||||
randomOne(),
|
||||
randomOne(),
|
||||
}
|
||||
ones[0].Connections = []entity.Peer{entity.Peer{Name: ones[2].Name, Relationship: ":("}}
|
||||
ones[0].Connections = []entity.One{entity.One{Name: ones[2].Name, Relationship: ":("}}
|
||||
|
||||
t.Run("graph.Insert(...)", func(t *testing.T) {
|
||||
for _, one := range ones {
|
||||
@@ -91,7 +91,7 @@ func TestIntegration(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("graph.Update(foo, ++...); graph.Update(foo, --if :()", func(t *testing.T) {
|
||||
err := graph.Update(ctx, ones[0].Query(), operator.Set{entity.Connections, []entity.Peer{entity.Peer{Name: "hello", Relationship: ":("}}})
|
||||
err := graph.Update(ctx, ones[0].Query(), operator.Set{entity.Connections, []entity.One{entity.One{Name: "hello", Relationship: ":("}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -139,6 +139,6 @@ func randomOne() entity.One {
|
||||
Image: "/path/to.jpg",
|
||||
Text: "tee hee xd",
|
||||
Modified: time.Now().UnixNano(),
|
||||
Connections: []entity.Peer{},
|
||||
Connections: []entity.One{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func NewMongo() Mongo {
|
||||
}
|
||||
return Mongo{
|
||||
client: c,
|
||||
db: "db",
|
||||
db: config.New().Database,
|
||||
col: "col",
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user