generated from padok-team/yatas-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabaseV1.go
47 lines (38 loc) · 1.13 KB
/
DatabaseV1.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
package main
import (
"context"
"encoding/json"
"log"
"net/http"
"github.com/jomei/notionapi"
)
type DatabaseV1Service interface {
Create(ctx context.Context, request *DatabaseV1CreateRequest) (*notionapi.Database, error)
}
type DatabaseV1Client struct {
Client *NotionClientV1
}
type DatabaseV1CreateRequest struct {
Parent notionapi.Parent `json:"parent"`
Title []notionapi.RichText `json:"title"`
Icon *notionapi.Icon `json:"icon,omitempty"`
Properties notionapi.PropertyConfigs `json:"properties"`
IsInline bool `json:"is_inline"`
}
func (dc *DatabaseV1Client) Create(ctx context.Context, requestBody *DatabaseV1CreateRequest) (*notionapi.Database, error) {
res, err := dc.Client.request(ctx, http.MethodPost, "databases", nil, requestBody)
if err != nil {
return nil, err
}
defer func() {
if errClose := res.Body.Close(); errClose != nil {
log.Println("Failed to close body, should never happen")
}
}()
var response notionapi.Database
err = json.NewDecoder(res.Body).Decode(&response)
if err != nil {
return nil, err
}
return &response, nil
}