Skip to content

Commit

Permalink
Added author in the search results for books
Browse files Browse the repository at this point in the history
  • Loading branch information
ltctceplrm committed Dec 21, 2023
1 parent d21ac66 commit e30db08
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/api/apis/OpenLibraryAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ export class OpenLibraryAPI extends APIModel {

async searchByTitle(title: string): Promise<MediaTypeModel[]> {
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) {
Expand All @@ -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),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/BookModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ export class BookModel extends MediaTypeModel {
}

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

0 comments on commit e30db08

Please sign in to comment.