コード例 #1
0
        public PartialFindResult <FavoriteSongForUserContract> GetFavoriteSongs(RatedSongQueryParams queryParams)
        {
            ParamIs.NotNull(() => queryParams);

            return(HandleQuery(session => {
                // Apply initial filter
                var q = session.Query <FavoriteSongForUser>()
                        .Where(a => !a.Song.Deleted && a.User.Id == queryParams.UserId);

                if (queryParams.FilterByRating != SongVoteRating.Nothing)
                {
                    q = q.Where(s => s.Rating == queryParams.FilterByRating);
                }

                // Group by rating if needed
                if (queryParams.GroupByRating)
                {
                    q = q.OrderByDescending(r => r.Rating);
                }

                // Add custom order
                q = q.AddSongOrder(queryParams.SortRule, LanguagePreference);

                // Apply paging
                var resultQ = q.Skip(queryParams.Paging.Start).Take(queryParams.Paging.MaxEntries);

                var contracts = resultQ.ToArray().Select(a => new FavoriteSongForUserContract(a, PermissionContext.LanguagePreference)).ToArray();
                var totalCount = (queryParams.Paging.GetTotalCount ? q.Count() : 0);

                return new PartialFindResult <FavoriteSongForUserContract>(contracts, totalCount);
            }));
        }
コード例 #2
0
        public PartialFindResult <RatedSongForUserForApiContract> GetRatedSongs(
            int userId,
            string query                   = "",
            string tag                     = null,
            int?artistId                   = null,
            bool childVoicebanks           = false,
            SongVoteRating?rating          = null,
            int?songListId                 = null,
            bool groupByRating             = true,
            int start                      = 0, int maxResults = defaultMax, bool getTotalCount = false,
            SongSortRule?sort              = null,
            NameMatchMode nameMatchMode    = NameMatchMode.Auto,
            SongOptionalFields fields      = SongOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            maxResults = Math.Min(maxResults, absoluteMax);
            query      = FindHelpers.GetMatchModeAndQueryForSearch(query, ref nameMatchMode);

            var queryParams = new RatedSongQueryParams(userId, new PagingProperties(start, maxResults, getTotalCount))
            {
                Query           = query,
                NameMatchMode   = nameMatchMode,
                SortRule        = sort ?? SongSortRule.Name,
                ArtistId        = artistId ?? 0,
                ChildVoicebanks = childVoicebanks,
                FilterByRating  = rating ?? SongVoteRating.Nothing,
                GroupByRating   = groupByRating,
                SonglistId      = songListId ?? 0,
                Tag             = tag
            };

            var songs = queries.GetRatedSongs(queryParams, ratedSong => new RatedSongForUserForApiContract(ratedSong, lang, fields));

            return(songs);
        }
コード例 #3
0
ファイル: UserController.cs プロジェクト: sethura/vocadb
        public ActionResult FavoriteSongsPaged(int id, int?page, SongVoteRating?rating = null, SongSortRule sort = SongSortRule.Name, bool groupByRating = true)
        {
            const int songsPerPage = 50;

            var pageIndex   = (page - 1) ?? 0;
            var r           = rating ?? SongVoteRating.Nothing;
            var queryParams = new RatedSongQueryParams(id, PagingProperties.CreateFromPage(pageIndex, songsPerPage, true))
            {
                FilterByRating = r, SortRule = sort, GroupByRating = groupByRating
            };
            var result = Service.GetFavoriteSongs(queryParams);
            var data   = new PagingData <FavoriteSongForUserContract>(result.Items.ToPagedList(pageIndex, songsPerPage, result.TotalCount), id, "FavoriteSongs", "ui-tabs-3");

            data.RouteValues = new RouteValueDictionary(new { action = "FavoriteSongs", id, rating, sort, groupByRating });

            return(PartialView("FavoriteSongsPaged", data));
        }
コード例 #4
0
ファイル: UserApiController.cs プロジェクト: kateabr/vocadb
        public PartialFindResult <RatedSongForUserForApiContract> GetRatedSongs(
            int id,
            string query                    = "",
            string tagName                  = null,
            [FromUri] int[] tagId           = null,
            [FromUri] int[] artistId        = null,
            bool childVoicebanks            = false,
            LogicalGrouping artistGrouping  = LogicalGrouping.And,
            SongVoteRating?rating           = null,
            int?songListId                  = null,
            bool groupByRating              = true,
            [FromUri] PVServices?pvServices = null,
            [FromUri] AdvancedSearchFilter[] advancedFilters = null,
            int start = 0, int maxResults = defaultMax, bool getTotalCount = false,
            RatedSongForUserSortRule?sort  = null,
            NameMatchMode nameMatchMode    = NameMatchMode.Auto,
            SongOptionalFields fields      = SongOptionalFields.None,
            ContentLanguagePreference lang = ContentLanguagePreference.Default)
        {
            maxResults = Math.Min(maxResults, absoluteMax);
            var textQuery = SearchTextQuery.Create(query, nameMatchMode);

            var queryParams = new RatedSongQueryParams(id, new PagingProperties(start, maxResults, getTotalCount))
            {
                TextQuery       = textQuery,
                SortRule        = sort ?? RatedSongForUserSortRule.Name,
                ArtistIds       = artistId,
                ArtistGrouping  = artistGrouping,
                ChildVoicebanks = childVoicebanks,
                FilterByRating  = rating ?? SongVoteRating.Nothing,
                GroupByRating   = groupByRating,
                PVServices      = pvServices,
                SonglistId      = songListId ?? 0,
                TagIds          = tagId,
                TagName         = tagName,
                AdvancedFilters = advancedFilters
            };

            var songs = queries.GetRatedSongs(queryParams, ratedSong => new RatedSongForUserForApiContract(ratedSong, lang, fields));

            return(songs);
        }
コード例 #5
0
ファイル: UserQueries.cs プロジェクト: sethura/vocadb
        public PartialFindResult <T> GetRatedSongs <T>(RatedSongQueryParams queryParams, Func <FavoriteSongForUser, T> fac)
        {
            ParamIs.NotNull(() => queryParams);

            return(HandleQuery(session => {
                // Apply initial filter
                var q = session.OfType <FavoriteSongForUser>().Query()
                        .Where(a => !a.Song.Deleted && a.User.Id == queryParams.UserId)
                        .WhereChildHasName(queryParams.Query, queryParams.NameMatchMode)
                        .WhereSongHasArtist(queryParams.ArtistId, queryParams.ChildVoicebanks)
                        .WhereHasRating(queryParams.FilterByRating)
                        .WhereSongIsInList(queryParams.SonglistId)
                        .WhereSongHasTag(queryParams.Tag);

                var queryWithSort = q;

                // Group by rating if needed
                if (queryParams.GroupByRating && queryParams.FilterByRating == SongVoteRating.Nothing)
                {
                    queryWithSort = queryWithSort.OrderByDescending(r => r.Rating);
                }

                // Add custom order
                queryWithSort = queryWithSort.AddSongOrder(queryParams.SortRule, PermissionContext.LanguagePreference);

                // Apply paging
                var resultQ = queryWithSort
                              .Skip(queryParams.Paging.Start)
                              .Take(queryParams.Paging.MaxEntries);

                var contracts = resultQ.ToArray().Select(fac).ToArray();
                var totalCount = (queryParams.Paging.GetTotalCount ? q.Count() : 0);

                return new PartialFindResult <T>(contracts, totalCount);
            }));
        }
コード例 #6
0
ファイル: UserQueries.cs プロジェクト: sethura/vocadb
 public PartialFindResult <FavoriteSongForUserContract> GetRatedSongs(RatedSongQueryParams queryParams)
 {
     return(GetRatedSongs(queryParams, ratedSong => new FavoriteSongForUserContract(ratedSong, PermissionContext.LanguagePreference)));
 }