-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.mjs
executable file
·27 lines (22 loc) · 1.04 KB
/
main.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import BookService from './services/books.services.mjs';
import { fetchBooks } from './services/googleAPIBooks.services.mjs';
import { generateColumnLayoutElement, generateBookCardTemplate } from './templates/bookCard.template.mjs';
async function myApp() {
// Fetch and map books...
const rawBooks = await fetchBooks();
const booksService = new BookService(rawBooks);
const books = booksService.sortBooksByPublishedDate().get();
// Books...
console.log({ books: books.toString() });
// AVG rating by category = 'Computers'
console.log('Average rating of the “Computers” books =', booksService.getAVGRatingByCategory('Computers'));
// Attach to DOM...
const targetElement = document.getElementById('books-container');
const bookCardTemplates = books.map((book) => generateBookCardTemplate(book));
bookCardTemplates.forEach((bookCardTemplate) => {
const element = generateColumnLayoutElement();
element.appendChild(bookCardTemplate);
targetElement.appendChild(element);
});
};
myApp();