Esempio n. 1
0
        public async Task <IActionResult> Get([FromQuery] string searchQuery, [FromQuery] int pageSize, [FromQuery] int pageNumber, [FromQuery] int skippedResults)
        {
            var query  = new GetRecipesQuery(searchQuery, pageSize, pageNumber, skippedResults);
            var result = await Mediator.Send(query);

            return(Ok(result));
        }
Esempio n. 2
0
        public async Task <IEnumerable <RecipeModel> > Handle(GetRecipesQuery request, CancellationToken cancellationToken)
        {
            var recipes = await _context.RecipeVariations
                          .Include(rv => rv.Author)
                          .Include(rv => rv.Ingredients)
                          .Include(rv => rv.Recipe)
                          .OrderByDescending(rv => rv.CreatedAt)
                          .Take(100)
                          .ToArrayAsync(cancellationToken: cancellationToken)
                          .ConfigureAwait(false);

            return(_mapper.Map <IEnumerable <RecipeModel> >(recipes));
        }
Esempio n. 3
0
        public async Task CreateRecipe_NewRecipe_SuccessfullRead()
        {
            IServiceCollection services = new ServiceCollection();

            services.AddKitchenDomain()
            .AddKitchenApplication()
            .AddKitchenInfrastructure("Server=.;Database=RestaurantManagementSystem;Trusted_Connection=True;MultipleActiveResultSets=true", "S0M3 M4G1C UN1C0RNS G3N3R4T3D TH1S S3CR3T");
            var serviceProviderFactory = new DefaultServiceProviderFactory();

            IServiceProvider serviceProvider = serviceProviderFactory.CreateServiceProvider(services);

            IMediator Mediator = serviceProvider.GetService <IMediator>();

            var createRecipeCommand = new CreateRecipeCommand();

            createRecipeCommand.Name        = "Mandja";
            createRecipeCommand.Description = "Vkusno";
            createRecipeCommand.Preparation = "Gotvish";

            createRecipeCommand.Ingredients.Add(new Ingredient("Qdene", 500));

            CreateRecipeOutputModel createRecipeOutput;

            createRecipeOutput = await Mediator.Send(createRecipeCommand);

            var recipiesQuery = new GetRecipesQuery();

            recipiesQuery.OnlyActive = true;

            var recipesResult = await Mediator.Send(recipiesQuery);

            var recipe = recipesResult.Recipes.FirstOrDefault(recipe => recipe.Id == createRecipeOutput.RecipeId);

            Assert.AreEqual(createRecipeCommand.Name, recipe.Name);
            Assert.AreEqual(createRecipeCommand.Description, recipe.Description);
            Assert.AreEqual(createRecipeCommand.Preparation, recipe.Preparation);
        }
Esempio n. 4
0
        public async Task <IEnumerable <GetRecipesQueryResult> > Handle(GetRecipesQuery request, CancellationToken cancellationToken)
        {
            var recipes = await _recipeRepository.GetRecipesAsync(request.Page, request.ItemsPerPage);

            return(recipes.MapToGetRecipesQueryResult());
        }
 public async Task <ActionResult <GetRecipesOutputModel> > GetRecipiesQuery([FromQuery] GetRecipesQuery getRecipesQuery)
 {
     return(await Send(getRecipesQuery));
 }
Esempio n. 6
0
 public Task <IEnumerable <GetRecipesQueryResult> > Get([FromQuery] GetRecipesQuery query, CancellationToken cancellationToken) =>
 _mediator.Send(query, cancellationToken);