public async Task <GetBookshelfApiModel> Handle(GetBookshelfQuery request, CancellationToken cancellationToken) { GoogleData.Bookshelf googleBookshelf = await _booksService.Mylibrary.Bookshelves.Get(request.BookshelfId.ToString()).ExecuteAsync(); if (googleBookshelf == null) { return(ApiModel.NotFound <GetBookshelfApiModel>()); } Bookshelf bookshelf = _mapper.Map <Bookshelf>(googleBookshelf); return(new GetBookshelfApiModel(bookshelf)); }
public async Task <GetBookshelfsApiListModel> Handle(GetBookshelfsListQuery request, CancellationToken cancellationToken) { GoogleData.Bookshelves googleBookshelves = await _booksService.Mylibrary.Bookshelves.List().ExecuteAsync(); googleBookshelves.Items = googleBookshelves.Items.Where(x => x.Id.HasValue).ToList(); if (googleBookshelves == null) { return(ApiModel.NotFound <GetBookshelfsApiListModel>()); } switch (request.BookshelfOptions) { case BookshelfsOption.Base: googleBookshelves.Items = googleBookshelves.Items.Where(x => x.Id < 5).ToList(); break; case BookshelfsOption.Custom: googleBookshelves.Items = googleBookshelves.Items.Where(x => x.Id > 9).ToList(); break; case BookshelfsOption.BaseAndCustom: googleBookshelves.Items = googleBookshelves.Items.Where(x => x.Id < 5 || x.Id > 9).ToList(); break; case BookshelfsOption.Others: googleBookshelves.Items = googleBookshelves.Items.Where(x => x.Id >= 5 || x.Id <= 9).ToList(); break; case BookshelfsOption.Favorites: var favoriteBookshelves = await _context.FavoriteBookshelves .Where(x => x.UserId == request.UserId) .Select(x => x.BookshelfId) .ToListAsync(); googleBookshelves.Items = googleBookshelves.Items .Where(x => favoriteBookshelves.Contains(x.Id.ToString())).ToList(); break; case BookshelfsOption.All: default: break; } IEnumerable <Bookshelf> bookshelfs = _mapper .Map <IEnumerable <GoogleData.Bookshelf>, IEnumerable <Bookshelf> >(googleBookshelves.Items); return(new GetBookshelfsApiListModel(bookshelfs)); }