mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
7f636aef4f
- Introduce kolide.ListOptions to store pagination params (in the future it can also store ordering/filtering params) - Refactor service/datastore methods to take kolide.ListOptions - Implement pagination
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
func decodeCreateUserRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
var req createUserRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return req, nil
|
|
}
|
|
|
|
func decodeGetUserRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
id, err := idFromRequest(r, "id")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return getUserRequest{ID: id}, nil
|
|
}
|
|
|
|
func decodeListUsersRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
opt, err := listOptionsFromRequest(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return listUsersRequest{ListOptions: opt}, nil
|
|
}
|
|
|
|
func decodeChangePasswordRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
var req resetPasswordRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
return nil, err
|
|
}
|
|
return req, nil
|
|
}
|
|
|
|
func decodeModifyUserRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
id, err := idFromRequest(r, "id")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var req modifyUserRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
|
|
return nil, err
|
|
}
|
|
req.ID = id
|
|
return req, nil
|
|
}
|
|
|
|
func decodeForgotPasswordRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
var req forgotPasswordRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
return nil, err
|
|
}
|
|
return req, nil
|
|
}
|
|
|
|
func decodeResetPasswordRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
var req resetPasswordRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
return nil, err
|
|
}
|
|
return req, nil
|
|
}
|