Commit c430f3af5828b604349ed454102d925c8d478daa

Authored by Marko Tikvić
1 parent 4994f13a4a
Exists in master and in 1 other branch v2

fixed camel case correlation fields

Showing 1 changed file with 1 additions and 1 deletions   Show diff stats
1 package restutility 1 package restutility
2 2
3 import ( 3 import (
4 "net/http" 4 "net/http"
5 "strings" 5 "strings"
6 ) 6 )
7 7
8 type LangMap map[string]map[string]string 8 type LangMap map[string]map[string]string
9 9
10 type Field struct { 10 type Field struct {
11 Parameter string `json:"param"` 11 Parameter string `json:"param"`
12 Type string `json:"type"` 12 Type string `json:"type"`
13 Visible bool `json:"visible"` 13 Visible bool `json:"visible"`
14 Editable bool `json:"editable"` 14 Editable bool `json:"editable"`
15 } 15 }
16 16
17 type JSONParams struct { 17 type JSONParams struct {
18 Lang LangMap 18 Lang LangMap
19 Fields []Field 19 Fields []Field
20 IdField string 20 IdField string
21 Correlations []CorrelationField `json:"correlation_fields"` 21 Correlations []CorrelationField `json:"correlation_fields"`
22 } 22 }
23 23
24 type JSONPayload struct { 24 type JSONPayload struct {
25 Method string `json:"method"` 25 Method string `json:"method"`
26 Params map[string]string `json:"params"` 26 Params map[string]string `json:"params"`
27 Lang LangMap `json:"lang"` 27 Lang LangMap `json:"lang"`
28 Fields []Field `json:"fields"` 28 Fields []Field `json:"fields"`
29 Correlations []CorrelationField `json:"correlation_fields"` 29 Correlations []CorrelationField `json:"correlationFields"`
30 IdField string `json:"idField"` 30 IdField string `json:"idField"`
31 // Data can only hold slices of any type. It can't be used for itteration 31 // Data can only hold slices of any type. It can't be used for itteration
32 Data interface{} `json:"data"` 32 Data interface{} `json:"data"`
33 } 33 }
34 34
35 func NewJSONParams(lang LangMap, 35 func NewJSONParams(lang LangMap,
36 fields []Field, 36 fields []Field,
37 id string, 37 id string,
38 correlations []CorrelationField) JSONParams { 38 correlations []CorrelationField) JSONParams {
39 39
40 var jp JSONParams 40 var jp JSONParams
41 41
42 jp.Lang = lang 42 jp.Lang = lang
43 jp.Fields = fields 43 jp.Fields = fields
44 jp.IdField = id 44 jp.IdField = id
45 jp.Correlations = correlations 45 jp.Correlations = correlations
46 46
47 return jp 47 return jp
48 } 48 }
49 49
50 func NewJSONPayload(r *http.Request, table string) JSONPayload { 50 func NewJSONPayload(r *http.Request, table string) JSONPayload {
51 var obj JSONPayload 51 var obj JSONPayload
52 params := loadTable(table) 52 params := loadTable(table)
53 obj.Method = strings.ToLower(r.Method + " " + r.URL.Path) 53 obj.Method = strings.ToLower(r.Method + " " + r.URL.Path)
54 obj.Params = make(map[string]string, 0) 54 obj.Params = make(map[string]string, 0)
55 obj.Lang = make(map[string]map[string]string, 0) 55 obj.Lang = make(map[string]map[string]string, 0)
56 obj.Fields = make([]Field, 0) 56 obj.Fields = make([]Field, 0)
57 obj.IdField = params.IdField 57 obj.IdField = params.IdField
58 obj.Correlations = params.Correlations 58 obj.Correlations = params.Correlations
59 59
60 for k, m := range params.Lang { 60 for k, m := range params.Lang {
61 obj.Lang[k] = m 61 obj.Lang[k] = m
62 } 62 }
63 for _, f := range params.Fields { 63 for _, f := range params.Fields {
64 obj.Fields = append(obj.Fields, f) 64 obj.Fields = append(obj.Fields, f)
65 } 65 }
66 66
67 return obj 67 return obj
68 } 68 }
69 69
70 70