Support primary key ID and unique key Name where api uses name

This commit is contained in:
breel
2020-08-02 09:59:47 -06:00
parent 37fe9415e7
commit 8e6e86955e
14 changed files with 68 additions and 49 deletions

View File

@@ -10,8 +10,8 @@ import (
)
const (
Name = "_id"
JSONName = "name"
ID = "_id"
Name = "name"
Relationship = "relationship"
Type = "type"
Title = "title"
@@ -22,14 +22,15 @@ const (
)
type One struct {
Name string `bson:"_id,omitempty" json:"name,omitempty"`
ID string `bson:"_id,omitempty" json:"_id,omitempty"`
Name string `bson:"name,omitempty" json:"name,omitempty"`
Type string `bson:"type,omitempty" json:"type,omitempty"`
Title string `bson:"title,omitempty" json:"title,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 map[string]One `bson:"connections" json:"connections,omitempty"`
Attachments map[string]string `bson:"attachments,omitempty" json:"attachments,omitempty"`
Attachments map[string]string `bson:"attachments" json:"attachments,omitempty"`
}
func (o One) Query() One {
@@ -75,10 +76,6 @@ func (o One) MarshalBSON() ([]byte, error) {
m[k] = strings.TrimSpace(v.(string))
}
}
if name, ok := m[JSONName]; ok {
m[Name] = name
delete(m, JSONName)
}
if !isMin {
connections := map[string]interface{}{}
switch m[Connections].(type) {