コード例 #1
0
        public StatusListParams Map(StatusListParamsModel from, StatusListParams to)
        {
            to.SavedByUserId   = from.SavedByUserId;
            to.CreatedByUserId = from.CreatedByUserId;
            to.MaxId           = from.MaxId;
            to.Count           = from.Count;

            return(to);
        }
コード例 #2
0
        public void MapFromModelToDto()
        {
            // Arrange
            var model = new StatusListParamsModel
            {
                SavedByUserId   = "1",
                CreatedByUserId = "2",
                MaxId           = "3",
                Count           = 4
            };

            // Act
            var dto = this.mapper.Map(model, new StatusListParams());

            // Assert
            Assert.Equal(model.SavedByUserId, dto.SavedByUserId);
            Assert.Equal(model.CreatedByUserId, dto.CreatedByUserId);
            Assert.Equal(model.MaxId, dto.MaxId);
            Assert.Equal(model.Count, dto.Count);
        }
コード例 #3
0
        public async Task <IEnumerable <StatusModel> > GetAllSavedAsync(StatusListParamsModel statusListParams)
        {
            if (statusListParams == null)
            {
                throw new ArgumentNullException("statusListParams");
            }

            var mapper        = new StatusMapper();
            var paramsMapper  = new StatusListParamsMapper();
            var paramsModel   = paramsMapper.Map(statusListParams, new StatusListParams());
            var savedStatuses = await this.statusStoreRepository.GetAllSavedAsync(paramsModel);

            var statusModels = savedStatuses.Select(x => mapper.Map(x, new StatusModel())).ToList();

            statusModels.ForEach(x =>
            {
                x.IsSaved   = true;
                x.CreatedAt = x.CreatedAt.ToLocalTime();
            });

            return(statusModels);
        }
コード例 #4
0
        public async Task <IHttpActionResult> Get([FromUri] TimelineRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (string.IsNullOrEmpty(request.UserId))
            {
                throw new ArgumentException(
                          "TimelineRequest.UserId is required.");
            }

            var userTask = request.TrimUser
                ? Task.FromResult((UserModel)null)
                : this.userService.GetAsync(request.UserId);

            var statusListParams = new StatusListParamsModel
            {
                SavedByUserId   = this.claimsHelper.GetUserId(),
                CreatedByUserId = request.UserId,
                MaxId           = request.MaxId,
                Count           = request.Count
            };

            var statusesTask = request.SavedOnly
                ? this.statusService.GetAllSavedAsync(statusListParams)
                : this.statusService.GetUserTimelineAsync(statusListParams);

            await Task.WhenAll(userTask, statusesTask);

            var response = new TimelineResponse
            {
                User     = userTask.Result,
                Statuses = statusesTask.Result
            };

            return(Ok(response));
        }
コード例 #5
0
        public async Task <IEnumerable <StatusModel> > GetUserTimelineAsync(StatusListParamsModel statusListParams)
        {
            if (statusListParams == null)
            {
                throw new ArgumentNullException("statusListParams");
            }

            var mapper       = new StatusMapper();
            var paramsMapper = new StatusListParamsMapper();
            var paramsModel  = paramsMapper.Map(statusListParams, new StatusListParams());
            var statuses     = await this.statusRepository.GetUserTimelineAsync(paramsModel);

            var statusModels = statuses
                               .Select(x => mapper.Map(x, new StatusModel()))
                               .ToList();

            var savedStatusIds = await this.statusStoreRepository.GetSavedStatusIdsAsync();

            var savedStatusIdsList = savedStatusIds.ToList();

            statusModels.ForEach(x => x.IsSaved = savedStatusIdsList.Contains(x.Id));

            return(statusModels);
        }