3
0

update spec and generators

This commit is contained in:
Tit Petric
2018-07-05 14:00:40 +00:00
parent 1a3a6b1ac1
commit e59eedb0b7
6 changed files with 103 additions and 5 deletions
+9 -1
View File
@@ -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)) {
+11
View File
@@ -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": [
+24
View File
@@ -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": "",
+48 -2
View File
@@ -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
}
+9 -1
View File
@@ -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}
+2 -1
View File
@@ -8,7 +8,8 @@ import (
var _ = chi.URLParam
// Types list request parameters
type typesListRequest struct{}
type typesListRequest struct {
}
func (typesListRequest) new() *typesListRequest {
return &typesListRequest{}