Example #1
0
        public async override Task <ListWordListWordsResponse> ListWordListWords(ListWordListWordsRequest request,
                                                                                 ServerCallContext context)
        {
            if (string.IsNullOrEmpty(request.Parent))
            {
                throw new RpcException(new Status(StatusCode.InvalidArgument, "parent must not be empty"));
            }
            var wordListId = ResourceNames.ToWordListId(request.Parent);

            var pageSize = Math.Min(MaxPageSize, request.PageSize > 0 ? request.PageSize : DefaultPageSize);
            var offset   = ParsePageToken(request.PageToken);
            var wordIds  = await _dbContext.WordListWords
                           .Where(w => w.WordListId == wordListId)
                           .OrderBy(w => w.Ordering)
                           .Select(w => w.WordId)
                           .Skip(offset)
                           .Take(pageSize)
                           .ToListAsync();

            var words          = new List <Yngdieng.Frontend.V3.Protos.Word>();
            var userPreference = UserPreferences.FromContext(context);
            var zhConverter    = new ZhConverter(_openCc, userPreference.ZhConversionPreference);

            foreach (var wordId in wordIds)
            {
                words.Add(await Words.GetWord(_indexHolder, _dbContext, zhConverter, ResourceNames.ToDocRef(wordId), Words.Mode.Snippet));
            }
            return(new ListWordListWordsResponse
            {
                Words = { words },
                NextPageToken = (offset + words.Count).ToString()
            });
        }
Example #2
0
        public async override Task <Yngdieng.Frontend.V3.Protos.WordList> GetWordList(GetWordListRequest request,
                                                                                      ServerCallContext context)
        {
            if (string.IsNullOrEmpty(request.Name))
            {
                throw new RpcException(new Status(StatusCode.InvalidArgument, "name must not be empty"));
            }
            var wordListId = ResourceNames.ToWordListId(request.Name);

            return(Renderers.ToWordList(await _dbContext.WordLists.Where(w => w.WordListId == wordListId).SingleAsync()));
        }