Ejemplo n.º 1
0
        public async Task <IActionResult> Handle(GetCoffeeQuery request, CancellationToken cancellationToken)
        {
            var coffee = await coffeeRepository.FindById(request.CoffeeId);

            this.logger.LogInformation($"Fetching coffee with id: {request.CoffeeId}");

            if (coffee == null)
            {
                this.logger.LogWarning($"Cannot find coffee with id: {request.CoffeeId}");
                return(NotFound());
            }

            return(Ok(coffee));
        }
        public async Task <IActionResult> Handle(DeleteCoffeeCommand command, CancellationToken cancellationToken)
        {
            logger.LogInformation($"Deleting coffee with id: {command.CoffeeId}");

            var coffee = await coffeeRepository.FindById(command.CoffeeId);

            if (coffee == null)
            {
                this.logger.LogWarning($"Cannot find coffee with id: {command.CoffeeId}");
                return(NotFound());
            }

            await coffeeRepository.Delete(coffee);

            logger.LogInformation($"Successfully deleted coffee with id: {command.CoffeeId}");

            return(Ok(coffee));
        }