Commit 368c7f87bff1233ad437437804a91bd03833238a

Authored by Marko Tikvić
1 parent fbf92700f4
Exists in master

pagination work

Showing 2 changed files with 25 additions and 12 deletions   Show diff stats
... ... @@ -188,9 +188,9 @@ func GetTokenClaims(req *http.Request) (*TokenClaims, error) {
188 188 }
189 189  
190 190 // randomSalt returns a string of 32 random characters.
191   -const saltSize = 32
192   -
193 191 func randomSalt() (s string, err error) {
  192 + const saltSize = 32
  193 +
194 194 rawsalt := make([]byte, saltSize)
195 195  
196 196 _, err = rand.Read(rawsalt)
... ...
... ... @@ -47,6 +47,7 @@ type Translation struct {
47 47 FieldsLabels map[string]string `json:"fieldsLabels"`
48 48 }
49 49  
  50 +// output
50 51 type PaginationLinks struct {
51 52 Base string `json:"base"`
52 53 Next string `json:"next"`
... ... @@ -54,13 +55,25 @@ type PaginationLinks struct {
54 55 Self string `json:"self"`
55 56 }
56 57  
  58 +// input
57 59 type PaginationParameters struct {
  60 + URL string `json:"-"`
58 61 Offset int64 `json:"offset"`
59 62 Limit int64 `json:"limit"`
60 63 SortBy string `json:"sortBy"`
61 64 Order string `json:"order"`
62 65 }
63 66  
  67 +// TODO(marko)
  68 +func GetPaginationParameters(req *http.Request) (p PaginationParameters) {
  69 + return p
  70 +}
  71 +
  72 +// TODO(marko)
  73 +func (p *PaginationParameters) paginationLinks() (links PaginationLinks) {
  74 + return links
  75 +}
  76 +
64 77 type Payload struct {
65 78 Method string `json:"method"`
66 79 Params map[string]string `json:"params"`
... ... @@ -70,9 +83,9 @@ type Payload struct {
70 83 IdField string `json:"idField"`
71 84  
72 85 // Pagination
73   - Count int64 `json:"count"`
74   - Total int64 `json:"total"`
75   - Links *PaginationLinks `json:"_links"`
  86 + Count int64 `json:"count"`
  87 + Total int64 `json:"total"`
  88 + Links PaginationLinks `json:"_links"`
76 89  
77 90 // Data holds JSON payload. It can't be used for itteration.
78 91 Data interface{} `json:"data"`
... ... @@ -82,17 +95,17 @@ func (p *Payload) SetData(data interface{}) {
82 95 p.Data = data
83 96 }
84 97  
85   -func (p *Payload) SetPaginationInfo(reqUrl string, count, total int64, params PaginationParameters) {
  98 +func (p *Payload) SetPaginationInfo(count, total int64, params PaginationParameters) {
86 99 p.Count = count
87 100 p.Total = total
88   -
  101 + p.Links = params.paginationLinks()
89 102 }
90 103  
91   -// NewPayload returs a payload sceleton for entity described with etype.
92   -func NewPayload(r *http.Request, etype string) Payload {
93   - pload := metadata[etype]
94   - pload.Method = r.Method + " " + r.RequestURI
95   - return pload
  104 +// NewPayload returs a payload sceleton for entity described with key.
  105 +func NewPayload(r *http.Request, key string) Payload {
  106 + p := metadata[key]
  107 + p.Method = r.Method + " " + r.RequestURI
  108 + return p
96 109 }
97 110  
98 111 // DecodeJSON decodes JSON data from r to v.
... ...