Files: added tags filtering

This commit is contained in:
Maksim Chegulov 2022-05-26 16:37:31 +03:00
parent 518fe17d14
commit 3123bbd187
6 changed files with 17 additions and 9 deletions

View File

@ -39,7 +39,7 @@ public interface ITagDao<T>
IAsyncEnumerable<Tag> GetTagsAsync(Guid owner, TagType tagType);
IAsyncEnumerable<Tag> GetTagsAsync(string name, TagType tagType);
IAsyncEnumerable<Tag> GetTagsAsync(string[] names, TagType tagType);
IAsyncEnumerable<TagInfo> GetTagsInfoAsync(string searchText, TagType tagType, bool byName);
IAsyncEnumerable<TagInfo> GetTagsInfoAsync(string searchText, TagType tagType, bool byName, int from = 0, int count = 0);
IAsyncEnumerable<TagInfo> GetTagsInfoAsync(IEnumerable<int> ids);
IEnumerable<Tag> SaveTags(IEnumerable<Tag> tag);
IEnumerable<Tag> SaveTags(Tag tag);

View File

@ -215,7 +215,7 @@ internal class TagDao<T> : AbstractDao, ITagDao<T>
}
}
public async IAsyncEnumerable<TagInfo> GetTagsInfoAsync(string searchText, TagType tagType, bool byName)
public async IAsyncEnumerable<TagInfo> GetTagsInfoAsync(string searchText, TagType tagType, bool byName, int from = 0, int count = 0)
{
var q = Query(FilesDbContext.Tag).AsNoTracking().Where(r => r.Type == tagType);
@ -229,6 +229,13 @@ internal class TagDao<T> : AbstractDao, ITagDao<T>
q = q.Where(r => r.Name.ToLower().Contains(lowerText));
}
if (count != 0)
{
q = q.Take(count);
}
q = q.Skip(from);
await foreach (var tag in FromQueryAsync(q).ConfigureAwait(false))
{
yield return tag;

View File

@ -467,7 +467,7 @@ internal abstract class ThirdPartyProviderDao<T> : ThirdPartyProviderDao, IDispo
return AsyncEnumerable.Empty<Tag>();
}
public IAsyncEnumerable<TagInfo> GetTagsInfoAsync(string searchText, TagType tagType, bool byName)
public IAsyncEnumerable<TagInfo> GetTagsInfoAsync(string searchText, TagType tagType, bool byName, int from = 0, int count = 0)
{
return AsyncEnumerable.Empty<TagInfo>();
}

View File

@ -128,9 +128,9 @@ internal class ProviderTagDao : ProviderDaoBase, ITagDao<string>
return _tagDao.GetTagsAsync(subject, tagType, fileEntries);
}
public IAsyncEnumerable<TagInfo> GetTagsInfoAsync(string searchText, TagType tagType, bool byName)
public IAsyncEnumerable<TagInfo> GetTagsInfoAsync(string searchText, TagType tagType, bool byName, int from = 0, int count = 0)
{
return _tagDao.GetTagsInfoAsync(searchText, tagType, byName);
return _tagDao.GetTagsInfoAsync(searchText, tagType, byName, from, count);
}
public IAsyncEnumerable<TagInfo> GetTagsInfoAsync(IEnumerable<int> ids)

View File

@ -154,9 +154,9 @@ public class CustomTagsService<T>
return folder;
}
public async IAsyncEnumerable<TagInfo> GetTagsInfoAsync(string searchText, TagType tagType)
public async IAsyncEnumerable<TagInfo> GetTagsInfoAsync(string searchText, TagType tagType, int from, int count)
{
await foreach (var tagInfo in TagDao.GetTagsInfoAsync(searchText, tagType, false))
await foreach (var tagInfo in TagDao.GetTagsInfoAsync(searchText, tagType, false, from, count))
{
yield return tagInfo;
}

View File

@ -250,9 +250,10 @@ public abstract class VirtualRoomsController<T> : ApiControllerBase
{
ErrorIfNotDocSpace();
var filterValue = _apiContext.FilterValue;
var from = Convert.ToInt32(_apiContext.StartIndex);
var count = Convert.ToInt32(_apiContext.Count);
await foreach (var tag in _customTagsService.GetTagsInfoAsync(filterValue, TagType.Custom))
await foreach (var tag in _customTagsService.GetTagsInfoAsync(_apiContext.FilterValue, TagType.Custom, from, count))
{
yield return tag;
}