public async Task <PaginatedResult <NoteModel> > GetNotesAsync(NoteQueryModel model, Guid ownerId) { var notes = await _noteRepository.GetAsync( ownerId, model.Page, model.Size, model.IsAscSort, model.SortProperty, model.Title, model.Text, model.Tags ); var count = await _noteRepository.CountAsync( ownerId, model.Title, model.Text, model.Tags); return(new PaginatedResult <NoteModel> { Items = notes.Select(note => _mapper.Map <Note, NoteModel>(note)), TotalCount = count, Size = model.Size, Page = model.Page }); }
public async Task <IActionResult> GetAll([FromQuery] NoteQueryModel query) { var callerId = GetIdFromClaims(); var notes = await _noteService.GetNotes(callerId, query); return(Ok(_mapper.Map <List <NoteViewModel> >(notes))); }
public async Task <List <Note> > GetNotes(string owner, NoteQueryModel query) { var notesCollection = _mongoDatabase.GetCollection <Note>("notes"); var filterBuilder = Builders <Note> .Filter; var filter = filterBuilder.Eq("Owner", owner); if (query.Date.Year != 0001) { filter = filter & filterBuilder.Gte(x => x.Created, query.Date) & filterBuilder.Lt(x => x.Created, query.Date.AddDays(1)); } if (!string.IsNullOrWhiteSpace(query.Tag)) { filter = filter & filterBuilder.AnyEq(x => x.Tags, query.Tag); } return(await notesCollection.Find(filter) .Limit(query.Limit) .Skip(query.Skip) .Sort("{Created: -1}") .ToListAsync()); }