From e2e6b27057051b059346a2d1517ab0a105ec2cfe Mon Sep 17 00:00:00 2001 From: Lucas TESSON Date: Wed, 17 Apr 2024 18:58:57 +0200 Subject: [PATCH] feat(bracket): add support of brackets --- api/bracket.go | 26 ++++++++++++++++++++++++++ api/model.go | 7 +++++++ 2 files changed, 33 insertions(+) create mode 100644 api/bracket.go diff --git a/api/bracket.go b/api/bracket.go new file mode 100644 index 0000000..a5e8a15 --- /dev/null +++ b/api/bracket.go @@ -0,0 +1,26 @@ +package api + +type GetBracketsParams struct{} + +func (client *Client) GetBrackets(params *GetBracketsParams, opts ...Option) ([]*Bracket, error) { + bks := []*Bracket{} + if err := get(client, "/brackets", params, &bks, opts...); err != nil { + return nil, err + } + return bks, nil +} + +type PostBracketsParams struct { + ID float64 `json:"id"` // XXX Why is that a float64 ?? Why is it even sent by the client as CTFd will return a new one ? + Name string `json:"name"` + Description string `json:"description"` + Type string `json:"type"` +} + +func (client *Client) PostBrackets(params *PostBracketsParams, opts ...Option) (*Bracket, error) { + bk := &Bracket{} + if err := post(client, "/brackets", params, bk, opts...); err != nil { + return nil, err + } + return bk, nil +} diff --git a/api/model.go b/api/model.go index c0cda72..4de6ad8 100644 --- a/api/model.go +++ b/api/model.go @@ -22,6 +22,13 @@ type ( SolvedByMe bool `json:"solved_by_me"` } + Bracket struct { + ID int `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + Type string `json:"type"` + } + Type struct { ID *string `json:"id,omitempty"` Name string `json:"name"`