implemented hooks for user-collections & user-collection-entry models to update updatedAt and order fields

This commit is contained in:
X4Lo committed 2024-04-30 22:21:17 +01:00
1 parent 36866dabe6
commit cea1b207a3
12 files changed
+170 -61

No files matched your search

@@ -46,12 +46,11 @@ export class UserCollectionService {
// Add an entry to a list
addEntryToCollection(
userCollectionId: number,
entryId: number,
order: number
entryId: number
): Observable<UserCollectionEntry> {
return this.http.post<UserCollectionEntry>(
`${this.backend_apiUrl}/${this.apiAction}/${userCollectionId}/entries/${entryId}`,
{ order: order }
{}
);
}
@@ -2,7 +2,7 @@
<div class="card-head">
<img class="card-img" [src]="getPostPath()" alt="Movie Poster">
<div class="card-overlay" (click)="cardClick()">
<div class="card-overlay">
<div class="rating">
<i class='bx bx-star'></i>
<span>{{formattedRate}}</span>
@@ -98,7 +98,7 @@ export class UserCollectionGridCardComponent {
// ? EVENTS
cardClick() {
if (this.entry.isInLibrary)
this.router.navigate([`/entry/${this.entry.id}`]);
this.router.navigate([`/entries/${this.entry.id}`]);
}
// ? EVENT EMITTER
@@ -2,8 +2,8 @@ import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { UserCollectionService } from '../../../../core/services/userCollection.service';
import { UserCollection } from '../../../../shared/models/userCollection.model';
import { Entry } from '../../../../shared/models/entry.model';
import { DatePipe } from '@angular/common';
import { CollectionEntry } from '../../../../shared/models/dtos/collection-entry.dto';
@Component({
selector: 'app-userCollection-info-page',
@@ -11,7 +11,7 @@ import { DatePipe } from '@angular/common';
styleUrls: ['./userCollection-info-page.component.css'],
providers: [DatePipe],
})
export class UserCollectionInfoPageComponent implements OnInit{
export class UserCollectionInfoPageComponent implements OnInit {
list: UserCollection = {} as UserCollection;
createdAt: string = '';
updatedAt: string = '';
@@ -28,20 +28,15 @@ export class UserCollectionInfoPageComponent implements OnInit{
this.listService.getCollection(id.toString()).subscribe(
(data) => {
// Handle the successful reception of data.
this.list = data as unknown as UserCollection;
this.list.entries = this.list.entries as Entry[];
this.list.entries = this.list.entries as CollectionEntry[];
this.createdAt = this.getCreatedDate()?.toString() || '';
this.updatedAt = this.getUpdatedAt()?.toString() || '';
console.log('Data received:', this.list);
console.log(`Collection "${this.list.name}" received:`, this.list);
},
(error) => {
// Handle any error that occurs during the subscription
console.error('Error occurred:', error);
},
() => {
// Handle completion of the Observable
}
);
}
@@ -54,6 +49,7 @@ export class UserCollectionInfoPageComponent implements OnInit{
return this.datePipe.transform(this.list.createdAt, 'dd MMMM, yyyy');
}
// TODO use a relativeDate pipe
getUpdatedAt() {
const updatedAt = this.list.updatedAt;
// First, check if updatedAt is a valid date string or timestamp
@@ -77,14 +73,14 @@ export class UserCollectionInfoPageComponent implements OnInit{
const diffInHours = diffInMs / (1000 * 60 * 60);
if (diffInHours < 1) {
const diffInMinutes = diffInMs / (1000 * 60);
if(diffInMinutes >= 2) isPlural = 's'
if (diffInMinutes >= 2) isPlural = 's';
return `${Math.floor(diffInMinutes)} minute${isPlural} ago`;
}
if(diffInHours >= 2) isPlural = 's'
return `${Math.floor(diffInHours)} hour${isPlural} ago`;
if (diffInHours >= 2) isPlural = 's';
return `${Math.floor(diffInHours)} hour${isPlural} ago`;
}
if(diffInDays >= 2) isPlural = 's'
if (diffInDays >= 2) isPlural = 's';
return `${Math.floor(diffInDays)} day${isPlural} ago`;
} else {
// More than a week, show formatted date
@@ -43,7 +43,7 @@ export class UserCollectionsListItemComponent {
}
redirectTo(): void {
this.router.navigate([`/user-collections/${this.list.id}`]);
this.router.navigate([`/collections/${this.list.id}`]);
}
deleteList() {
@@ -124,11 +124,7 @@ export class UserCollectionsModalComponent implements OnInit {
`Adding Entry ${this.entryId} to list: ${userCollection.name}`
);
this.listService
.addEntryToCollection(
userCollection.id,
this.entryId,
userCollection.userCollectionEntries.length + 1
)
.addEntryToCollection(userCollection.id, this.entryId)
.subscribe({
next: (response) => {
console.log('Successfuly added Entry To Collection:', response);
@@ -0,0 +1,5 @@
import { Entry } from '../entry.model';
export interface CollectionEntry extends Entry {
order: number;
}
@@ -1,4 +1,4 @@
import { Entry } from './entry.model';
import { CollectionEntry } from './dtos/collection-entry.dto';
import { UserCollectionEntry } from './userCollectionEntry.model';
export interface UserCollection {
@@ -11,7 +11,7 @@ export interface UserCollection {
poster_path: string;
userCollectionEntries: UserCollectionEntry[];
entries: Entry[];
entries: CollectionEntry[];
changed: boolean;
isChecked: boolean;