public async Task TestHandle_ShouldReturnCorrectly() { // Arrange var tags = new List <Tag> { new Tag(Guid.NewGuid().ToString()), new Tag(Guid.NewGuid().ToString()), new Tag(Guid.NewGuid().ToString()) }; Context.Tags.AddRange(tags); await Context.SaveChangesAsync(); var expected = new TagListDto { Tags = tags.Select(t => t.Value) }; var query = new TagListQuery(); var sut = new TagListQuery.Handler(Context, Mapper); // Act var result = await sut.Handle(query, CancellationToken.None); // Assert result.Should().BeEquivalentTo(expected); }
public PagedResultDto <TagListDto> GetSubscribeTags(UserSubscribeSearchDto userSubscribeDto) { var userTags = _userTagRepository.Select.Include(r => r.Tag) .Where(r => r.CreateUserId == userSubscribeDto.UserId) .OrderByDescending(r => r.CreateTime) .ToPagerList(userSubscribeDto, out long count) .Select(r => { TagListDto tagDto = _mapper.Map <TagListDto>(r.Tag); if (tagDto != null) { tagDto.ThumbnailDisplay = _fileRepository.GetFileUrl(tagDto.Thumbnail); tagDto.IsSubscribe = true; } else { return(new TagListDto() { Id = r.TagId, TagName = "该标签已被拉黑", IsSubscribe = true }); } return(tagDto); }).ToList(); return(new PagedResultDto <TagListDto>(userTags, count)); }
public ActionResult GetTags() { var tags = _repo.GetTags(); TagListDto tagList = new TagListDto(); tagList.TagList = tags; return(Ok(tagList)); }
public async Task <TagListDto> GetAsync(Guid id) { Tag tag = await _tagRepository.Select.Where(a => a.Id == id).ToOneAsync(); if (tag == null) { throw new LinCmsException("不存在此标签"); } TagListDto tagDto = _mapper.Map <TagListDto>(tag); tagDto.IsSubscribe = this.IsSubscribe(id); tagDto.ThumbnailDisplay = _currentUser.GetFileUrl(tagDto.Thumbnail); return(tagDto); }
public PagedResultDto <TagListDto> GetSubscribeTags(UserSubscribeSearchDto userSubscribeDto) { var userTags = _userTagRepository.Select.Include(r => r.Tag) .Where(r => r.CreateUserId == userSubscribeDto.UserId) .OrderByDescending(r => r.CreateTime) .ToPagerList(userSubscribeDto, out long count) .Select(r => { TagListDto tagDto = _mapper.Map <TagListDto>(r.Tag); tagDto.ThumbnailDisplay = _currentUser.GetFileUrl(tagDto.Thumbnail); tagDto.IsSubscribe = true; return(tagDto); }).ToList(); return(new PagedResultDto <TagListDto>(userTags, count)); }
/// <summary> /// 根据状态得到标签列表 /// </summary> /// <param name="searchDto"></param> /// <returns></returns> public PagedResultDto <TagListDto> Get(TagSearchDto searchDto) { if (searchDto.Sort.IsNullOrEmpty()) { searchDto.Sort = "create_time desc"; } List <TagListDto> tags = _tagRepository.Select.IncludeMany(r => r.UserTags, r => r.Where(u => u.CreateUserId == _currentUser.Id)) .WhereIf(searchDto.TagIds.IsNotNullOrEmpty(), r => searchDto.TagIds.Contains(r.Id)) .WhereIf(searchDto.TagName.IsNotNullOrEmpty(), r => r.TagName.Contains(searchDto.TagName)) .WhereIf(searchDto.Status != null, r => r.Status == searchDto.Status) .OrderBy(searchDto.Sort) .ToPagerList(searchDto, out long totalCount) .Select(r => { TagListDto tagDto = _mapper.Map <TagListDto>(r); tagDto.ThumbnailDisplay = _currentUser.GetFileUrl(tagDto.Thumbnail); tagDto.IsSubscribe = r.UserTags.Any(); return(tagDto); }).ToList(); return(new PagedResultDto <TagListDto>(tags, totalCount)); }