generator updates, implement types api for crm
This commit is contained in:
+2
-2
@@ -46,9 +46,9 @@ foreach (array("structs", "handlers", "interfaces", "request", "") as $type) {
|
||||
$tpl->assign("name", $name);
|
||||
$tpl->assign("self", strtolower(substr($name, 0, 1)));
|
||||
$tpl->assign("api", $api);
|
||||
$tpl->assign("fields", $api['struct']);
|
||||
$tpl->assign("structs", $api['struct']);
|
||||
$tpl->assign("calls", $api['apis']);
|
||||
$contents = $tpl->get();
|
||||
$contents = str_replace("\n}", "}", $tpl->get());
|
||||
|
||||
$save = true;
|
||||
if ($type === "" && file_exists($filename)) {
|
||||
|
||||
+2
-1
@@ -65,7 +65,7 @@ CRM module definitions
|
||||
| id | uint64 | POST | Module ID | N/A | NO |
|
||||
| name | string | POST | Module Name | N/A | YES |
|
||||
|
||||
## List contents from module section
|
||||
## List/read contents from module section
|
||||
|
||||
#### Method
|
||||
|
||||
@@ -77,6 +77,7 @@ CRM module definitions
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| id | string | GET | Module ID | N/A | NO |
|
||||
|
||||
## Add/update contents in module section
|
||||
|
||||
|
||||
+13
-3
@@ -34,8 +34,13 @@
|
||||
"path": "module",
|
||||
"authentication": [],
|
||||
"struct": [
|
||||
{ "name": "ID", "type": "uint64" },
|
||||
{ "name": "Name", "type": "string" }
|
||||
{
|
||||
"name": "Module",
|
||||
"fields": [
|
||||
{ "name": "ID", "type": "uint64" },
|
||||
{ "name": "Name", "type": "string" }
|
||||
]
|
||||
}
|
||||
],
|
||||
"apis": [
|
||||
{
|
||||
@@ -62,7 +67,12 @@
|
||||
{
|
||||
"name": "content/list",
|
||||
"method": "GET",
|
||||
"title": "List contents from module section"
|
||||
"title": "List/read contents from module section",
|
||||
"parameters": {
|
||||
"get": [
|
||||
{ "type": "string", "name": "id", "title": "Module ID" }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "content/edit",
|
||||
|
||||
@@ -5,12 +5,17 @@
|
||||
"Interface": "Module",
|
||||
"Struct": [
|
||||
{
|
||||
"name": "ID",
|
||||
"type": "uint64"
|
||||
},
|
||||
{
|
||||
"name": "Name",
|
||||
"type": "string"
|
||||
"fields": [
|
||||
{
|
||||
"name": "ID",
|
||||
"type": "uint64"
|
||||
},
|
||||
{
|
||||
"name": "Name",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"name": "Module"
|
||||
}
|
||||
],
|
||||
"Protocol": "",
|
||||
@@ -57,9 +62,17 @@
|
||||
{
|
||||
"Name": "content/list",
|
||||
"Method": "GET",
|
||||
"Title": "List contents from module section",
|
||||
"Title": "List/read contents from module section",
|
||||
"Path": "/content/list",
|
||||
"Parameters": null
|
||||
"Parameters": {
|
||||
"get": [
|
||||
{
|
||||
"name": "id",
|
||||
"title": "Module ID",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "content/edit",
|
||||
|
||||
+34
-3
@@ -2,20 +2,51 @@ package crm
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/titpetric/factory"
|
||||
)
|
||||
|
||||
var _ = errors.Wrap
|
||||
|
||||
func (*Module) List(r *moduleListRequest) (interface{}, error) {
|
||||
return nil, errors.New("Not implemented: Module.list")
|
||||
db, err := factory.Database.Get()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if r.id > 0 {
|
||||
m := Module{}.new()
|
||||
return m, db.Get(m, "select * from crm_module id=?", r.id)
|
||||
}
|
||||
|
||||
res := make([]Module, 0)
|
||||
err = db.Select(&res, "select * from crm_module order by name asc")
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (*Module) Edit(r *moduleEditRequest) (interface{}, error) {
|
||||
return nil, errors.New("Not implemented: Module.edit")
|
||||
db, err := factory.Database.Get()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m := Module{}.new()
|
||||
m.SetID(r.id).SetName(r.name)
|
||||
if m.GetID() > 0 {
|
||||
return m, db.Replace("crm_module", m)
|
||||
}
|
||||
m.SetID(factory.Sonyflake.NextID())
|
||||
return m, db.Insert("crm_module", m)
|
||||
}
|
||||
|
||||
func (*Module) ContentList(r *moduleContentListRequest) (interface{}, error) {
|
||||
return nil, errors.New("Not implemented: Module.content/list")
|
||||
if r.id > 0 {
|
||||
m := ModuleContentRow{}.new()
|
||||
return m, db.Get(m, "select * from crm_module id=?", r.id)
|
||||
}
|
||||
|
||||
res := make([]ModuleContentRow, 0)
|
||||
err = db.Select(&res, "select * from crm_module order by name asc")
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (*Module) ContentEdit(r *moduleContentEditRequest) (interface{}, error) {
|
||||
|
||||
@@ -66,6 +66,7 @@ var _ RequestFiller = moduleEditRequest{}.new()
|
||||
|
||||
// Module content/list request parameters
|
||||
type moduleContentListRequest struct {
|
||||
id string
|
||||
}
|
||||
|
||||
func (moduleContentListRequest) new() *moduleContentListRequest {
|
||||
@@ -83,6 +84,8 @@ func (m *moduleContentListRequest) Fill(r *http.Request) error {
|
||||
for name, param := range postVars {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
m.id = get["id"]
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+10
-6
@@ -1,17 +1,21 @@
|
||||
package crm
|
||||
|
||||
// Modules
|
||||
type Module struct {
|
||||
ID uint64
|
||||
Name string
|
||||
type (
|
||||
// Modules
|
||||
Module struct {
|
||||
ID uint64
|
||||
Name string
|
||||
|
||||
changed []string
|
||||
}
|
||||
changed []string
|
||||
}
|
||||
)
|
||||
|
||||
/* Constructors */
|
||||
func (Module) new() *Module {
|
||||
return &Module{}
|
||||
}
|
||||
|
||||
/* Getters/setters */
|
||||
func (m *Module) GetID() uint64 {
|
||||
return m.ID
|
||||
}
|
||||
|
||||
@@ -1,31 +1,39 @@
|
||||
package {package}
|
||||
|
||||
type ({foreach $structs as $struct}
|
||||
|
||||
{if strpos($name, "Literal") !== false}
|
||||
{foreach $fields as $field}
|
||||
{foreach $struct.fields as $field}
|
||||
{field}{newline}
|
||||
{/foreach}
|
||||
{else}
|
||||
// {api.title}
|
||||
type {name} struct {
|
||||
{foreach $fields as $field}
|
||||
{struct.name} struct {
|
||||
{foreach $struct.fields as $field}
|
||||
{field.name} {field.type}{if $field.tag} `{$field.tag}`{/if}{newline}
|
||||
{/foreach}
|
||||
|
||||
changed []string
|
||||
}
|
||||
|
||||
func ({name}) new() *{name} {
|
||||
return &{name}{}
|
||||
{/if}{/foreach}
|
||||
)
|
||||
|
||||
/* Constructors */
|
||||
{foreach $structs as $struct}
|
||||
func ({struct.name}) new() *{struct.name} {
|
||||
return &{struct.name}{}
|
||||
}
|
||||
{/foreach}
|
||||
|
||||
{/if}
|
||||
|
||||
{foreach $fields as $field}
|
||||
func ({self} *{name}) Get{field.name}() {field.type} {
|
||||
/* Getters/setters */
|
||||
{foreach $structs as $struct}
|
||||
{foreach $struct.fields as $field}
|
||||
func ({self} *{struct.name}) Get{field.name}() {field.type} {
|
||||
return {self}.{field.name}
|
||||
}
|
||||
|
||||
func ({self} *{name}) Set{field.name}(value {field.type}) *{name} {{if !$field.complex}
|
||||
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}.{field.name} = value
|
||||
@@ -36,3 +44,5 @@ func ({self} *{name}) Set{field.name}(value {field.type}) *{name} {{if !$field.c
|
||||
return {self}
|
||||
}
|
||||
{/foreach}
|
||||
|
||||
{/foreach}
|
||||
@@ -8,8 +8,7 @@ import (
|
||||
var _ = chi.URLParam
|
||||
|
||||
// Types list request parameters
|
||||
type typesListRequest struct {
|
||||
}
|
||||
type typesListRequest struct{}
|
||||
|
||||
func (typesListRequest) new() *typesListRequest {
|
||||
return &typesListRequest{}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package crm
|
||||
|
||||
// Types
|
||||
type Types struct {
|
||||
changed []string
|
||||
}
|
||||
type ()
|
||||
|
||||
func (Types) new() *Types {
|
||||
return &Types{}
|
||||
}
|
||||
/* Constructors */
|
||||
|
||||
/* Getters/setters */
|
||||
|
||||
Reference in New Issue
Block a user