Skip to content

Commit e30db08

Browse files
committed
Added author in the search results for books
1 parent d21ac66 commit e30db08

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/api/apis/OpenLibraryAPI.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ export class OpenLibraryAPI extends APIModel {
1919

2020
async searchByTitle(title: string): Promise<MediaTypeModel[]> {
2121
console.log(`MDB | api "${this.apiName}" queried by Title`);
22-
23-
const searchUrl = `https://openlibrary.org/search.json?title=${encodeURIComponent(title)}`;
24-
22+
const titlesplit = title.split("++")
23+
if(titlesplit.length !== 1 ){
24+
var searchUrl = `https://openlibrary.org/search.json?title=${encodeURIComponent(titlesplit[0])}&author=${encodeURIComponent(titlesplit[1])}`;
25+
}
26+
else{
27+
var searchUrl = `https://openlibrary.org/search.json?title=${encodeURIComponent(title)}`;
28+
}
2529
const fetchData = await fetch(searchUrl);
2630
console.debug(fetchData);
2731
if (fetchData.status !== 200) {
@@ -41,6 +45,7 @@ export class OpenLibraryAPI extends APIModel {
4145
year: result.first_publish_year,
4246
dataSource: this.apiName,
4347
id: result.key,
48+
author: result.author_name ?? 'unknown',
4449
} as BookModel),
4550
);
4651
}

src/models/BookModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ export class BookModel extends MediaTypeModel {
5656
}
5757

5858
getSummary(): string {
59-
return this.englishTitle + ' (' + this.year + ')';
59+
return this.englishTitle + ' (' + this.year + ') - ' + this.author;
6060
}
6161
}

0 commit comments

Comments
 (0)