Esempio n. 1
0
        public async Task <Unit> Handle(ThingUpdatedEvent @event, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"---- Received {nameof(ThingUpdatedEvent)} message: Thing.Guid = [{@event.Guid}] ----");

            var thing = await _thingRepository.GetByGuid(@event.Guid);

            if (thing == null)
            {
                return(await HandleNotExistingThing(@event));
            }

            _thingMappingService.Map(@event, thing);
            await _unitOfWork.Commit();

            _logger.LogInformation($"---- Updated {nameof(ThingUpdatedEvent)} message: Thing.Guid = [{@event.Guid}] ----");

            return(await Task.FromResult(Unit.Value));
        }
Esempio n. 2
0
        public async Task <IEnumerable <ThingListDto> > GetThings()
        {
            _logger.LogInformation("{class}.{method} Invoked", nameof(ThingQueryService), nameof(GetThings));

            var userGuid = _httpContextUserService.GetUserGuid();
            var things   = await _thingRepository.GetWithCategoriesAndCurrenciesAndPlaces(userGuid);

            return(_thingMappingService.Map(things));
        }
Esempio n. 3
0
        public async Task <int> CreateThing(CreateThingDto createThingDto)
        {
            _logger.LogInformation("{class}.{method} with dto = [{@dto}] Invoked", nameof(ThingCommandService), nameof(CreateThing), createThingDto);

            var userGuid = _httpContextUserService.GetUserGuid();
            var user     = await _userRepository.GetByGuid(userGuid);

            var thing = _thingMappingService.Map(createThingDto, user.Id);

            _thingRepository.Add(thing);
            await _unitOfWork.Commit();

            _logger.LogInformation("{entityName} with id = [{id}] has been created in local database", nameof(Thing), thing.Id);

            var @event = _thingMappingService.MapToThingCreatedEvent(thing);

            _eventBusPublisher.Publish(@event);

            _logger.LogInformation("{entityName} with id = [{id}] has been successfully created", nameof(Thing), thing.Id);
            return(thing.Id);
        }
Esempio n. 4
0
        public async Task <Unit> Handle(ThingCreatedEvent @event, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"---- Received {nameof(ThingCreatedEvent)} message: Thing.Guid = [{@event.Guid}] ----");

            var thing = await _thingRepository.GetByGuid(@event.Guid);

            if (thing != null)
            {
                _logger.LogInformation($"---- Thing with Guid = [{@event.Guid}] already exists. Skipping event ----");
                return(await Task.FromResult(Unit.Value));
            }

            thing = _thingMappingService.Map(@event);
            _thingRepository.Add(thing);

            await _unitOfWork.Commit();

            _logger.LogInformation($"---- Saved {nameof(ThingCreatedEvent)} message: Thing.Guid = [{@event.Guid}] Thing.Id = [{thing.Id}]----");

            return(await Task.FromResult(Unit.Value));
        }