forked from ctfer-io/go-ctfd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
awards.go
49 lines (43 loc) · 1.43 KB
/
awards.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
package api
type GetAwardsParams struct {
UserID *int `schema:"user_id,omitempty"`
TeamID *int `schema:"team_id,omitempty"`
Type *string `schema:"type,omitempty"`
Value *int `schema:"value,omitempty"`
Category *int `schema:"category,omitempty"`
Icon *int `schema:"icon,omitempty"`
Q *string `schema:"q,omitempty"`
Field *string `schema:"field,omitempty"`
}
func (client *Client) GetAwards(params *GetAwardsParams, opts ...Option) ([]*Award, error) {
awards := []*Award{}
if err := get(client, "/awards", params, &awards, opts...); err != nil {
return nil, err
}
return awards, nil
}
type PostAwardsParams struct {
Name string `json:"name"`
Description string `json:"description"`
Category string `json:"category"`
Icon string `json:"icon"`
UserID int `json:"user_id"`
Value string `json:"value"`
}
func (client *Client) PostAwards(params *PostAwardsParams, opts ...Option) (*Award, error) {
award := &Award{}
if err := post(client, "/awards", params, &award, opts...); err != nil {
return nil, err
}
return award, nil
}
func (client *Client) GetAward(id string, opts ...Option) (*Award, error) {
award := &Award{}
if err := get(client, "/awards/"+id, nil, &award, opts...); err != nil {
return nil, err
}
return award, nil
}
func (client *Client) DeleteAward(id string, opts ...Option) error {
return delete(client, "/awards/"+id, nil, nil, opts...)
}