3
0

upd(crm): serialization for ModuleFieldSet

This commit is contained in:
Tit Petric
2018-12-04 16:37:25 +01:00
parent eb9869bcdf
commit 0c5f1ea97e

View File

@@ -3,6 +3,9 @@ package types
import (
"time"
"database/sql/driver"
"encoding/json"
"github.com/jmoiron/sqlx/types"
systemTypes "github.com/crusttech/crust/system/types"
@@ -53,7 +56,7 @@ type (
Module struct {
ID uint64 `json:"moduleID,string" db:"id"`
Name string `json:"name" db:"name"`
Fields types.JSONText `json:"fields" db:"json"`
Fields ModuleFieldSet `json:"fields" db:"json"`
Page *Page `json:"page,omitempty"`
@@ -81,6 +84,8 @@ type (
Visible bool `json:"isVisible" db:"is_visible"`
}
ModuleFieldSet []ModuleField
// Page - page structure
Page struct {
ID uint64 `json:"pageID,string" db:"id"`
@@ -112,3 +117,14 @@ type (
Height int `json:"height"`
}
)
func (f *ModuleFieldSet) Scan(src interface{}) error {
if data, ok := src.([]byte); ok {
return json.Unmarshal(data, f)
}
return nil
}
func (f ModuleFieldSet) Value() (driver.Value, error) {
return json.Marshal(f)
}