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.
67 lines
1.2 KiB
67 lines
1.2 KiB
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
|
|
}
|
|
}
|
|
}
|
|
`
|