package logs 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, channelName string, date time.Time, open bool, event string) (models.Log, error) { input := addInput{ Date: date, Channel: channelName, Open: &open, Event: &event, } data, err := api.Global().Query(ctx, addGQL, map[string]interface{}{"input": input}, []string{"log.add"}) if err != nil { return models.Log{}, err } res := addResult{} err = json.Unmarshal(data, &res) if err != nil { return models.Log{}, err } return res.Log, nil } type addResult struct { Log models.Log `json:"addLog"` } type addInput struct { Date time.Time `json:"date"` Channel string `json:"channel"` Title *string `json:"title"` Open *bool `json:"open"` Event *string `json:"event"` Description *string `json:"description"` } const addGQL = ` mutation AddLog($input:LogAddInput!) { addLog(input:$input) { id date channelName title eventName description open posts { id time kind nick text } } } `