Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions client/src/app/book.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,14 @@ export class BookService {

return this.http.get<Book[]>(`${URL}/books/search?term=${query}`);
}

similar(isbn: string, limit = 5): Observable<BookView[]> {
if (limit > 100) {
limit = 100;
}

return this.http.get<Book[]>(`${URL}/books/similar?isbn=${isbn}`).pipe(
map((books:Book[]) => books.map((book:Book) => new BookView(book)))
);
}
}
35 changes: 34 additions & 1 deletion client/src/app/book/book.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,39 @@ <h3>Publisher Country</h3>
</mat-card-content>
</mat-card>

<mat-card class="book-recs">
<h3>Similar Books</h3>
<div class="book-recs-content" *ngIf="similarBooks | async; else noRecs">
<mat-card *ngFor="let book of similarBooks | async" class="book-card">
<img class="img-link cropped book-thumbnail"
onerror="this.onerror=null; this.src='http://lgimages.s3.amazonaws.com/gc-md.gif'"
[routerLink]="['/books', book.isbn]"
mat-card-image [src]="book.cover" [alt]="book.title" />

<mat-card-header class="book-card-header">
<mat-card-title class="book-card-title">
<h5 class="book-title"><a [routerLink]="['/books', book.isbn]">{{ book.title }}</a></h5>
<span class="book-authors">by
<span *ngFor="let author of book.authors; let last = last">
<a [routerLink]="['/authors', author._id]">{{ author.name }}</a>
<span *ngIf="!last">, </span>
</span>
</span>
</mat-card-title>
</mat-card-header>

<mat-card-content class="book-card-content">
<div>
<p class="book-description" [innerHTML]="book.synopsis"></p>
</div>
</mat-card-content>
</mat-card>
</div>
<ng-template #noRecs>
<p>No similar books found. </p>
</ng-template>
</mat-card>

<mat-card class="book-reviews">
<h3>Reviews from Readers</h3>

Expand All @@ -82,4 +115,4 @@ <h3>Reviews from Readers</h3>
<h3>Write a Review</h3>
<lms-review-form [bookId]="book.isbn" (reviewAdded)="refetchBook()"></lms-review-form>
</mat-card>
</div>
</div>
6 changes: 6 additions & 0 deletions client/src/app/book/book.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BookService } from '../book.service';
import { BookView } from '../models/book-view';
import { Reservation } from '../models/reservation';
import { ReservationService } from '../reservation.service';
import {Observable} from "rxjs";

@Component({
selector: 'lms-book',
Expand All @@ -12,6 +13,7 @@ import { ReservationService } from '../reservation.service';
})
export class BookComponent implements OnInit {
book: BookView;
similarBooks: Observable<BookView[]>;
reservation: Reservation | undefined;

constructor(
Expand Down Expand Up @@ -47,6 +49,10 @@ export class BookComponent implements OnInit {
});
}

getSimilarBooks() {
this.similarBooks = this.bookService.similar(this.book.isbn);
}

setUserReservation(reservations: Reservation[]) {
this.reservation = reservations.find(r => r.book._id === this.book.isbn);
}
Expand Down
4 changes: 0 additions & 4 deletions server/.env

This file was deleted.

1 change: 1 addition & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
Loading