diff --git a/frontend/src/app/features/cards/main-card/main-card.component.html b/frontend/src/app/features/cards/main-card/main-card.component.html
index f3e235f..da4c238 100644
--- a/frontend/src/app/features/cards/main-card/main-card.component.html
+++ b/frontend/src/app/features/cards/main-card/main-card.component.html
@@ -7,12 +7,18 @@
{{formattedRate}}
-
diff --git a/frontend/src/app/features/cards/main-card/main-card.component.ts b/frontend/src/app/features/cards/main-card/main-card.component.ts
index a146199..f5eb9c4 100644
--- a/frontend/src/app/features/cards/main-card/main-card.component.ts
+++ b/frontend/src/app/features/cards/main-card/main-card.component.ts
@@ -1,16 +1,28 @@
-import { Component, Input } from '@angular/core';
+import { Component, Input, OnInit } from '@angular/core';
import { Entry } from '../../../shared/models/entry.model';
import { EntryService } from '../../../core/services/entry.service';
+import { LibraryService } from '../../../core/services/library.service';
@Component({
selector: 'app-main-card',
templateUrl: './main-card.component.html',
styleUrls: ['./main-card.component.css'],
})
-export class MainCardComponent {
+export class MainCardComponent implements OnInit {
@Input() entry!: Entry;
- constructor(private entryService: EntryService) {}
+ constructor(private libraryService: LibraryService) {}
+
+ ngOnInit(): void {
+ this.libraryService.isInLibrary(this.entry.entryId.tmdb_id).subscribe({
+ next: (e) => {
+ if (e != null) {
+ e.isInLibrary = true;
+ this.entry = e;
+ }
+ },
+ });
+ }
get releaseYear(): number {
return new Date(this.entry.release_date).getFullYear();
@@ -20,11 +32,15 @@ export class MainCardComponent {
return this.entry.entryRating.tmdb_rating.toFixed(1);
}
- addEntry(tmdb_id: string) {
+ addEntry(tmdb_id: string, is_tvserie: boolean) {
console.log('Adding Entry To Library.');
- this.entryService.addEntry(tmdb_id).subscribe({
+ this.libraryService.addEntry(tmdb_id, is_tvserie).subscribe({
next: (entry) => {
- console.log(entry);
+ if (entry != null) {
+ entry.isInLibrary = true;
+ this.entry = entry;
+ console.log(entry);
+ }
},
error: (error) => {
console.error('Error adding entry:', error);
@@ -32,6 +48,23 @@ export class MainCardComponent {
});
}
+ removeEntry(id: number) {
+ console.log('Deleting Entry From Library.');
+ this.libraryService.deleteEntry(id).subscribe({
+ next: (response) => {
+ // Handle successful deletion
+ console.log('Entry successfully deleted.', response);
+ this.entry.id = 0;
+ this.entry.isInLibrary = false;
+ },
+ error: (error) => {
+ // Handle error scenario
+ console.error('Error deleting entry:', error);
+ // Optionally, display an error message to the user using a service or a component
+ },
+ });
+ }
+
logEntry() {
console.log(this.entry);
}