Implement refresh library

This commit is contained in:
aditya.chandel
2024-12-26 14:36:55 -07:00
parent f3bf5e9c0b
commit bc1aa39b34
18 changed files with 214 additions and 32 deletions
+7 -3
View File
@@ -1,8 +1,8 @@
import {Component, OnInit} from '@angular/core';
import {RxStompService} from './book/service/rx-stomp.service';
import {Message} from '@stomp/stompjs';
import {Book} from './book/model/book.model';
import {BookService} from './book/service/book.service';
import {Action, parseBookNotification} from './book/model/book-notification.model';
@Component({
selector: 'app-root',
@@ -17,8 +17,12 @@ export class AppComponent implements OnInit {
ngOnInit(): void {
this.rxStompService.watch('/topic/books').subscribe((message: Message) => {
const book: Book = JSON.parse(message.body);
this.bookService.handleNewlyCreatedBook(book);
const notification = parseBookNotification(message.body);
if (notification.action === Action.BOOK_ADDED) {
this.bookService.handleNewlyCreatedBook(notification.addedBook!);
} else if (notification.action === Action.BOOKS_REMOVED) {
this.bookService.handleRemovedBookIds(notification.removedBookIds!);
}
});
}