public async override Task <Yngdieng.Frontend.V3.Protos.Word> GetWord(GetWordRequest request, ServerCallContext context) { if (string.IsNullOrEmpty(request.Name)) { throw new RpcException(new Status(StatusCode.InvalidArgument, "name must not be empty")); } var docId = ResourceNames.ToDocId(request.Name); if (_indexHolder.GetIndex().DocIdRedirections.ContainsKey(docId)) { var redirectionTarget = _indexHolder.GetIndex().DocIdRedirections[docId]; _logger.LogInformation($"DocId Redirection: {docId} -> {redirectionTarget}"); docId = redirectionTarget; } DocRef docRef; try { docRef = DocRefs.Decode(docId); } catch (Exception e) { throw new RpcException(new Status(StatusCode.InvalidArgument, $"{request.Name} is not a valid name.", e)); } var userPreference = UserPreferences.FromContext(context); var zhConverter = new ZhConverter(_openCc, userPreference.ZhConversionPreference); return(await Words.GetWord(_indexHolder, _dbContext, zhConverter, docRef)); }
public async override Task <Yngdieng.Admin.V1.Protos.Word> GetWord(GetWordRequest request, ServerCallContext context) { if (string.IsNullOrEmpty(request.Name)) { throw new RpcException(new Status(StatusCode.InvalidArgument, "name must not be empty")); } var wordRef = ResourceNames.ToWordRef(request.Name); return(Renderers.ToWord( await _dbContext.Words.Where(w => w.WordId == wordRef.WordId).SingleAsync(), await _dbContext.Prons.Where(p => p.WordId == wordRef.WordId) .Select(p => new PronRef { WordId = wordRef.WordId, PronId = p.PronId }) .ToListAsync() )); }