package posts import ( "context" "encoding/json" "time" "git.aiterp.net/rpdata/logbot3/internal/api" "git.aiterp.net/rpdata/logbot3/internal/models" ) // Add adds a log file. func Add(ctx context.Context, log models.Log, time time.Time, kind, nick, text string) (models.Post, error) { input := addInput{ LogID: log.ID, Time: time, Kind: kind, Nick: nick, Text: text, } data, err := api.Global().Query(ctx, addGQL, map[string]interface{}{"input": input}, []string{"post.add"}) if err != nil { return models.Post{}, err } res := addResult{} err = json.Unmarshal(data, &res) if err != nil { return models.Post{}, err } return res.Post, nil } type addResult struct { Post models.Post `json:"addPost"` } type addInput struct { LogID string `json:"logId"` Time time.Time `json:"time"` Kind string `json:"kind"` Nick string `json:"nick"` Text string `json:"text"` } const addGQL = ` mutation AddPost($input:PostAddInput!) { addPost(input:$input) { id time kind nick text } } `