private async Task HandleRemarkStatisticsAsync(T @event) { var remarkStatistics = await _remarkStatisticsRepository.GetAsync(@event.RemarkId); var remark = await _serviceClient.GetAsync <RemarkDto>(@event.Resource); if (remarkStatistics.HasNoValue) { remarkStatistics = new RemarkStatistics(@event.RemarkId, remark.Value.Category.Name, @event.UserId, remark.Value.Author.Name, remark.Value.CreatedAt, remark.Value.State.State, remark.Value.Location.Latitude, remark.Value.Location.Longitude, remark.Value.Location.Address, remark.Value.Description, remark.Value.Tags); } else { Location location = null; if (remark.Value.State.Location != null) { location = new Location(remark.Value.State.Location.Latitude, remark.Value.Location.Longitude, remark.Value.Location.Address); } remarkStatistics.Value.AddState(new RemarkState(remark.Value.State.State, @event.UserId, location: location)); } await _remarkStatisticsRepository.AddOrUpdateAsync(remarkStatistics.Value); }
public StatisticsModule(IRemarkStatisticsRepository remarkStatisticsRepository, IUserStatisticsRepository userStatisticsRepository, ICategoryStatisticsRepository categoryStatisticsRepository, ITagStatisticsRepository tagStatisticsRepository, IMapper mapper) : base(mapper, "statistics") { Get("remarks", async args => await FetchCollection <BrowseRemarkStatistics, RemarkStatistics> (async x => await remarkStatisticsRepository.BrowseAsync(x)) .MapTo <RemarkStatistics>() .HandleAsync()); Get("remarks/{id}", async args => await Fetch <GetRemarkStatistics, RemarkStatistics> (async x => await remarkStatisticsRepository.GetAsync(x.Id)) .MapTo <RemarkStatistics>() .HandleAsync()); Get("remarks/general", async args => await Fetch <GetRemarkGeneralStatistics, RemarksCountStatistics> (async x => await remarkStatisticsRepository.GetGeneralStatisticsAsync(x)) .MapTo <RemarksCountStatisticsDto>() .HandleAsync()); Get("categories", async args => await FetchCollection <BrowseCategoryStatistics, CategoryStatistics> (async x => await categoryStatisticsRepository.BrowseAsync(x)) .MapTo <CategoryStatisticsDto>() .HandleAsync()); Get("tags", async args => await FetchCollection <BrowseTagStatistics, TagStatistics> (async x => await tagStatisticsRepository.BrowseAsync(x)) .MapTo <TagStatisticsDto>() .HandleAsync()); Get("users", async args => await FetchCollection <BrowseUserStatistics, UserStatistics> (async x => await userStatisticsRepository.BrowseAsync(x)) .MapTo <UserStatisticsDto>() .HandleAsync()); Get("users/{id}", async args => await Fetch <GetUserStatistics, UserStatistics> (async x => await userStatisticsRepository.GetByIdAsync(x.Id)) .MapTo <UserStatisticsDto>() .HandleAsync()); }