2016-09-29 02:44:05 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2017-03-15 15:55:30 +00:00
|
|
|
"context"
|
2016-09-29 02:44:05 +00:00
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
2016-10-12 16:35:34 +00:00
|
|
|
"strings"
|
2016-09-29 02:44:05 +00:00
|
|
|
|
2016-12-30 01:58:12 +00:00
|
|
|
"github.com/gorilla/mux"
|
2016-09-29 02:44:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func decodeCreateInviteRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
var req createInviteRequest
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-10-12 16:35:34 +00:00
|
|
|
if req.payload.Email != nil {
|
|
|
|
*req.payload.Email = strings.ToLower(*req.payload.Email)
|
|
|
|
}
|
2016-09-29 02:44:05 +00:00
|
|
|
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeDeleteInviteRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-10-14 21:08:57 +00:00
|
|
|
return deleteInviteRequest{ID: id}, nil
|
2016-09-29 02:44:05 +00:00
|
|
|
}
|
2016-10-13 18:21:47 +00:00
|
|
|
|
2016-12-30 01:58:12 +00:00
|
|
|
func decodeVerifyInviteRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
token, ok := vars["token"]
|
|
|
|
if !ok {
|
|
|
|
return 0, errBadRoute
|
|
|
|
}
|
|
|
|
return verifyInviteRequest{Token: token}, nil
|
|
|
|
}
|
|
|
|
|
2016-10-13 18:21:47 +00:00
|
|
|
func decodeListInvitesRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
opt, err := listOptionsFromRequest(r)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return listInvitesRequest{ListOptions: opt}, nil
|
|
|
|
}
|