Пример #1
0
        public async Task <ActionResult <IEnumerable <TaskAggregate> > > FilterTask([FromBody] FilterTaskArgs dto)
        {
            var result = await _tasksManager.FilterTasksAsync(dto);

            var list = result.list;

            if (result.fromCache)
            {
                Response.StatusCode = (int)_cacheFoundCode;
                return(new ActionResult <IEnumerable <TaskAggregate> >(list));
            }
            return(Ok(list));
        }
Пример #2
0
        public static string GetFilterArgsCachekey(FilterTaskArgs args)
        {
            string AddArg(string sourceString, string arg)
            {
                if (string.IsNullOrWhiteSpace(sourceString))
                {
                    return(arg);
                }

                return(sourceString + "&" + arg);
            }

            string argsString = string.Empty;

            if (args.Title != null)
            {
                argsString = AddArg(argsString, $"title={args.Title}");
            }

            if (!args.LabelsIds.IsNullOrEmpty())
            {
                argsString = AddArg(argsString, $"labels={string.Join(",",args.LabelsIds)}");
            }

            if (!args.ListsIds.IsNullOrEmpty())
            {
                argsString = AddArg(argsString, $"lists={string.Join(",",args.ListsIds)}");
            }

            if (!args.UsersIds.IsNullOrEmpty())
            {
                argsString = AddArg(argsString, $"users={string.Join(",",args.UsersIds)}");
            }

            if (!args.States.IsNullOrEmpty())
            {
                argsString = AddArg(argsString, $"states={string.Join(",",args.States.Select(s => (int)s))}");
            }

            return(string.Format(_tasksFilterCacheKeyPattern, argsString));
        }
 public async Task <ActionResult <IEnumerable <TaskAggregate> > > FilterTask([FromBody] FilterTaskArgs dto)
 {
     return(Ok(await _tasksManager.FilterTasksAsync(dto)));
 }
        public async Task <IEnumerable <TaskAggregate> > FilterTasksAsync(FilterTaskArgs args)
        {
            string AddStatement(string currentStatement, string addingPart)
            {
                if (string.IsNullOrWhiteSpace(currentStatement))
                {
                    return(" where " + addingPart);
                }

                return(currentStatement + " and " + addingPart);
            }

            string AddContainsStringStatement(string currentStatements, IEnumerable <string> items, string key)
            {
                if (!items.IsNullOrEmpty())
                {
                    currentStatements = AddStatement(
                        currentStatements,
                        $" {key} in ( {string.Join(", ", items.Select(i => $"'{i}'"))} ) "
                        );
                }

                return(currentStatements);
            }

            string whereStatement = string.Empty;

            whereStatement = AddContainsStringStatement(whereStatement, args.ListsIds, "ls.id");

            if (!args.UsersIds.IsNullOrEmpty())
            {
                whereStatement = AddStatement(
                    whereStatement,
                    $" t.id in ( select taskid from task_members where userid in ( {string.Join(", ", args.UsersIds.Select(u => $"'{u}'"))} ) ) "
                    );
            }

            if (!args.LabelsIds.IsNullOrEmpty())
            {
                whereStatement = AddStatement(
                    whereStatement,
                    $" t.id in ( select taskid from task_labels where labelid in ( {string.Join(", ", args.LabelsIds.Select(l => $"'{l}'"))} ) ) "
                    );
            }


            if (!args.States.IsNullOrEmpty())
            {
                whereStatement = AddStatement(
                    whereStatement,
                    $" t.state in ( {string.Join(", ", args.States.Select(s => (int)s))} ) "
                    );
            }

            if (!string.IsNullOrWhiteSpace(args.Title))
            {
                whereStatement = AddStatement(whereStatement,
                                              $" t.title like '{args.Title}' ");
            }

            if (string.IsNullOrWhiteSpace(whereStatement))
            {
                return(new List <TaskAggregate>());
            }

            string query = GetMergedSelectQuery(whereStatement);

            var queryResults = await _connection.QueryAsync <TaskQueryJoinedResult>(query);

            var aggregatedResult = AggregateQueryResult(queryResults.ToList());

            return(aggregatedResult);
        }
        public async Task <(IEnumerable <TaskAggregate> list, bool fromCache)> FilterTasksAsync(FilterTaskArgs args)
        {
            string cacheKey        = CacheSettings.GetFilterArgsCachekey(args);
            var    cachedTasksList = await _cache.TryGetCachedValueAsync <IEnumerable <TaskAggregate> >(cacheKey);

            if (cachedTasksList != null)
            {
                return(cachedTasksList, true);
            }

            var filteredTasksList = await _tasksRepository.FilterTasksAsync(args);

            await _cache.SetCacheValueAsync(cacheKey, filteredTasksList, CacheSettings.TasksFilterCacheLifetime);

            return(filteredTasksList, false);
        }
 public Task <IEnumerable <TaskAggregate> > FilterTasksAsync(FilterTaskArgs args)
 {
     return(_tasksRepository.FilterTasksAsync(args));
 }