public override Task <GetLibrarySongsResponse> GetLibrarySongs(GetLibrarySongsRequest request, ServerCallContext context)
        {
            var filter = new LibraryPageFilter()
            {
                UserId    = Guid.Parse(request.UserId),
                Genre     = (GenreEnum)request.Genre,
                Decade    = (DecadeEnum)request.Decade,
                PageIndex = request.PageIndex,
                PageSize  = request.PageSize
            };

            if (request.PopularityRankingId != null && request.PopularityRankingId != "")
            {
                filter.PopularityRankingId = Guid.Parse(request.PopularityRankingId);
            }

            var(totalNumber, songs) = _libraryService.GetLibrarySongs(filter);
            var response = new GetLibrarySongsResponse()
            {
                TotalNumber = totalNumber
            };

            response.Songs.AddRange(songs.Select(s => SongGrpcConverter.ToMessage(s)).ToList());
            return(Task.FromResult(response));
        }
예제 #2
0
        public async Task <LibraryPageModel> GetLibrarySongsAsync(LibraryPageFilter filter)
        {
            var channel = new Channel(channelTarget, ChannelCredentials.Insecure);

            try
            {
                var client  = new LibraryGrpcService.LibraryGrpcServiceClient(channel);
                var request = new GetLibrarySongsRequest()
                {
                    UserId    = filter.UserId.ToString(),
                    PageIndex = filter.PageIndex,
                    PageSize  = filter.PageSize
                };

                if (filter.Genre != null)
                {
                    request.Genre = (int)filter.Genre;
                }

                if (filter.Decade != null)
                {
                    request.Decade = (int)filter.Decade;
                }

                if (filter.PopularityRankingId != null)
                {
                    request.PopularityRankingId = filter.PopularityRankingId.ToString();
                }


                var response = await client.GetLibrarySongsAsync(request);

                return(new LibraryPageModel()
                {
                    TotalNumber = response.TotalNumber,
                    Songs = response.Songs.Select(s => SongGrpcConverter.ToMessage(s)).ToList()
                });
            }
            finally
            {
                await channel.ShutdownAsync();
            }
        }