예제 #1
0
 private void MockBookRetrieval()
 {
     _booksDbSet.SetDbSetData(new List <Book>().AsQueryable());
     _bookInfoService.FindBookByIsbnAsync("123").Returns(Task.FromResult(new ExternalBookInfo {
         Author = "test", Url = "test", Title = "asd"
     }));
 }
예제 #2
0
        private async Task <RetrievedBookInfoDto> GetInfoFromExternalApiAsync(string code)
        {
            var bookInfo = await _bookInfoService.FindBookByIsbnAsync(code);

            _serviceValidator.ThrowIfBookDoesNotExistGoogleApi(bookInfo != null);
            return(MapGoogleApiBookToDto(bookInfo));
        }
예제 #3
0
        public async Task <RetrievedBookInfoDto> FindBookByIsbnAsync(string isbn, int organizationId)
        {
            var bookAlreadyExists = _booksDbSet
                                    .Any(book =>
                                         book.OrganizationId == organizationId &&
                                         book.Code == isbn);

            _bookServiceValidator.CheckIfBookAlreadyExists(bookAlreadyExists);

            var result = await _bookInfoService.FindBookByIsbnAsync(isbn);

            _bookServiceValidator.CheckIfBookWasFoundByIsbnFromExternalProvider(result);
            var retrievedBookDto = MapBookInfoToDto(result);

            return(retrievedBookDto);
        }
예제 #4
0
        public async Task UpdateBookCoversAsync()
        {
            var booksWithoutCover = _booksDbSet.Where(book => book.BookCoverUrl == null);

            foreach (var book in booksWithoutCover)
            {
                try
                {
                    var bookInfo = await _bookService.FindBookByIsbnAsync(book.Code);

                    if (bookInfo?.CoverImageUrl == null)
                    {
                        continue;
                    }

                    book.BookCoverUrl = bookInfo.CoverImageUrl;
                    await _uow.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    _logger.Error(ex);
                }
            }
        }