2016-09-26 18:48:55 +00:00
|
|
|
package service
|
2016-09-04 05:13:42 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
func decodeCreateQueryRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
var req createQueryRequest
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeModifyQueryRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var req modifyQueryRequest
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
req.ID = id
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeDeleteQueryRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var req deleteQueryRequest
|
|
|
|
req.ID = id
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2016-12-09 17:12:45 +00:00
|
|
|
func decodeDeleteQueriesRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
var req deleteQueriesRequest
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2016-09-04 05:13:42 +00:00
|
|
|
func decodeGetQueryRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var req getQueryRequest
|
|
|
|
req.ID = id
|
|
|
|
return req, nil
|
|
|
|
}
|
2016-10-13 18:21:47 +00:00
|
|
|
|
|
|
|
func decodeListQueriesRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
opt, err := listOptionsFromRequest(r)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return listQueriesRequest{ListOptions: opt}, nil
|
|
|
|
}
|