The new logbot, not committed from the wrong terminal window this time.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

58 lines
1.0 KiB

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
}
}
`