public async Task <List <ToDoListResource> > Handle(GetAllToDoListQuery request, CancellationToken cancellationToken) { string userId = _operatorUser.Id; var lists = await _toDoListRepository.GetListsAsync(new Guid(userId)); var result = lists.Select(x => new ToDoListResource { Id = x.Id, Title = x.Title, UserId = x.UserId, Date = x.CreateTime }).ToList(); return(result); }
public async Task GetLists() { var userID = Guid.NewGuid(); await _unitOfWork.SaveAsync(); var listModel = new ToDoList(); var id1 = Guid.NewGuid(); listModel.Id = id1; listModel.CreateTime = DateTime.Now; listModel.Title = "测试一下"; listModel.UserId = userID; _toDoListRepository.AddToDoList(listModel); await _unitOfWork.SaveAsync(); listModel = new ToDoList(); var id2 = Guid.NewGuid(); listModel.Id = id2; listModel.CreateTime = DateTime.Now; listModel.Title = "测试一下2"; listModel.UserId = userID; _toDoListRepository.AddToDoList(listModel); await _unitOfWork.SaveAsync(); listModel = new ToDoList(); var id3 = Guid.NewGuid(); listModel.Id = id3; listModel.CreateTime = DateTime.Now; listModel.Title = "测试一下3"; listModel.UserId = Guid.NewGuid(); _toDoListRepository.AddToDoList(listModel); await _unitOfWork.SaveAsync(); var result = await _toDoListRepository.GetListsAsync(userID); Assert.Contains(result, t => t.Id == id1); Assert.Contains(result, t => t.Id == id2); Assert.DoesNotContain(result, t => t.Id == Guid.NewGuid()); Assert.DoesNotContain(result, t => t.Id == id3); }
public async Task <IActionResult> Get() { string userId = _operatorUser.Id; if (string.IsNullOrEmpty(userId)) { return(NotFound()); } var lists = await _toDoListRepository.GetListsAsync(new Guid(userId)); var result = lists.Select(x => new ToDoListResource { Id = x.Id, Title = x.Title, UserId = x.UserId, Date = x.CreateTime }); return(Ok(result)); }