package queries import ( "context" "git.aiterp.net/rpdata/api/graphql/resolver/types" "git.aiterp.net/rpdata/api/model/log" ) // LogsArgs is args for the logs query type LogsArgs struct { Filter *struct { Search *string Characters *[]string Channels *[]string Events *[]string Open *bool Limit *int32 } } // Logs resolves the logs query func (r *QueryResolver) Logs(ctx context.Context, args *LogsArgs) ([]*types.LogResolver, error) { var logs []log.Log var err error filter := args.Filter if filter != nil { limit := 100 search := "" if filter.Search != nil { search = *filter.Search limit = 0 } channels := []string(nil) if filter.Channels != nil { channels = *filter.Channels limit = 0 } characters := []string(nil) if filter.Characters != nil { characters = *filter.Characters limit = 0 } events := []string(nil) if filter.Events != nil { events = *filter.Events limit = 0 } if filter.Limit != nil { limit = int(*filter.Limit) } open := filter.Open != nil && *filter.Open == true logs, err = log.ListSearch(search, channels, characters, events, open, limit) if err != nil { return nil, err } } else { logs, err = log.List(100) if err != nil { return nil, err } } resolvers := make([]*types.LogResolver, len(logs)) for i := range logs { resolvers[i] = &types.LogResolver{L: logs[i]} } return resolvers, nil }