From e59eedb0b7989412c72e4ffc1e78ec014899db5d Mon Sep 17 00:00:00 2001 From: Tit Petric Date: Thu, 5 Jul 2018 14:00:40 +0000 Subject: [PATCH] update spec and generators --- crm/_gen.php | 10 ++++++- crm/docs/src/spec.json | 11 ++++++++ crm/docs/src/spec/module.json | 24 ++++++++++++++++ crm/module.structs.go | 50 ++++++++++++++++++++++++++++++++-- crm/templates/http_structs.tpl | 10 ++++++- crm/types.request.go | 3 +- 6 files changed, 103 insertions(+), 5 deletions(-) diff --git a/crm/_gen.php b/crm/_gen.php index ff7f61ec1..0e8bf795f 100755 --- a/crm/_gen.php +++ b/crm/_gen.php @@ -47,8 +47,16 @@ foreach (array("structs", "handlers", "interfaces", "request", "") as $type) { $tpl->assign("self", strtolower(substr($name, 0, 1))); $tpl->assign("api", $api); $tpl->assign("structs", $api['struct']); + $imports = array(); + foreach ($api['struct'] as $struct) { + if (isset($struct['imports'])) + foreach ($struct['imports'] as $import) { + $imports[] = $import; + } + } + $tpl->assign("imports", $imports); $tpl->assign("calls", $api['apis']); - $contents = str_replace("\n}", "}", $tpl->get()); + $contents = str_replace("\n\n}", "\n}", $tpl->get()); $save = true; if ($type === "" && file_exists($filename)) { diff --git a/crm/docs/src/spec.json b/crm/docs/src/spec.json index 522d35503..d8a1500ad 100644 --- a/crm/docs/src/spec.json +++ b/crm/docs/src/spec.json @@ -40,6 +40,17 @@ { "name": "ID", "type": "uint64" }, { "name": "Name", "type": "string" } ] + }, + { + "name": "ModuleContentRow", + "imports": [ + "github.com/jmoiron/sqlx/types" + ], + "fields": [ + { "name": "ID", "type": "uint64", "tag": "db:\"id\"" }, + { "name": "ModuleID", "type": "uint64", "tag": "db:\"module_id\"" }, + { "name": "Fields", "type": "types.JSONText", "tag": "db:\"address\"", "complex": true } + ] } ], "apis": [ diff --git a/crm/docs/src/spec/module.json b/crm/docs/src/spec/module.json index b36f5fff5..d3b1b4e56 100644 --- a/crm/docs/src/spec/module.json +++ b/crm/docs/src/spec/module.json @@ -16,6 +16,30 @@ } ], "name": "Module" + }, + { + "fields": [ + { + "name": "ID", + "tag": "db:\"id\"", + "type": "uint64" + }, + { + "name": "ModuleID", + "tag": "db:\"module_id\"", + "type": "uint64" + }, + { + "complex": true, + "name": "Fields", + "tag": "db:\"address\"", + "type": "types.JSONText" + } + ], + "imports": [ + "github.com/jmoiron/sqlx/types" + ], + "name": "ModuleContentRow" } ], "Protocol": "", diff --git a/crm/module.structs.go b/crm/module.structs.go index 414c4fa5c..727794fec 100644 --- a/crm/module.structs.go +++ b/crm/module.structs.go @@ -1,5 +1,9 @@ package crm +import ( + "github.com/jmoiron/sqlx/types" +) + type ( // Modules Module struct { @@ -8,12 +12,24 @@ type ( changed []string } + + // Modules + ModuleContentRow struct { + ID uint64 `db:"id"` + ModuleID uint64 `db:"module_id"` + Fields types.JSONText `db:"address"` + + changed []string + } ) /* Constructors */ func (Module) new() *Module { return &Module{} } +func (ModuleContentRow) new() *ModuleContentRow { + return &ModuleContentRow{} +} /* Getters/setters */ func (m *Module) GetID() uint64 { @@ -22,7 +38,7 @@ func (m *Module) GetID() uint64 { func (m *Module) SetID(value uint64) *Module { if m.ID != value { - m.changed = append(m.changed, "id") + m.changed = append(m.changed, "ID") m.ID = value } return m @@ -33,8 +49,38 @@ func (m *Module) GetName() string { func (m *Module) SetName(value string) *Module { if m.Name != value { - m.changed = append(m.changed, "name") + m.changed = append(m.changed, "Name") m.Name = value } return m } +func (m *ModuleContentRow) GetID() uint64 { + return m.ID +} + +func (m *ModuleContentRow) SetID(value uint64) *ModuleContentRow { + if m.ID != value { + m.changed = append(m.changed, "ID") + m.ID = value + } + return m +} +func (m *ModuleContentRow) GetModuleID() uint64 { + return m.ModuleID +} + +func (m *ModuleContentRow) SetModuleID(value uint64) *ModuleContentRow { + if m.ModuleID != value { + m.changed = append(m.changed, "ModuleID") + m.ModuleID = value + } + return m +} +func (m *ModuleContentRow) GetFields() types.JSONText { + return m.Fields +} + +func (m *ModuleContentRow) SetFields(value types.JSONText) *ModuleContentRow { + m.Fields = value + return m +} diff --git a/crm/templates/http_structs.tpl b/crm/templates/http_structs.tpl index d54b6868d..86d679e6c 100644 --- a/crm/templates/http_structs.tpl +++ b/crm/templates/http_structs.tpl @@ -1,5 +1,13 @@ package {package} +{if !empty($imports)} +import ( +{foreach ($imports as $import)} + "{import}" +{/foreach} +) +{/if} + type ({foreach $structs as $struct} {if strpos($name, "Literal") !== false} @@ -35,7 +43,7 @@ func ({self} *{struct.name}) Get{field.name}() {field.type} { func ({self} *{struct.name}) Set{field.name}(value {field.type}) *{struct.name} {{if !$field.complex} if {self}.{field.name} != value { - {self}.changed = append({self}.changed, "{field.name|strtolower}") + {self}.changed = append({self}.changed, "{field.name}") {self}.{field.name} = value } {else} diff --git a/crm/types.request.go b/crm/types.request.go index bebc6631e..0cff98a47 100644 --- a/crm/types.request.go +++ b/crm/types.request.go @@ -8,7 +8,8 @@ import ( var _ = chi.URLParam // Types list request parameters -type typesListRequest struct{} +type typesListRequest struct { +} func (typesListRequest) new() *typesListRequest { return &typesListRequest{}