-
Notifications
You must be signed in to change notification settings - Fork 673
/
requests.go
92 lines (75 loc) · 1.66 KB
/
requests.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0
package api
import (
"errors"
"github.com/absmach/magistrala/internal/apiutil"
"github.com/absmach/magistrala/invitations"
)
const maxLimitSize = 100
var errMissingDomain = errors.New("missing domain")
type sendInvitationReq struct {
token string
UserID string `json:"user_id,omitempty"`
DomainID string `json:"domain_id,omitempty"`
Relation string `json:"relation,omitempty"`
Resend bool `json:"resend,omitempty"`
}
func (req *sendInvitationReq) validate() error {
if req.token == "" {
return apiutil.ErrBearerToken
}
if req.UserID == "" {
return apiutil.ErrMissingID
}
if req.DomainID == "" {
return errMissingDomain
}
if err := invitations.CheckRelation(req.Relation); err != nil {
return err
}
return nil
}
type listInvitationsReq struct {
token string
invitations.Page
}
func (req *listInvitationsReq) validate() error {
if req.token == "" {
return apiutil.ErrBearerToken
}
if req.Page.Limit > maxLimitSize || req.Page.Limit < 1 {
return apiutil.ErrLimitSize
}
return nil
}
type acceptInvitationReq struct {
token string
DomainID string `json:"domain_id,omitempty"`
}
func (req *acceptInvitationReq) validate() error {
if req.token == "" {
return apiutil.ErrBearerToken
}
if req.DomainID == "" {
return errMissingDomain
}
return nil
}
type invitationReq struct {
token string
userID string
domainID string
}
func (req *invitationReq) validate() error {
if req.token == "" {
return apiutil.ErrBearerToken
}
if req.userID == "" {
return apiutil.ErrMissingID
}
if req.domainID == "" {
return errMissingDomain
}
return nil
}