|
|
package resolvers
import ( "context" "errors" "time"
"git.aiterp.net/rpdata/api/graph2/graphcore" "git.aiterp.net/rpdata/api/models" )
// Queries
func (r *queryResolver) Log(ctx context.Context, id string) (*models.Log, error) { return r.s.Logs.Find(ctx, id) }
func (r *queryResolver) Logs(ctx context.Context, filter *models.LogFilter) ([]*models.Log, error) { return r.s.Logs.List(ctx, filter) }
// Mutations
func (r *mutationResolver) AddLog(ctx context.Context, input graphcore.LogAddInput) (*models.Log, error) { open := input.Open != nil && *input.Open == true title := "" if input.Title != nil { title = *input.Title } event := "" if input.Event != nil { event = *input.Event } description := "" if input.Description != nil { description = *input.Description }
return r.s.Logs.Create(ctx, title, description, input.Channel, event, open) }
func (r *mutationResolver) ImportLog(ctx context.Context, input graphcore.LogImportInput) ([]*models.Log, error) { date := time.Time{} if input.Date != nil { date = *input.Date }
tz := time.UTC if input.Timezone != nil { parsedTZ, err := time.LoadLocation(*input.Timezone) if err != nil { return nil, errors.New("Unknown timezone: " + *input.Timezone) }
tz = parsedTZ }
sessionThreshold := time.Hour * 12 if input.SessionThresholdMs != nil { sessionThreshold = time.Duration(*input.SessionThresholdMs) * time.Millisecond }
return r.s.Logs.Import(ctx, input.Importer, date, tz, input.ChannelName, sessionThreshold, input.Data) }
func (r *mutationResolver) SplitLog(ctx context.Context, input graphcore.LogSplitInput) (*models.Log, error) { return r.s.Logs.SplitLog(ctx, input.LogID, input.StartPostID) }
func (r *mutationResolver) MergeLog(ctx context.Context, input graphcore.LogMergeInput) (*models.Log, error) { removeAfter := input.RemoveAfter != nil && *input.RemoveAfter
return r.s.Logs.MergeLogs(ctx, input.TargetLogID, input.SourceLogID, removeAfter) }
func (r *mutationResolver) EditLog(ctx context.Context, input graphcore.LogEditInput) (*models.Log, error) { update := models.LogUpdate{ Open: input.Open, Description: input.Description, EventName: input.Event, Title: input.Title, }
return r.s.Logs.Update(ctx, input.ID, update) }
func (r *mutationResolver) RemoveLog(ctx context.Context, input graphcore.LogRemoveInput) (*models.Log, error) { return r.s.Logs.Delete(ctx, input.ID) }
|