3
0

update codegen for crm

This commit is contained in:
Tit Petric 2018-07-13 14:02:55 +02:00
parent c963dd7a2f
commit b186b94033
6 changed files with 29 additions and 10 deletions

View File

@ -40,7 +40,8 @@ foreach (array("structs", "handlers", "interfaces", "request", "") as $type) {
$tpl->load("http_$type.tpl");
$tpl->assign("parsers", array(
"uint64" => "parseUInt64"
"uint64" => "parseUInt64",
"bool" => "parseBool",
));
$tpl->assign("package", $api['package']);
$tpl->assign("name", $name);
@ -80,3 +81,13 @@ foreach (array("routes") as $type) {
file_put_contents($filename, $contents);
}
// camel case to snake case
function decamel($input) {
preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);
$ret = $matches[0];
foreach ($ret as &$match) {
$match = $match == strtoupper($match) ? strtolower($match) : lcfirst($match);
}
return implode('_', $ret);
}

View File

@ -32,6 +32,7 @@ func (moduleListRequest) new() *moduleListRequest {
}
func (m *moduleListRequest) Fill(r *http.Request) error {
r.ParseForm()
get := map[string]string{}
post := map[string]string{}
urlQuery := r.URL.Query()
@ -60,6 +61,7 @@ func (moduleEditRequest) new() *moduleEditRequest {
}
func (m *moduleEditRequest) Fill(r *http.Request) error {
r.ParseForm()
get := map[string]string{}
post := map[string]string{}
urlQuery := r.URL.Query()
@ -89,6 +91,7 @@ func (moduleContentListRequest) new() *moduleContentListRequest {
}
func (m *moduleContentListRequest) Fill(r *http.Request) error {
r.ParseForm()
get := map[string]string{}
post := map[string]string{}
urlQuery := r.URL.Query()
@ -117,6 +120,7 @@ func (moduleContentEditRequest) new() *moduleContentEditRequest {
}
func (m *moduleContentEditRequest) Fill(r *http.Request) error {
r.ParseForm()
get := map[string]string{}
post := map[string]string{}
urlQuery := r.URL.Query()
@ -146,6 +150,7 @@ func (moduleContentDeleteRequest) new() *moduleContentDeleteRequest {
}
func (m *moduleContentDeleteRequest) Fill(r *http.Request) error {
r.ParseForm()
get := map[string]string{}
post := map[string]string{}
urlQuery := r.URL.Query()

View File

@ -22,17 +22,17 @@ import (
type (
// Modules
Module struct {
ID uint64
Name string
ID uint64 `db:"id"`
Name string `db:"name"`
changed []string
}
// Modules
ModuleContentRow struct {
ID uint64 `db:"id"`
ModuleID uint64 `db:"module_id"`
Fields types.JSONText `db:"address"`
ID uint64 `db:"id" db:"id"`
ModuleID uint64 `db:"module_id" db:"module_id"`
Fields types.JSONText `db:"address" db:"fields"`
changed []string
}

View File

@ -24,6 +24,7 @@ func ({name|lcfirst}{call.name|capitalize}Request) new() *{name|lcfirst}{call.na
}
func ({self} *{name|lcfirst}{call.name|capitalize}Request) Fill(r *http.Request) error {
r.ParseForm()
get := map[string]string{}
post := map[string]string{}
urlQuery := r.URL.Query()
@ -37,9 +38,9 @@ func ({self} *{name|lcfirst}{call.name|capitalize}Request) Fill(r *http.Request)
{foreach $call.parameters as $method => $params}
{foreach $params as $param}
{if strtolower($method) === "path"}
{self}.{param.name} = chi.URLParam(r, "{param.name}")
{self}.{param.name} = {if ($param.type !== "string")}{$parsers[$param.type]}({/if}chi.URLParam(r, "{param.name}"){if ($param.type !== "string")}){/if}{newline}
{elseif substr($param.type, 0, 2) !== '[]'}
{self}.{param.name} = {if $param.type !== "string"}{$parsers[$param.type]}({method|strtolower}["{param.name}"]){else}{method|strtolower}["{param.name}"]{/if}{newline}
{self}.{param.name} = {if ($param.type !== "string")}{$parsers[$param.type]}({method|strtolower}["{param.name}"]){else}{method|strtolower}["{param.name}"]{/if}{newline}
{/if}
{/foreach}
{/foreach}

View File

@ -20,7 +20,7 @@ type ({foreach $structs as $struct}
// {api.title}
{struct.name} struct {
{foreach $struct.fields as $field}
{field.name} {field.type}{if $field.tag} `{$field.tag}`{/if}{newline}
{field.name} {field.type} `{if $field.tag}{$field.tag} {/if}db:"{if $field.dbname}{$field.dbname}{else}{$field.name|decamel}{/if}"`{newline}
{/foreach}
changed []string
@ -55,4 +55,4 @@ func ({self} *{struct.name}) Set{field.name}(value {field.type}) *{struct.name}
}
{/foreach}
{/foreach}
{/foreach}

View File

@ -31,6 +31,7 @@ func (typesListRequest) new() *typesListRequest {
}
func (t *typesListRequest) Fill(r *http.Request) error {
r.ParseForm()
get := map[string]string{}
post := map[string]string{}
urlQuery := r.URL.Query()
@ -56,6 +57,7 @@ func (typesTypeRequest) new() *typesTypeRequest {
}
func (t *typesTypeRequest) Fill(r *http.Request) error {
r.ParseForm()
get := map[string]string{}
post := map[string]string{}
urlQuery := r.URL.Query()