-
Notifications
You must be signed in to change notification settings - Fork 0
/
favorites.1.3.add_block_as_favorite.go
52 lines (43 loc) · 1.15 KB
/
favorites.1.3.add_block_as_favorite.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
package favorites
import (
"encoding/json"
"io"
"net/http"
"github.com/snowpal/pitch-building-blocks-sdk/lib"
helpers2 "github.com/snowpal/pitch-building-blocks-sdk/lib/helpers"
"github.com/snowpal/pitch-building-blocks-sdk/lib/structs/common"
"github.com/snowpal/pitch-building-blocks-sdk/lib/structs/response"
)
func AddBlockAsFavorite(jwtToken string, favoriteParam common.ResourceIdParam) (response.AddFavorite, error) {
resFavorite := response.AddFavorite{}
route, err := helpers2.GetRoute(
lib.RouteFavoritesAddBlockAsFavorite,
favoriteParam.BlockId,
favoriteParam.KeyId,
)
if err != nil {
return resFavorite, err
}
var req *http.Request
req, err = http.NewRequest(http.MethodPost, route, nil)
if err != nil {
return resFavorite, err
}
helpers2.AddUserHeaders(jwtToken, req)
var res *http.Response
res, err = helpers2.MakeRequest(req)
if err != nil {
return resFavorite, err
}
defer helpers2.CloseBody(res.Body)
var body []byte
body, err = io.ReadAll(res.Body)
if err != nil {
return resFavorite, err
}
err = json.Unmarshal(body, &resFavorite)
if err != nil {
return resFavorite, err
}
return resFavorite, nil
}