Exemplo n.º 1
0
        public async Task <IActionResult> RunQuery([FromBody] RunQueryRequest request)
        {
            try
            {
                CheckRunQueryRequestValidity(request);

                var user = await userManager.GetUserAsync(HttpContext.User);

                var userId   = user == null ? Guid.Empty : user.Id;
                var userName = user == null ? null : user.UserName;

                var excludedTags = (request.ExcludedTags.Count() == 1 && request.ExcludedTags.First() == allTagsFakeGuid) ? null : request.ExcludedTags;

                var applicationRequest = new SearchCards.Request(request.Deck, request.DeckIsInclusive, request.Heap, request.PageNo, request.PageSize, request.RequiredText, request.RequiredTags, excludedTags, request.Visibility, request.RatingFilteringMode, request.RatingFilteringValue, request.NotificationFiltering);

                var applicationResult = new SearchCards(dbContext).Run(applicationRequest, userId);

                var result = new RunQueryViewModel(applicationResult, userName, localizer, decksControllerLocalizer);

                return(base.Ok(result));
            }
            catch (SearchResultTooBigForRatingException)
            {
                return(ControllerError.BadRequest(localizer["SearchTooBigForRatingFiltering"].Value, this));
            }
            catch (Exception e)
            {
                return(ControllerError.BadRequest(e, this));
            }
        }
Exemplo n.º 2
0
        public async Task TestDBWithOnePublicCard_FindAll()
        {
            var testDB = DbHelper.GetEmptyTestDB();

            var userId = await UserHelper.CreateInDbAsync(testDB);

            var tag1Name = RandomHelper.String();
            var tag1     = await TagHelper.CreateAsync(testDB, tag1Name);

            var tag2Name = RandomHelper.String();
            var tag2     = await TagHelper.CreateAsync(testDB, tag2Name);

            var card = await CardHelper.CreateAsync(testDB, userId, tagIds : new[] { tag1, tag2 });

            using var dbContext = new MemCheckDbContext(testDB);
            var requestWithUser = new SearchCards.Request {
                UserId = userId
            };
            var resultWithUser = await new SearchCards(dbContext.AsCallContext()).RunAsync(requestWithUser);

            Assert.AreEqual(1, resultWithUser.TotalNbCards);
            Assert.AreEqual(1, resultWithUser.PageCount);
            Assert.AreEqual(card.Id, resultWithUser.Cards.First().CardId);

            var requestWithoutUser = new SearchCards.Request();
            var resultWithoutUser  = await new SearchCards(dbContext.AsCallContext()).RunAsync(requestWithoutUser);

            Assert.AreEqual(1, resultWithoutUser.TotalNbCards);
            Assert.AreEqual(1, resultWithoutUser.PageCount);
            var foundCard = resultWithoutUser.Cards.First();

            Assert.AreEqual(card.Id, foundCard.CardId);
            Assert.AreEqual(card.TagsInCards.Count(), foundCard.Tags.Count());
            Assert.IsTrue(foundCard.Tags.Any(t => t == tag1Name));
            Assert.IsTrue(foundCard.Tags.Any(t => t == tag2Name));
            Assert.AreEqual(0, foundCard.CountOfUserRatings);
            Assert.AreEqual(0, foundCard.AverageRating);
            Assert.AreEqual(0, foundCard.CurrentUserRating);
            Assert.IsTrue(!foundCard.DeckInfo.Any());
            Assert.AreEqual(card.FrontSide, foundCard.FrontSide);
            Assert.AreEqual(userId, foundCard.VersionCreator.Id);
            Assert.AreEqual(card.VersionDescription, foundCard.VersionDescription);
            Assert.AreEqual(card.VersionUtcDate, foundCard.VersionUtcDate);
            Assert.IsTrue(!foundCard.VisibleTo.Any());
        }
Exemplo n.º 3
0
        private static SearchCards.Request GetRequest(SearchSubscription subscription)
        {
            var request = new SearchCards.Request
            {
                UserId       = subscription.UserId,
                RequiredText = subscription.RequiredText,
                RequiredTags = subscription.RequiredTags.Select(t => t.TagId),
                PageSize     = SearchCards.Request.MaxPageSize,
                PageNo       = 0
            };

            if (subscription.ExcludeAllTags)
            {
                request = request with {
                    ExcludedTags = null
                }
            }
            ;