3
0

upd(codegen): enable imports with requests

This commit is contained in:
Tit Petric
2018-12-04 15:26:51 +01:00
parent d98d8be69a
commit 43554592e4
39 changed files with 172 additions and 227 deletions

View File

@@ -61,7 +61,13 @@
"entrypoint": "page",
"path": "/page",
"authentication": [],
"struct": [],
"struct": [
{
"imports": [
"sqlxTypes github.com/jmoiron/sqlx/types"
]
}
],
"apis": [
{
"name": "list",
@@ -117,7 +123,7 @@
"title": "Visible in navigation"
},
{
"type": "types.JSONText",
"type": "sqlxTypes.JSONText",
"name": "blocks",
"required": true,
"title": "Blocks JSON"
@@ -194,7 +200,7 @@
"title": "Visible in navigation"
},
{
"type": "types.JSONText",
"type": "sqlxTypes.JSONText",
"name": "blocks",
"required": true,
"title": "Blocks JSON"
@@ -255,7 +261,7 @@
{
"name": "Module",
"imports": [
"github.com/jmoiron/sqlx/types"
"sqlxTypes github.com/jmoiron/sqlx/types"
],
"fields": [
{
@@ -268,7 +274,7 @@
},
{
"name": "Fields",
"type": "types.JSONText",
"type": "sqlxTypes.JSONText",
"json": "fields",
"db": "json"
}
@@ -302,7 +308,7 @@
{
"name": "Content",
"imports": [
"github.com/jmoiron/sqlx/types"
"sqlxTypes github.com/jmoiron/sqlx/types"
],
"fields": [
{
@@ -315,7 +321,7 @@
},
{
"name": "Fields",
"type": "types.JSONText",
"type": "sqlxTypes.JSONText",
"db": "json"
}
]
@@ -352,7 +358,7 @@
"title": "Module Name"
},
{
"type": "types.JSONText",
"type": "sqlxTypes.JSONText",
"name": "fields",
"required": true,
"title": "Fields JSON"
@@ -476,7 +482,7 @@
"title": "Module Name"
},
{
"type": "types.JSONText",
"type": "sqlxTypes.JSONText",
"name": "fields",
"required": true,
"title": "Fields JSON"
@@ -552,7 +558,7 @@
],
"post": [
{
"type": "types.JSONText",
"type": "sqlxTypes.JSONText",
"name": "fields",
"required": true,
"title": "Content JSON"
@@ -604,7 +610,7 @@
],
"post": [
{
"type": "types.JSONText",
"type": "sqlxTypes.JSONText",
"name": "fields",
"required": true,
"title": "Content JSON"

View File

@@ -18,11 +18,11 @@
"db": "json",
"json": "fields",
"name": "Fields",
"type": "types.JSONText"
"type": "sqlxTypes.JSONText"
}
],
"imports": [
"github.com/jmoiron/sqlx/types"
"sqlxTypes github.com/jmoiron/sqlx/types"
],
"name": "Module"
},
@@ -64,11 +64,11 @@
{
"db": "json",
"name": "Fields",
"type": "types.JSONText"
"type": "sqlxTypes.JSONText"
}
],
"imports": [
"github.com/jmoiron/sqlx/types"
"sqlxTypes github.com/jmoiron/sqlx/types"
],
"name": "Content"
}
@@ -111,7 +111,7 @@
"name": "fields",
"required": true,
"title": "Fields JSON",
"type": "types.JSONText"
"type": "sqlxTypes.JSONText"
}
]
}
@@ -235,7 +235,7 @@
"name": "fields",
"required": true,
"title": "Fields JSON",
"type": "types.JSONText"
"type": "sqlxTypes.JSONText"
}
]
}
@@ -311,7 +311,7 @@
"name": "fields",
"required": true,
"title": "Content JSON",
"type": "types.JSONText"
"type": "sqlxTypes.JSONText"
}
]
}
@@ -363,7 +363,7 @@
"name": "fields",
"required": true,
"title": "Content JSON",
"type": "types.JSONText"
"type": "sqlxTypes.JSONText"
}
]
}

View File

@@ -3,7 +3,13 @@
"Description": "CRM module pages",
"Package": "crm",
"Interface": "Page",
"Struct": [],
"Struct": [
{
"imports": [
"sqlxTypes github.com/jmoiron/sqlx/types"
]
}
],
"Parameters": null,
"Protocol": "",
"Authentication": [],
@@ -66,7 +72,7 @@
"name": "blocks",
"required": true,
"title": "Blocks JSON",
"type": "types.JSONText"
"type": "sqlxTypes.JSONText"
}
]
}
@@ -143,7 +149,7 @@
"name": "blocks",
"required": true,
"title": "Blocks JSON",
"type": "types.JSONText"
"type": "sqlxTypes.JSONText"
}
]
}

View File

@@ -644,6 +644,13 @@
"Client ID",
"Session ID"
],
"struct": [
{
"imports": [
"github.com/crusttech/crust/internal/rbac"
]
}
],
"apis": [
{
"name": "list",

View File

@@ -2,7 +2,13 @@
"Title": "Permissions",
"Package": "sam",
"Interface": "Permissions",
"Struct": null,
"Struct": [
{
"imports": [
"github.com/crusttech/crust/internal/rbac"
]
}
],
"Parameters": {},
"Protocol": "",
"Authentication": [

View File

@@ -398,7 +398,7 @@
"struct": [
{
"imports": [
"github.com/jmoiron/sqlx/types"
"sqlxTypes github.com/jmoiron/sqlx/types"
]
}
],
@@ -464,7 +464,7 @@
},
{
"name": "meta",
"type": "types.JSONText",
"type": "sqlxTypes.JSONText",
"required": false,
"title": "Meta data"
},
@@ -536,7 +536,7 @@
},
{
"name": "meta",
"type": "types.JSONText",
"type": "sqlxTypes.JSONText",
"required": false,
"title": "Meta data"
},

View File

@@ -5,7 +5,7 @@
"Struct": [
{
"imports": [
"github.com/jmoiron/sqlx/types"
"sqlxTypes github.com/jmoiron/sqlx/types"
]
}
],
@@ -80,7 +80,7 @@
"name": "meta",
"required": false,
"title": "Meta data",
"type": "types.JSONText"
"type": "sqlxTypes.JSONText"
},
{
"name": "satosaID",
@@ -152,7 +152,7 @@
"name": "meta",
"required": false,
"title": "Meta data",
"type": "types.JSONText"
"type": "sqlxTypes.JSONText"
},
{
"name": "satosaID",

View File

@@ -38,9 +38,27 @@ function array_change_key_case_recursive($arr) {
}, array_change_key_case($arr));
}
function imports($api) {
$imports = array();
if (is_array($api['struct']))
foreach ($api['struct'] as $struct) {
if (isset($struct['imports']))
foreach ($struct['imports'] as $import) {
$import = explode(" ", $import);
if (count($import) == 1) {
$imports[] = '"' . $import[0] . '"';
} else {
$imports[] = $import[0] . ' "' . $import[1] . '"';
}
}
}
return array_unique($imports);
}
$tpl = new Monotek\MiniTPL\Template;
$tpl->set_compile_location("/tmp", true);
$tpl->add_default("newline", "\n");
$tpl->add_default("EOL", "\n");
$generators = array();
exec("find -L " . __DIR__ . "/" . $project . " -name index.php", $generators);
@@ -81,7 +99,7 @@ $parsers = array(
"[]uint64" => "parseUInt64A",
"int" => "parseInt",
"bool" => "parseBool",
"types.JSONText" => "parseJSONText",
"sqlxTypes.JSONText" => "parseJSONTextWithErr",
);
foreach ($generators as $generator) {

View File

@@ -19,14 +19,7 @@ foreach ($apis as $api) {
$tpl->assign("apis", $apis);
$tpl->assign("self", strtolower(substr($name, 0, 1)));
$tpl->assign("structs", $api['struct']);
$imports = array();
if (is_array($api['struct']))
foreach ($api['struct'] as $struct) {
if (isset($struct['imports']))
foreach ($struct['imports'] as $import) {
$imports[] = $import;
}
}
$imports = imports($api);
$tpl->assign("imports", $imports);
$tpl->assign("calls", $api['apis']);
$contents = str_replace("\n\n}", "\n}", $tpl->get());

View File

@@ -11,14 +11,7 @@ foreach ($apis as $api) {
$tpl->assign("api", $api);
$tpl->assign("self", strtolower(substr($name, 0, 1)));
$tpl->assign("structs", $api['struct']);
$imports = array();
if (is_array($api['struct']))
foreach ($api['struct'] as $struct) {
if (isset($struct['imports']))
foreach ($struct['imports'] as $import) {
$imports[] = $import;
}
}
$imports = imports($api);
$tpl->assign("imports", $imports);
$tpl->assign("calls", $api['apis']);
$contents = str_replace("\n\n}", "\n}", $tpl->get());

View File

@@ -19,14 +19,7 @@ foreach ($apis as $api) {
$tpl->assign("apis", $apis);
$tpl->assign("self", strtolower(substr($name, 0, 1)));
$tpl->assign("structs", $api['struct']);
$imports = array();
if (is_array($api['struct']))
foreach ($api['struct'] as $struct) {
if (isset($struct['imports']))
foreach ($struct['imports'] as $import) {
$imports[] = $import;
}
}
$imports = imports($api);
$tpl->assign("imports", $imports);
$tpl->assign("calls", $api['apis']);
$contents = str_replace("\n\n}", "\n}", $tpl->get());

View File

@@ -22,13 +22,7 @@ foreach ($apis as $api) {
$tpl->assign("apis", $apis);
$tpl->assign("self", strtolower(substr($name, 0, 1)));
$tpl->assign("structs", $api['struct']);
$imports = array();
foreach ($api['struct'] as $struct) {
if (isset($struct['imports']))
foreach ($struct['imports'] as $import) {
$imports[] = $import;
}
}
$imports = imports($api);
$tpl->assign("imports", $imports);
$tpl->assign("calls", $api['apis']);
$contents = str_replace("\n\n}", "\n}", $tpl->get());

View File

@@ -19,14 +19,7 @@ foreach ($apis as $api) {
$tpl->assign("apis", $apis);
$tpl->assign("self", strtolower(substr($name, 0, 1)));
$tpl->assign("structs", $api['struct']);
$imports = array();
if (is_array($api['struct']))
foreach ($api['struct'] as $struct) {
if (isset($struct['imports']))
foreach ($struct['imports'] as $import) {
$imports[] = $import;
}
}
$imports = imports($api);
$tpl->assign("imports", $imports);
$tpl->assign("calls", $api['apis']);
$contents = str_replace("\n\n}", "\n}", $tpl->get());

View File

@@ -11,14 +11,7 @@ foreach ($apis as $api) {
$tpl->assign("api", $api);
$tpl->assign("self", strtolower(substr($name, 0, 1)));
$tpl->assign("structs", $api['struct']);
$imports = array();
if (is_array($api['struct']))
foreach ($api['struct'] as $struct) {
if (isset($struct['imports']))
foreach ($struct['imports'] as $import) {
$imports[] = $import;
}
}
$imports = imports($api);
$tpl->assign("imports", $imports);
$tpl->assign("calls", $api['apis']);
$contents = str_replace("\n\n}", "\n}", $tpl->get());

View File

@@ -19,14 +19,7 @@ foreach ($apis as $api) {
$tpl->assign("apis", $apis);
$tpl->assign("self", strtolower(substr($name, 0, 1)));
$tpl->assign("structs", $api['struct']);
$imports = array();
if (is_array($api['struct']))
foreach ($api['struct'] as $struct) {
if (isset($struct['imports']))
foreach ($struct['imports'] as $import) {
$imports[] = $import;
}
}
$imports = imports($api);
$tpl->assign("imports", $imports);
$tpl->assign("calls", $api['apis']);
$contents = str_replace("\n\n}", "\n}", $tpl->get());

View File

@@ -19,14 +19,7 @@ foreach ($apis as $api) {
$tpl->assign("apis", $apis);
$tpl->assign("self", strtolower(substr($name, 0, 1)));
$tpl->assign("structs", $api['struct']);
$imports = array();
if (is_array($api['struct']))
foreach ($api['struct'] as $struct) {
if (isset($struct['imports']))
foreach ($struct['imports'] as $import) {
$imports[] = $import;
}
}
$imports = imports($api);
$tpl->assign("imports", $imports);
$tpl->assign("calls", $api['apis']);
$contents = str_replace("\n\n}", "\n}", $tpl->get());

View File

@@ -11,14 +11,7 @@ foreach ($apis as $api) {
$tpl->assign("api", $api);
$tpl->assign("self", strtolower(substr($name, 0, 1)));
$tpl->assign("structs", $api['struct']);
$imports = array();
if (is_array($api['struct']))
foreach ($api['struct'] as $struct) {
if (isset($struct['imports']))
foreach ($struct['imports'] as $import) {
$imports[] = $import;
}
}
$imports = imports($api);
$tpl->assign("imports", $imports);
$tpl->assign("calls", $api['apis']);
$contents = str_replace("\n\n}", "\n}", $tpl->get());

View File

@@ -19,14 +19,7 @@ foreach ($apis as $api) {
$tpl->assign("apis", $apis);
$tpl->assign("self", strtolower(substr($name, 0, 1)));
$tpl->assign("structs", $api['struct']);
$imports = array();
if (is_array($api['struct']))
foreach ($api['struct'] as $struct) {
if (isset($struct['imports']))
foreach ($struct['imports'] as $import) {
$imports[] = $import;
}
}
$imports = imports($api);
$tpl->assign("imports", $imports);
$tpl->assign("calls", $api['apis']);
$contents = str_replace("\n\n}", "\n}", $tpl->get());

View File

@@ -6,18 +6,18 @@ import (
"io"
"net/http"
"encoding/json"
"github.com/go-chi/chi"
"github.com/pkg/errors"
"github.com/jmoiron/sqlx/types"
"github.com/crusttech/crust/internal/rbac"
"mime/multipart"
"strings"
"github.com/go-chi/chi"
"github.com/pkg/errors"
{if !empty($imports)}{foreach ($imports as $import)}
{import}{EOL}{/foreach}{/if}
)
var _ = chi.URLParam
var _ = types.JSONText{}
var _ = multipart.FileHeader{}
var _ = rbac.Operation{}
{foreach $calls as $call}
// {name} {call.name} request parameters
@@ -68,17 +68,17 @@ func ({self} *{name|expose}{call.name|capitalize}) Fill(r *http.Request) (err er
{elseif substr($param.type, 0, 2) === '[]' && isset($parsers[$param.type])}
{self}.{param.name|expose} = {$parsers[$param.type]}({if $method === "post"}r.Form["{param.name}"]{else}urlQuery["{param.name}"]{/if})
{elseif $param.type === "*multipart.FileHeader"}
if _, {self}.{param.name|expose}, err = r.FormFile("{$param.name}"); err != nil {
return errors.Wrap(err, "error procesing uploaded file")
}
if _, {self}.{param.name|expose}, err = r.FormFile("{$param.name}"); err != nil {
return errors.Wrap(err, "error procesing uploaded file")
}
{elseif substr($param.type, 0, 2) !== '[]'}
if val, ok := {method|strtolower}["{param.name}"]; ok {
{if $param.type === "types.JSONText"}
if {self}.{param.name|expose}, err = {$parsers[$param.type]}(val); err != nil {
return err
}
if val, ok := {method|strtolower}["{param.name}"]; ok {
{if substr($parsers[$param.type], -7) === 'WithErr'}
if {self}.{param.name|expose}, err = {$parsers[$param.type]}(val); err != nil {
return err
}
{else}
{self}.{param.name|expose} = {if ($param.type !== "string")}{$parsers[$param.type]}(val){else}val{/if}
{self}.{param.name|expose} = {if ($param.type !== "string")}{$parsers[$param.type]}(val){else}val{/if}{EOL}
{/if}
}{/if}
{/foreach}

View File

@@ -5,8 +5,7 @@ package {package}
{if !empty($imports)}
import (
{foreach ($imports as $import)}
"{import}"
{/foreach}
{import}{EOL}{/foreach}
)
{/if}

View File

@@ -17,20 +17,17 @@ package request
import (
"encoding/json"
"github.com/crusttech/crust/internal/rbac"
"github.com/go-chi/chi"
"github.com/jmoiron/sqlx/types"
"github.com/pkg/errors"
"io"
"mime/multipart"
"net/http"
"strings"
"github.com/go-chi/chi"
"github.com/pkg/errors"
)
var _ = chi.URLParam
var _ = types.JSONText{}
var _ = multipart.FileHeader{}
var _ = rbac.Operation{}
// Field list request parameters
type FieldList struct {

View File

@@ -17,20 +17,19 @@ package request
import (
"encoding/json"
"github.com/crusttech/crust/internal/rbac"
"github.com/go-chi/chi"
"github.com/jmoiron/sqlx/types"
"github.com/pkg/errors"
"io"
"mime/multipart"
"net/http"
"strings"
"github.com/go-chi/chi"
"github.com/pkg/errors"
sqlxTypes "github.com/jmoiron/sqlx/types"
)
var _ = chi.URLParam
var _ = types.JSONText{}
var _ = multipart.FileHeader{}
var _ = rbac.Operation{}
// Module list request parameters
type ModuleList struct {
@@ -81,7 +80,7 @@ var _ RequestFiller = NewModuleList()
// Module create request parameters
type ModuleCreate struct {
Name string
Fields types.JSONText
Fields sqlxTypes.JSONText
}
func NewModuleCreate() *ModuleCreate {
@@ -121,7 +120,7 @@ func (m *ModuleCreate) Fill(r *http.Request) (err error) {
}
if val, ok := post["fields"]; ok {
if m.Fields, err = parseJSONText(val); err != nil {
if m.Fields, err = parseJSONTextWithErr(val); err != nil {
return err
}
}
@@ -271,7 +270,7 @@ var _ RequestFiller = NewModuleChart()
type ModuleEdit struct {
ModuleID uint64 `json:",string"`
Name string
Fields types.JSONText
Fields sqlxTypes.JSONText
}
func NewModuleEdit() *ModuleEdit {
@@ -312,7 +311,7 @@ func (m *ModuleEdit) Fill(r *http.Request) (err error) {
}
if val, ok := post["fields"]; ok {
if m.Fields, err = parseJSONText(val); err != nil {
if m.Fields, err = parseJSONTextWithErr(val); err != nil {
return err
}
}
@@ -426,7 +425,7 @@ var _ RequestFiller = NewModuleContentList()
// Module content/create request parameters
type ModuleContentCreate struct {
ModuleID uint64 `json:",string"`
Fields types.JSONText
Fields sqlxTypes.JSONText
}
func NewModuleContentCreate() *ModuleContentCreate {
@@ -463,7 +462,7 @@ func (m *ModuleContentCreate) Fill(r *http.Request) (err error) {
m.ModuleID = parseUInt64(chi.URLParam(r, "moduleID"))
if val, ok := post["fields"]; ok {
if m.Fields, err = parseJSONText(val); err != nil {
if m.Fields, err = parseJSONTextWithErr(val); err != nil {
return err
}
}
@@ -522,7 +521,7 @@ var _ RequestFiller = NewModuleContentRead()
type ModuleContentEdit struct {
ModuleID uint64 `json:",string"`
ContentID uint64 `json:",string"`
Fields types.JSONText
Fields sqlxTypes.JSONText
}
func NewModuleContentEdit() *ModuleContentEdit {
@@ -560,7 +559,7 @@ func (m *ModuleContentEdit) Fill(r *http.Request) (err error) {
m.ContentID = parseUInt64(chi.URLParam(r, "contentID"))
if val, ok := post["fields"]; ok {
if m.Fields, err = parseJSONText(val); err != nil {
if m.Fields, err = parseJSONTextWithErr(val); err != nil {
return err
}
}

View File

@@ -17,20 +17,19 @@ package request
import (
"encoding/json"
"github.com/crusttech/crust/internal/rbac"
"github.com/go-chi/chi"
"github.com/jmoiron/sqlx/types"
"github.com/pkg/errors"
"io"
"mime/multipart"
"net/http"
"strings"
"github.com/go-chi/chi"
"github.com/pkg/errors"
sqlxTypes "github.com/jmoiron/sqlx/types"
)
var _ = chi.URLParam
var _ = types.JSONText{}
var _ = multipart.FileHeader{}
var _ = rbac.Operation{}
// Page list request parameters
type PageList struct {
@@ -85,7 +84,7 @@ type PageCreate struct {
Title string
Description string
Visible bool
Blocks types.JSONText
Blocks sqlxTypes.JSONText
}
func NewPageCreate() *PageCreate {
@@ -141,7 +140,7 @@ func (p *PageCreate) Fill(r *http.Request) (err error) {
}
if val, ok := post["blocks"]; ok {
if p.Blocks, err = parseJSONText(val); err != nil {
if p.Blocks, err = parseJSONTextWithErr(val); err != nil {
return err
}
}
@@ -242,7 +241,7 @@ type PageEdit struct {
Title string
Description string
Visible bool
Blocks types.JSONText
Blocks sqlxTypes.JSONText
}
func NewPageEdit() *PageEdit {
@@ -299,7 +298,7 @@ func (p *PageEdit) Fill(r *http.Request) (err error) {
}
if val, ok := post["blocks"]; ok {
if p.Blocks, err = parseJSONText(val); err != nil {
if p.Blocks, err = parseJSONTextWithErr(val); err != nil {
return err
}
}

View File

@@ -11,7 +11,7 @@ import (
var truthy = regexp.MustCompile("^\\s*(t(rue)?|y(es)?|1)\\s*$")
func parseJSONText(s string) (types.JSONText, error) {
func parseJSONTextWithErr(s string) (types.JSONText, error) {
result := &types.JSONText{}
err := errors.Wrap(result.Scan(s), "error when parsing JSONText")
return *result, err

View File

@@ -63,7 +63,7 @@ CRM module definitions
| Parameter | Type | Method | Description | Default | Required? |
| --------- | ---- | ------ | ----------- | ------- | --------- |
| name | string | POST | Module Name | N/A | YES |
| fields | types.JSONText | POST | Fields JSON | N/A | YES |
| fields | sqlxTypes.JSONText | POST | Fields JSON | N/A | YES |
## Read module
@@ -302,7 +302,7 @@ Example bar chart with number of leads per country: select lead.country from lea
| --------- | ---- | ------ | ----------- | ------- | --------- |
| moduleID | uint64 | PATH | Module ID | N/A | YES |
| name | string | POST | Module Name | N/A | YES |
| fields | types.JSONText | POST | Fields JSON | N/A | YES |
| fields | sqlxTypes.JSONText | POST | Fields JSON | N/A | YES |
## Delete module
@@ -348,7 +348,7 @@ Example bar chart with number of leads per country: select lead.country from lea
| Parameter | Type | Method | Description | Default | Required? |
| --------- | ---- | ------ | ----------- | ------- | --------- |
| moduleID | uint64 | PATH | Module ID | N/A | YES |
| fields | types.JSONText | POST | Content JSON | N/A | YES |
| fields | sqlxTypes.JSONText | POST | Content JSON | N/A | YES |
## Read contents by ID from module section
@@ -379,7 +379,7 @@ Example bar chart with number of leads per country: select lead.country from lea
| --------- | ---- | ------ | ----------- | ------- | --------- |
| moduleID | uint64 | PATH | Module ID | N/A | YES |
| contentID | uint64 | PATH | Content ID | N/A | YES |
| fields | types.JSONText | POST | Content JSON | N/A | YES |
| fields | sqlxTypes.JSONText | POST | Content JSON | N/A | YES |
## Delete content row from module section
@@ -434,7 +434,7 @@ CRM module pages
| title | string | POST | Title | N/A | YES |
| description | string | POST | Description | N/A | NO |
| visible | bool | POST | Visible in navigation | N/A | NO |
| blocks | types.JSONText | POST | Blocks JSON | N/A | YES |
| blocks | sqlxTypes.JSONText | POST | Blocks JSON | N/A | YES |
## Get page details
@@ -481,7 +481,7 @@ CRM module pages
| title | string | POST | Title | N/A | YES |
| description | string | POST | Description | N/A | NO |
| visible | bool | POST | Visible in navigation | N/A | NO |
| blocks | types.JSONText | POST | Blocks JSON | N/A | YES |
| blocks | sqlxTypes.JSONText | POST | Blocks JSON | N/A | YES |
## Reorder pages

View File

@@ -324,7 +324,7 @@ An organisation may have many teams. Teams may have many channels available. Acc
| name | string | POST | Name | N/A | YES |
| handle | string | POST | Handle | N/A | YES |
| kind | string | POST | Kind (normal, bot) | N/A | NO |
| meta | types.JSONText | POST | Meta data | N/A | NO |
| meta | sqlxTypes.JSONText | POST | Meta data | N/A | NO |
| satosaID | string | POST | Satosa ID | N/A | NO |
| organisationID | uint64 | POST | Organisation ID | N/A | NO |
@@ -347,7 +347,7 @@ An organisation may have many teams. Teams may have many channels available. Acc
| name | string | POST | Name | N/A | YES |
| handle | string | POST | Handle | N/A | YES |
| kind | string | POST | Kind (normal, bot) | N/A | NO |
| meta | types.JSONText | POST | Meta data | N/A | NO |
| meta | sqlxTypes.JSONText | POST | Meta data | N/A | NO |
| satosaID | string | POST | Satosa ID | N/A | NO |
| organisationID | uint64 | POST | Organisation ID | N/A | NO |

View File

@@ -17,20 +17,17 @@ package request
import (
"encoding/json"
"github.com/crusttech/crust/internal/rbac"
"github.com/go-chi/chi"
"github.com/jmoiron/sqlx/types"
"github.com/pkg/errors"
"io"
"mime/multipart"
"net/http"
"strings"
"github.com/go-chi/chi"
"github.com/pkg/errors"
)
var _ = chi.URLParam
var _ = types.JSONText{}
var _ = multipart.FileHeader{}
var _ = rbac.Operation{}
// Attachment original request parameters
type AttachmentOriginal struct {

View File

@@ -17,20 +17,17 @@ package request
import (
"encoding/json"
"github.com/crusttech/crust/internal/rbac"
"github.com/go-chi/chi"
"github.com/jmoiron/sqlx/types"
"github.com/pkg/errors"
"io"
"mime/multipart"
"net/http"
"strings"
"github.com/go-chi/chi"
"github.com/pkg/errors"
)
var _ = chi.URLParam
var _ = types.JSONText{}
var _ = multipart.FileHeader{}
var _ = rbac.Operation{}
// Channel list request parameters
type ChannelList struct {

View File

@@ -17,20 +17,17 @@ package request
import (
"encoding/json"
"github.com/crusttech/crust/internal/rbac"
"github.com/go-chi/chi"
"github.com/jmoiron/sqlx/types"
"github.com/pkg/errors"
"io"
"mime/multipart"
"net/http"
"strings"
"github.com/go-chi/chi"
"github.com/pkg/errors"
)
var _ = chi.URLParam
var _ = types.JSONText{}
var _ = multipart.FileHeader{}
var _ = rbac.Operation{}
// Message create request parameters
type MessageCreate struct {

View File

@@ -17,20 +17,19 @@ package request
import (
"encoding/json"
"github.com/crusttech/crust/internal/rbac"
"github.com/go-chi/chi"
"github.com/jmoiron/sqlx/types"
"github.com/pkg/errors"
"io"
"mime/multipart"
"net/http"
"strings"
"github.com/go-chi/chi"
"github.com/pkg/errors"
"github.com/crusttech/crust/internal/rbac"
)
var _ = chi.URLParam
var _ = types.JSONText{}
var _ = multipart.FileHeader{}
var _ = rbac.Operation{}
// Permissions list request parameters
type PermissionsList struct {

View File

@@ -17,20 +17,17 @@ package request
import (
"encoding/json"
"github.com/crusttech/crust/internal/rbac"
"github.com/go-chi/chi"
"github.com/jmoiron/sqlx/types"
"github.com/pkg/errors"
"io"
"mime/multipart"
"net/http"
"strings"
"github.com/go-chi/chi"
"github.com/pkg/errors"
)
var _ = chi.URLParam
var _ = types.JSONText{}
var _ = multipart.FileHeader{}
var _ = rbac.Operation{}
// Search messages request parameters
type SearchMessages struct {

View File

@@ -2,7 +2,7 @@ package types
import "github.com/crusttech/crust/internal/rbac"
/* File is generated from sam/types/permissions/3-channel.json with permissions.go */
/* File is generated from sam/types/permissions/3-channel.json with permissions.go */
func (c *Channel) Permissions() []rbac.OperationGroup {
return []rbac.OperationGroup{

View File

@@ -2,7 +2,7 @@ package types
import "github.com/crusttech/crust/internal/rbac"
/* File is generated from sam/types/permissions/1-organisation.json with permissions.go */
/* File is generated from sam/types/permissions/1-organisation.json with permissions.go */
func (c *Organisation) Permissions() []rbac.OperationGroup {
return []rbac.OperationGroup{

View File

@@ -2,7 +2,7 @@ package types
import "github.com/crusttech/crust/internal/rbac"
/* File is generated from sam/types/permissions/2-team.json with permissions.go */
/* File is generated from sam/types/permissions/2-team.json with permissions.go */
func (c *Team) Permissions() []rbac.OperationGroup {
return []rbac.OperationGroup{

View File

@@ -17,20 +17,17 @@ package request
import (
"encoding/json"
"github.com/crusttech/crust/internal/rbac"
"github.com/go-chi/chi"
"github.com/jmoiron/sqlx/types"
"github.com/pkg/errors"
"io"
"mime/multipart"
"net/http"
"strings"
"github.com/go-chi/chi"
"github.com/pkg/errors"
)
var _ = chi.URLParam
var _ = types.JSONText{}
var _ = multipart.FileHeader{}
var _ = rbac.Operation{}
// Auth check request parameters
type AuthCheck struct {

View File

@@ -17,20 +17,17 @@ package request
import (
"encoding/json"
"github.com/crusttech/crust/internal/rbac"
"github.com/go-chi/chi"
"github.com/jmoiron/sqlx/types"
"github.com/pkg/errors"
"io"
"mime/multipart"
"net/http"
"strings"
"github.com/go-chi/chi"
"github.com/pkg/errors"
)
var _ = chi.URLParam
var _ = types.JSONText{}
var _ = multipart.FileHeader{}
var _ = rbac.Operation{}
// Organisation list request parameters
type OrganisationList struct {

View File

@@ -17,20 +17,17 @@ package request
import (
"encoding/json"
"github.com/crusttech/crust/internal/rbac"
"github.com/go-chi/chi"
"github.com/jmoiron/sqlx/types"
"github.com/pkg/errors"
"io"
"mime/multipart"
"net/http"
"strings"
"github.com/go-chi/chi"
"github.com/pkg/errors"
)
var _ = chi.URLParam
var _ = types.JSONText{}
var _ = multipart.FileHeader{}
var _ = rbac.Operation{}
// Team list request parameters
type TeamList struct {

View File

@@ -17,20 +17,19 @@ package request
import (
"encoding/json"
"github.com/crusttech/crust/internal/rbac"
"github.com/go-chi/chi"
"github.com/jmoiron/sqlx/types"
"github.com/pkg/errors"
"io"
"mime/multipart"
"net/http"
"strings"
"github.com/go-chi/chi"
"github.com/pkg/errors"
sqlxTypes "github.com/jmoiron/sqlx/types"
)
var _ = chi.URLParam
var _ = types.JSONText{}
var _ = multipart.FileHeader{}
var _ = rbac.Operation{}
// User list request parameters
type UserList struct {
@@ -86,7 +85,7 @@ type UserCreate struct {
Name string
Handle string
Kind string
Meta types.JSONText
Meta sqlxTypes.JSONText
SatosaID string
OrganisationID uint64 `json:",string"`
}
@@ -148,7 +147,7 @@ func (u *UserCreate) Fill(r *http.Request) (err error) {
}
if val, ok := post["meta"]; ok {
if u.Meta, err = parseJSONText(val); err != nil {
if u.Meta, err = parseJSONTextWithErr(val); err != nil {
return err
}
}
@@ -175,7 +174,7 @@ type UserEdit struct {
Name string
Handle string
Kind string
Meta types.JSONText
Meta sqlxTypes.JSONText
SatosaID string
OrganisationID uint64 `json:",string"`
}
@@ -238,7 +237,7 @@ func (u *UserEdit) Fill(r *http.Request) (err error) {
}
if val, ok := post["meta"]; ok {
if u.Meta, err = parseJSONText(val); err != nil {
if u.Meta, err = parseJSONTextWithErr(val); err != nil {
return err
}
}

View File

@@ -11,7 +11,7 @@ import (
var truthy = regexp.MustCompile("^\\s*(t(rue)?|y(es)?|1)\\s*$")
func parseJSONText(s string) (types.JSONText, error) {
func parseJSONTextWithErr(s string) (types.JSONText, error) {
result := &types.JSONText{}
err := errors.Wrap(result.Scan(s), "error when parsing JSONText")
return *result, err