From fe9f04126dc17fa2edae387d198e7bb734700f7d Mon Sep 17 00:00:00 2001 From: ltctceplrm <14954927+ltctceplrm@users.noreply.github.com> Date: Tue, 19 Dec 2023 19:52:52 +0100 Subject: [PATCH 1/4] Added isbn field to books --- src/api/apis/OpenLibraryAPI.ts | 1 + src/models/BookModel.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/api/apis/OpenLibraryAPI.ts b/src/api/apis/OpenLibraryAPI.ts index 8ad4b13..72c165a 100644 --- a/src/api/apis/OpenLibraryAPI.ts +++ b/src/api/apis/OpenLibraryAPI.ts @@ -69,6 +69,7 @@ export class OpenLibraryAPI extends APIModel { dataSource: this.apiName, url: `https://openlibrary.org` + result.key, id: result.key, + isbn: result.isbn[0] ?? 'unknown', englishTitle: result.title_english ?? result.title, author: result.author_name ?? 'unknown', diff --git a/src/models/BookModel.ts b/src/models/BookModel.ts index 0c603c6..60860d5 100644 --- a/src/models/BookModel.ts +++ b/src/models/BookModel.ts @@ -9,6 +9,7 @@ export class BookModel extends MediaTypeModel { image: string; onlineRating: number; english_title: string; + isbn: number; released: boolean; @@ -25,6 +26,7 @@ export class BookModel extends MediaTypeModel { this.pages = undefined; this.image = undefined; this.onlineRating = undefined; + this.isbn = undefined; this.released = undefined; From d21ac660612839234659083f3fecf73cb1579438 Mon Sep 17 00:00:00 2001 From: ltctceplrm <14954927+ltctceplrm@users.noreply.github.com> Date: Tue, 19 Dec 2023 20:39:26 +0100 Subject: [PATCH 2/4] Added isbn13 as well --- src/api/apis/OpenLibraryAPI.ts | 3 ++- src/models/BookModel.ts | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/api/apis/OpenLibraryAPI.ts b/src/api/apis/OpenLibraryAPI.ts index 72c165a..3e7e09d 100644 --- a/src/api/apis/OpenLibraryAPI.ts +++ b/src/api/apis/OpenLibraryAPI.ts @@ -69,7 +69,8 @@ export class OpenLibraryAPI extends APIModel { dataSource: this.apiName, url: `https://openlibrary.org` + result.key, id: result.key, - isbn: result.isbn[0] ?? 'unknown', + isbn: result.isbn.find((el: string | any[]) => el.length <= 10) ?? 'unknown', + isbn13: result.isbn.find((el: string | any[]) => el.length == 13) ?? 'unknown', englishTitle: result.title_english ?? result.title, author: result.author_name ?? 'unknown', diff --git a/src/models/BookModel.ts b/src/models/BookModel.ts index 60860d5..f381d2e 100644 --- a/src/models/BookModel.ts +++ b/src/models/BookModel.ts @@ -10,6 +10,7 @@ export class BookModel extends MediaTypeModel { onlineRating: number; english_title: string; isbn: number; + isbn13: number; released: boolean; @@ -27,6 +28,7 @@ export class BookModel extends MediaTypeModel { this.image = undefined; this.onlineRating = undefined; this.isbn = undefined; + this.isbn13 = undefined; this.released = undefined; From e30db0897d6ffa4bb87b1ee05d39b440a189d893 Mon Sep 17 00:00:00 2001 From: ltctceplrm <14954927+ltctceplrm@users.noreply.github.com> Date: Thu, 21 Dec 2023 20:33:51 +0100 Subject: [PATCH 3/4] Added author in the search results for books --- src/api/apis/OpenLibraryAPI.ts | 11 ++++++++--- src/models/BookModel.ts | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/api/apis/OpenLibraryAPI.ts b/src/api/apis/OpenLibraryAPI.ts index 3e7e09d..e2ba01d 100644 --- a/src/api/apis/OpenLibraryAPI.ts +++ b/src/api/apis/OpenLibraryAPI.ts @@ -19,9 +19,13 @@ export class OpenLibraryAPI extends APIModel { async searchByTitle(title: string): Promise { console.log(`MDB | api "${this.apiName}" queried by Title`); - - const searchUrl = `https://openlibrary.org/search.json?title=${encodeURIComponent(title)}`; - + const titlesplit = title.split("++") + if(titlesplit.length !== 1 ){ + var searchUrl = `https://openlibrary.org/search.json?title=${encodeURIComponent(titlesplit[0])}&author=${encodeURIComponent(titlesplit[1])}`; + } + else{ + var searchUrl = `https://openlibrary.org/search.json?title=${encodeURIComponent(title)}`; + } const fetchData = await fetch(searchUrl); console.debug(fetchData); if (fetchData.status !== 200) { @@ -41,6 +45,7 @@ export class OpenLibraryAPI extends APIModel { year: result.first_publish_year, dataSource: this.apiName, id: result.key, + author: result.author_name ?? 'unknown', } as BookModel), ); } diff --git a/src/models/BookModel.ts b/src/models/BookModel.ts index f381d2e..183d402 100644 --- a/src/models/BookModel.ts +++ b/src/models/BookModel.ts @@ -56,6 +56,6 @@ export class BookModel extends MediaTypeModel { } getSummary(): string { - return this.englishTitle + ' (' + this.year + ')'; + return this.englishTitle + ' (' + this.year + ') - ' + this.author; } } From 80cca27bdef6ba38b8f3ed2223cdf612d8b2bea5 Mon Sep 17 00:00:00 2001 From: ltctceplrm <14954927+ltctceplrm@users.noreply.github.com> Date: Thu, 21 Dec 2023 20:35:59 +0100 Subject: [PATCH 4/4] Removed test for title + author search Forgot to remove this --- src/api/apis/OpenLibraryAPI.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/api/apis/OpenLibraryAPI.ts b/src/api/apis/OpenLibraryAPI.ts index e2ba01d..4591b14 100644 --- a/src/api/apis/OpenLibraryAPI.ts +++ b/src/api/apis/OpenLibraryAPI.ts @@ -19,13 +19,9 @@ export class OpenLibraryAPI extends APIModel { async searchByTitle(title: string): Promise { console.log(`MDB | api "${this.apiName}" queried by Title`); - const titlesplit = title.split("++") - if(titlesplit.length !== 1 ){ - var searchUrl = `https://openlibrary.org/search.json?title=${encodeURIComponent(titlesplit[0])}&author=${encodeURIComponent(titlesplit[1])}`; - } - else{ - var searchUrl = `https://openlibrary.org/search.json?title=${encodeURIComponent(title)}`; - } + + const searchUrl = `https://openlibrary.org/search.json?title=${encodeURIComponent(title)}`; + const fetchData = await fetch(searchUrl); console.debug(fetchData); if (fetchData.status !== 200) {