Merge pull request #911 from booklore-app/develop
Merge Develop into Master for release
This commit is contained in:
+36
@@ -0,0 +1,36 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.BookNote;
|
||||
import com.adityachandel.booklore.model.dto.CreateBookNoteRequest;
|
||||
import com.adityachandel.booklore.service.BookNoteService;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/book-notes")
|
||||
@AllArgsConstructor
|
||||
public class BookNoteController {
|
||||
|
||||
private final BookNoteService bookNoteService;
|
||||
|
||||
|
||||
@GetMapping("/book/{bookId}")
|
||||
public List<BookNote> getNotesForBook(@PathVariable Long bookId) {
|
||||
return bookNoteService.getNotesForBook(bookId);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public BookNote createNote(@Valid @RequestBody CreateBookNoteRequest request) {
|
||||
return bookNoteService.createOrUpdateNote(request);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{noteId}")
|
||||
public ResponseEntity<Void> deleteNote(@PathVariable Long noteId) {
|
||||
bookNoteService.deleteNote(noteId);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.BookReview;
|
||||
import com.adityachandel.booklore.service.BookReviewService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/reviews")
|
||||
@AllArgsConstructor
|
||||
public class BookReviewController {
|
||||
|
||||
private final BookReviewService bookReviewService;
|
||||
|
||||
@GetMapping("/book/{bookId}")
|
||||
public List<BookReview> listByBook(@PathVariable Long bookId) {
|
||||
return bookReviewService.getByBookId(bookId);
|
||||
}
|
||||
|
||||
@PostMapping("/book/{bookId}/refresh")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
public List<BookReview> refreshReviews(@PathVariable Long bookId) {
|
||||
return bookReviewService.refreshReviews(bookId);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<Void> delete(@PathVariable Long id) {
|
||||
bookReviewService.delete(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/book/{bookId}")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<Void> deleteAllByBookId(@PathVariable Long bookId) {
|
||||
bookReviewService.deleteAllByBookId(bookId);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.adityachandel.booklore.mapper;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.BookNote;
|
||||
import com.adityachandel.booklore.model.entity.BookNoteEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface BookNoteMapper {
|
||||
|
||||
@Mapping(target = "userId", source = "user.id")
|
||||
@Mapping(target = "bookId", source = "book.id")
|
||||
BookNote toDto(BookNoteEntity entity);
|
||||
|
||||
@Mapping(target = "user", ignore = true)
|
||||
@Mapping(target = "book", ignore = true)
|
||||
@Mapping(target = "createdAt", ignore = true)
|
||||
@Mapping(target = "updatedAt", ignore = true)
|
||||
BookNoteEntity toEntity(BookNote dto);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.adityachandel.booklore.mapper;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.BookReview;
|
||||
import com.adityachandel.booklore.model.entity.BookReviewEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface BookReviewMapper {
|
||||
|
||||
BookReview toDto(BookReviewEntity entity);
|
||||
|
||||
@Mapping(target = "id", ignore = true)
|
||||
@Mapping(target = "bookMetadata", ignore = true)
|
||||
BookReviewEntity toEntity(BookReview dto);
|
||||
}
|
||||
|
||||
@@ -32,4 +32,5 @@ public class MetadataClearFlags {
|
||||
private boolean authors;
|
||||
private boolean categories;
|
||||
private boolean cover;
|
||||
private boolean reviews;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ public class BookMetadata {
|
||||
private Set<String> categories;
|
||||
private MetadataProvider provider;
|
||||
private String thumbnailUrl;
|
||||
private List<BookReview> bookReviews;
|
||||
|
||||
private Boolean titleLocked;
|
||||
private Boolean subtitleLocked;
|
||||
@@ -75,4 +76,5 @@ public class BookMetadata {
|
||||
private Boolean coverLocked;
|
||||
private Boolean authorsLocked;
|
||||
private Boolean categoriesLocked;
|
||||
private Boolean reviewsLocked;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.adityachandel.booklore.model.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BookNote {
|
||||
private Long id;
|
||||
private Long userId;
|
||||
private Long bookId;
|
||||
private String title;
|
||||
private String content;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.adityachandel.booklore.model.dto;
|
||||
|
||||
import com.adityachandel.booklore.model.enums.MetadataProvider;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class BookReview {
|
||||
private Long id;
|
||||
private MetadataProvider metadataProvider;
|
||||
private String reviewerName;
|
||||
private String title;
|
||||
private Float rating;
|
||||
private Instant date;
|
||||
private String body;
|
||||
private String country;
|
||||
private Boolean spoiler;
|
||||
private Integer followersCount;
|
||||
private Integer textReviewsCount;
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.adityachandel.booklore.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CreateBookNoteRequest {
|
||||
private Long id;
|
||||
|
||||
@NotNull(message = "Book ID is required")
|
||||
private Long bookId;
|
||||
|
||||
private String title;
|
||||
|
||||
@NotBlank(message = "Content is required")
|
||||
private String content;
|
||||
}
|
||||
+1
-1
@@ -19,6 +19,6 @@ public class ReadProgressRequest {
|
||||
|
||||
@AssertTrue(message = "At least one progress field must be provided")
|
||||
public boolean isProgressValid() {
|
||||
return epubProgress != null || pdfProgress != null || cbxProgress != null;
|
||||
return epubProgress != null || pdfProgress != null || cbxProgress != null || dateFinished != null;
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -12,6 +12,7 @@ public enum AppSettingKey {
|
||||
METADATA_PROVIDER_SETTINGS("metadata_provider_settings", true),
|
||||
METADATA_MATCH_WEIGHTS("metadata_match_weights", true),
|
||||
METADATA_PERSISTENCE_SETTINGS("metadata_persistence_settings", true),
|
||||
METADATA_PUBLIC_REVIEWS_SETTINGS("metadata_public_reviews_settings", true),
|
||||
|
||||
AUTO_BOOK_SEARCH("auto_book_search", false),
|
||||
COVER_IMAGE_RESOLUTION("cover_image_resolution", false),
|
||||
|
||||
+1
@@ -29,4 +29,5 @@ public class AppSettings {
|
||||
private MetadataProviderSettings metadataProviderSettings;
|
||||
private MetadataMatchWeights metadataMatchWeights;
|
||||
private MetadataPersistenceSettings metadataPersistenceSettings;
|
||||
private MetadataPublicReviewsSettings metadataPublicReviewsSettings;
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.adityachandel.booklore.model.dto.settings;
|
||||
|
||||
import com.adityachandel.booklore.model.enums.MetadataProvider;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public class MetadataPublicReviewsSettings {
|
||||
|
||||
private boolean downloadEnabled;
|
||||
private Set<ReviewProviderConfig> providers;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public static class ReviewProviderConfig {
|
||||
private MetadataProvider provider;
|
||||
private boolean enabled;
|
||||
private int maxReviews;
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -8,7 +8,7 @@ import org.hibernate.annotations.FetchMode;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity
|
||||
@@ -191,6 +191,9 @@ public class BookMetadataEntity {
|
||||
@Column(name = "comicvine_id_locked")
|
||||
private Boolean comicvineIdLocked = Boolean.FALSE;
|
||||
|
||||
@Column(name = "reviews_locked")
|
||||
private Boolean reviewsLocked = Boolean.FALSE;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@MapsId
|
||||
@JoinColumn(name = "book_id")
|
||||
@@ -214,6 +217,10 @@ public class BookMetadataEntity {
|
||||
@Fetch(FetchMode.SUBSELECT)
|
||||
private Set<CategoryEntity> categories;
|
||||
|
||||
@OneToMany(mappedBy = "bookMetadata", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||
@Fetch(FetchMode.SUBSELECT)
|
||||
private Set<BookReviewEntity> reviews = new HashSet<>();
|
||||
|
||||
public void applyLockToAllFields(boolean lock) {
|
||||
this.titleLocked = lock;
|
||||
this.subtitleLocked = lock;
|
||||
@@ -242,6 +249,7 @@ public class BookMetadataEntity {
|
||||
this.goodreadsIdLocked = lock;
|
||||
this.hardcoverIdLocked = lock;
|
||||
this.googleIdLocked = lock;
|
||||
this.reviewsLocked = lock;
|
||||
}
|
||||
|
||||
public boolean areAllFieldsLocked() {
|
||||
@@ -272,6 +280,7 @@ public class BookMetadataEntity {
|
||||
&& Boolean.TRUE.equals(this.comicvineIdLocked)
|
||||
&& Boolean.TRUE.equals(this.hardcoverIdLocked)
|
||||
&& Boolean.TRUE.equals(this.googleIdLocked)
|
||||
&& Boolean.TRUE.equals(this.reviewsLocked)
|
||||
;
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package com.adityachandel.booklore.model.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import org.hibernate.annotations.UpdateTimestamp;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "book_notes")
|
||||
public class BookNoteEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
private BookLoreUserEntity user;
|
||||
|
||||
@Column(name = "user_id", insertable = false, updatable = false)
|
||||
private Long userId;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "book_id", nullable = false)
|
||||
private BookEntity book;
|
||||
|
||||
@Column(name = "book_id", insertable = false, updatable = false)
|
||||
private Long bookId;
|
||||
|
||||
@Column(name = "title")
|
||||
private String title;
|
||||
|
||||
@Column(name = "content", nullable = false, columnDefinition = "TEXT")
|
||||
private String content;
|
||||
|
||||
@CreationTimestamp
|
||||
@Column(name = "created_at", nullable = false, updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@UpdateTimestamp
|
||||
@Column(name = "updated_at", nullable = false)
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package com.adityachandel.booklore.model.entity;
|
||||
|
||||
import com.adityachandel.booklore.model.enums.MetadataProvider;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "public_book_review")
|
||||
public class BookReviewEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "metadata_provider", nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private MetadataProvider metadataProvider;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "book_id", nullable = false)
|
||||
private BookMetadataEntity bookMetadata;
|
||||
|
||||
@Column(name = "reviewer_name", length = 512)
|
||||
private String reviewerName;
|
||||
|
||||
@Column(name = "title", length = 512)
|
||||
private String title;
|
||||
|
||||
@Column(name = "rating")
|
||||
private Float rating;
|
||||
|
||||
@Column(name = "date")
|
||||
private Instant date;
|
||||
|
||||
@Column(name = "body", columnDefinition = "TEXT")
|
||||
private String body;
|
||||
|
||||
@Column(name = "country", length = 512)
|
||||
private String country;
|
||||
|
||||
@Column(name = "spoiler")
|
||||
private Boolean spoiler;
|
||||
|
||||
@Column(name = "followers_count")
|
||||
private Integer followersCount;
|
||||
|
||||
@Column(name = "text_reviews_count")
|
||||
private Integer textReviewsCount;
|
||||
}
|
||||
+1
-2
@@ -13,8 +13,7 @@ import java.time.LocalDateTime;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "user_settings",
|
||||
uniqueConstraints = {@UniqueConstraint(columnNames = {"user_id", "setting_key"})})
|
||||
@Table(name = "user_settings", uniqueConstraints = {@UniqueConstraint(columnNames = {"user_id", "setting_key"})})
|
||||
public class UserSettingEntity {
|
||||
|
||||
@Id
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.adityachandel.booklore.repository;
|
||||
|
||||
import com.adityachandel.booklore.model.entity.BookNoteEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface BookNoteRepository extends JpaRepository<BookNoteEntity, Long> {
|
||||
|
||||
Optional<BookNoteEntity> findByIdAndUserId(Long id, Long userId);
|
||||
|
||||
@Query("SELECT n FROM BookNoteEntity n WHERE n.bookId = :bookId AND n.userId = :userId ORDER BY n.updatedAt DESC")
|
||||
List<BookNoteEntity> findByBookIdAndUserIdOrderByUpdatedAtDesc(@Param("bookId") Long bookId, @Param("userId") Long userId);
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.adityachandel.booklore.repository;
|
||||
|
||||
import com.adityachandel.booklore.model.entity.BookReviewEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BookReviewRepository extends JpaRepository<BookReviewEntity, Long> {
|
||||
List<BookReviewEntity> findByBookMetadataBookId(Long bookId);
|
||||
|
||||
@Modifying
|
||||
@Query("DELETE FROM BookReviewEntity r WHERE r.bookMetadata.book.id = :bookId")
|
||||
void deleteByBookMetadataBookId(@Param("bookId") Long bookId);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
|
||||
import com.adityachandel.booklore.config.security.AuthenticationService;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.mapper.BookNoteMapper;
|
||||
import com.adityachandel.booklore.model.dto.BookLoreUser;
|
||||
import com.adityachandel.booklore.model.dto.BookNote;
|
||||
import com.adityachandel.booklore.model.dto.CreateBookNoteRequest;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookLoreUserEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookNoteEntity;
|
||||
import com.adityachandel.booklore.repository.BookNoteRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.repository.UserRepository;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class BookNoteService {
|
||||
|
||||
private final BookNoteRepository bookNoteRepository;
|
||||
private final BookRepository bookRepository;
|
||||
private final UserRepository userRepository;
|
||||
private final BookNoteMapper mapper;
|
||||
private final AuthenticationService authenticationService;
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<BookNote> getNotesForBook(Long bookId) {
|
||||
BookLoreUser currentUser = authenticationService.getAuthenticatedUser();
|
||||
return bookNoteRepository.findByBookIdAndUserIdOrderByUpdatedAtDesc(bookId, currentUser.getId())
|
||||
.stream()
|
||||
.map(mapper::toDto)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public BookNote createOrUpdateNote(CreateBookNoteRequest request) {
|
||||
BookLoreUser currentUser = authenticationService.getAuthenticatedUser();
|
||||
|
||||
BookEntity book = bookRepository.findById(request.getBookId())
|
||||
.orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(request.getBookId()));
|
||||
|
||||
BookLoreUserEntity user = userRepository.findById(currentUser.getId())
|
||||
.orElseThrow(() -> new EntityNotFoundException("User not found: " + currentUser.getId()));
|
||||
|
||||
BookNoteEntity noteEntity;
|
||||
|
||||
if (request.getId() != null) {
|
||||
noteEntity = bookNoteRepository.findByIdAndUserId(request.getId(), currentUser.getId())
|
||||
.orElseThrow(() -> new EntityNotFoundException("Note not found: " + request.getId()));
|
||||
noteEntity.setTitle(request.getTitle());
|
||||
noteEntity.setContent(request.getContent());
|
||||
} else {
|
||||
noteEntity = BookNoteEntity.builder()
|
||||
.user(user)
|
||||
.book(book)
|
||||
.title(request.getTitle())
|
||||
.content(request.getContent())
|
||||
.build();
|
||||
}
|
||||
|
||||
BookNoteEntity savedNote = bookNoteRepository.save(noteEntity);
|
||||
return mapper.toDto(savedNote);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteNote(Long noteId) {
|
||||
BookLoreUser currentUser = authenticationService.getAuthenticatedUser();
|
||||
BookNoteEntity note = bookNoteRepository.findByIdAndUserId(noteId, currentUser.getId()).orElseThrow(() -> new EntityNotFoundException("Note not found: " + noteId));
|
||||
bookNoteRepository.delete(note);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
|
||||
import com.adityachandel.booklore.config.security.AuthenticationService;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.mapper.BookReviewMapper;
|
||||
import com.adityachandel.booklore.model.dto.BookLoreUser;
|
||||
import com.adityachandel.booklore.model.dto.BookMetadata;
|
||||
import com.adityachandel.booklore.model.dto.BookReview;
|
||||
import com.adityachandel.booklore.model.dto.settings.MetadataPublicReviewsSettings;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.enums.MetadataProvider;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.repository.BookReviewRepository;
|
||||
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
||||
import com.adityachandel.booklore.service.metadata.BookReviewUpdateService;
|
||||
import com.adityachandel.booklore.service.metadata.MetadataRefreshService;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class BookReviewService {
|
||||
|
||||
private final BookReviewRepository bookReviewRepository;
|
||||
private final BookReviewMapper mapper;
|
||||
private final BookReviewUpdateService bookReviewUpdateService;
|
||||
private final BookRepository bookRepository;
|
||||
private final AppSettingService appSettingService;
|
||||
private final MetadataRefreshService metadataRefreshService;
|
||||
private final AuthenticationService authenticationService;
|
||||
|
||||
public List<BookReview> getByBookId(Long bookId) {
|
||||
List<BookReview> reviews = bookReviewRepository.findByBookMetadataBookId(bookId).stream()
|
||||
.map(mapper::toDto)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!appSettingService.getAppSettings().getMetadataPublicReviewsSettings().isDownloadEnabled() || !reviews.isEmpty()) {
|
||||
return reviews;
|
||||
}
|
||||
|
||||
BookLoreUser user = authenticationService.getAuthenticatedUser();
|
||||
if (!(user.getPermissions().isAdmin() || user.getPermissions().isCanManipulateLibrary())) {
|
||||
return reviews;
|
||||
}
|
||||
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
bookReviewUpdateService.addReviewsToBook(fetchBookReviews(bookEntity), bookEntity.getMetadata());
|
||||
bookRepository.save(bookEntity);
|
||||
return bookReviewRepository.findByBookMetadataBookId(bookId).stream()
|
||||
.map(mapper::toDto)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<BookReview> fetchBookReviews(BookEntity bookEntity) {
|
||||
|
||||
MetadataPublicReviewsSettings settings = appSettingService.getAppSettings().getMetadataPublicReviewsSettings();
|
||||
if (!settings.isDownloadEnabled()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<MetadataProvider> providers = settings.getProviders().stream()
|
||||
.filter(MetadataPublicReviewsSettings.ReviewProviderConfig::isEnabled)
|
||||
.map(MetadataPublicReviewsSettings.ReviewProviderConfig::getProvider)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Map<MetadataProvider, BookMetadata> metadataMap = metadataRefreshService.fetchMetadataForBook(providers, bookEntity);
|
||||
|
||||
return metadataMap.values().stream()
|
||||
.filter(meta -> meta.getBookReviews() != null)
|
||||
.flatMap(meta -> meta.getBookReviews().stream())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void delete(Long id) {
|
||||
if (!bookReviewRepository.existsById(id)) {
|
||||
throw new EntityNotFoundException("Review not found: " + id);
|
||||
}
|
||||
bookReviewRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<BookReview> refreshReviews(Long bookId) {
|
||||
BookEntity bookEntity = bookRepository.findById(bookId)
|
||||
.orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
|
||||
bookEntity.getMetadata().getReviews().clear();
|
||||
bookRepository.save(bookEntity);
|
||||
|
||||
bookReviewRepository.deleteByBookMetadataBookId(bookId);
|
||||
|
||||
List<BookReview> freshReviews = fetchBookReviews(bookEntity);
|
||||
bookReviewUpdateService.addReviewsToBook(freshReviews, bookEntity.getMetadata());
|
||||
bookRepository.save(bookEntity);
|
||||
|
||||
return bookReviewRepository.findByBookMetadataBookId(bookId).stream()
|
||||
.map(mapper::toDto)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteAllByBookId(Long bookId) {
|
||||
if (!bookRepository.existsById(bookId)) {
|
||||
throw ApiError.BOOK_NOT_FOUND.createException(bookId);
|
||||
}
|
||||
bookReviewRepository.deleteByBookMetadataBookId(bookId);
|
||||
}
|
||||
}
|
||||
@@ -312,9 +312,12 @@ public class BookService {
|
||||
userBookProgress.setCbxProgress(request.getCbxProgress().getPage());
|
||||
userBookProgress.setCbxProgressPercent(request.getCbxProgress().getPercentage());
|
||||
}
|
||||
|
||||
// Update dateFinished if provided
|
||||
if (request.getDateFinished() != null) {
|
||||
userBookProgress.setDateFinished(request.getDateFinished());
|
||||
}
|
||||
|
||||
userBookProgressRepository.save(userBookProgress);
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ public class VersionService {
|
||||
if (tag == null || !isVersionGreater(tag, currentVersion)) {
|
||||
continue;
|
||||
}
|
||||
String url = BASE_URI + "/releases/tag/" + tag;
|
||||
String url = "https://github.com/booklore-app/booklore" + "/releases/tag/" + tag;
|
||||
LocalDateTime published = LocalDateTime.parse(release.path("published_at").asText(), DateTimeFormatter.ISO_DATE_TIME);
|
||||
updates.add(new ReleaseNote(tag, release.path("name").asText(tag), release.path("body").asText(""), url, published));
|
||||
}
|
||||
|
||||
+1
@@ -70,6 +70,7 @@ public class AppSettingService {
|
||||
builder.metadataProviderSettings(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.METADATA_PROVIDER_SETTINGS, MetadataProviderSettings.class, settingPersistenceHelper.getDefaultMetadataProviderSettings(), true));
|
||||
builder.metadataMatchWeights(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.METADATA_MATCH_WEIGHTS, MetadataMatchWeights.class, settingPersistenceHelper.getDefaultMetadataMatchWeights(), true));
|
||||
builder.metadataPersistenceSettings(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.METADATA_PERSISTENCE_SETTINGS, MetadataPersistenceSettings.class, settingPersistenceHelper.getDefaultMetadataPersistenceSettings(), true));
|
||||
builder.metadataPublicReviewsSettings(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.METADATA_PUBLIC_REVIEWS_SETTINGS, MetadataPublicReviewsSettings.class, settingPersistenceHelper.getDefaultMetadataPublicReviewsSettings(), true));
|
||||
|
||||
builder.coverResolution(settingPersistenceHelper.getOrCreateSetting(AppSettingKey.COVER_IMAGE_RESOLUTION, "250x350"));
|
||||
builder.autoBookSearch(Boolean.parseBoolean(settingPersistenceHelper.getOrCreateSetting(AppSettingKey.AUTO_BOOK_SEARCH, "true")));
|
||||
|
||||
+21
-4
@@ -1,10 +1,7 @@
|
||||
package com.adityachandel.booklore.service.appsettings;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.request.MetadataRefreshOptions;
|
||||
import com.adityachandel.booklore.model.dto.settings.AppSettingKey;
|
||||
import com.adityachandel.booklore.model.dto.settings.MetadataMatchWeights;
|
||||
import com.adityachandel.booklore.model.dto.settings.MetadataPersistenceSettings;
|
||||
import com.adityachandel.booklore.model.dto.settings.MetadataProviderSettings;
|
||||
import com.adityachandel.booklore.model.dto.settings.*;
|
||||
import com.adityachandel.booklore.model.entity.AppSettingEntity;
|
||||
import com.adityachandel.booklore.model.enums.MetadataProvider;
|
||||
import com.adityachandel.booklore.repository.AppSettingsRepository;
|
||||
@@ -13,7 +10,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -183,4 +182,22 @@ public class SettingPersistenceHelper {
|
||||
.backupCover(false)
|
||||
.build();
|
||||
}
|
||||
|
||||
public MetadataPublicReviewsSettings getDefaultMetadataPublicReviewsSettings() {
|
||||
return MetadataPublicReviewsSettings.builder()
|
||||
.downloadEnabled(true)
|
||||
.providers(Set.of(
|
||||
MetadataPublicReviewsSettings.ReviewProviderConfig.builder()
|
||||
.provider(MetadataProvider.Amazon)
|
||||
.enabled(true)
|
||||
.maxReviews(5)
|
||||
.build(),
|
||||
MetadataPublicReviewsSettings.ReviewProviderConfig.builder()
|
||||
.provider(MetadataProvider.GoodReads)
|
||||
.enabled(false)
|
||||
.maxReviews(5)
|
||||
.build()
|
||||
))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
+20
-23
@@ -4,10 +4,7 @@ import com.adityachandel.booklore.model.MetadataClearFlags;
|
||||
import com.adityachandel.booklore.model.MetadataUpdateWrapper;
|
||||
import com.adityachandel.booklore.model.dto.BookMetadata;
|
||||
import com.adityachandel.booklore.model.dto.settings.MetadataPersistenceSettings;
|
||||
import com.adityachandel.booklore.model.entity.AuthorEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||
import com.adityachandel.booklore.model.entity.CategoryEntity;
|
||||
import com.adityachandel.booklore.model.entity.*;
|
||||
import com.adityachandel.booklore.model.enums.BookFileType;
|
||||
import com.adityachandel.booklore.repository.AuthorRepository;
|
||||
import com.adityachandel.booklore.repository.CategoryRepository;
|
||||
@@ -17,11 +14,11 @@ import com.adityachandel.booklore.service.metadata.backuprestore.MetadataBackupR
|
||||
import com.adityachandel.booklore.service.metadata.backuprestore.MetadataBackupRestoreFactory;
|
||||
import com.adityachandel.booklore.service.metadata.writer.MetadataWriterFactory;
|
||||
import com.adityachandel.booklore.util.FileService;
|
||||
import com.adityachandel.booklore.util.FileUtils;
|
||||
import com.adityachandel.booklore.util.MetadataChangeDetector;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -32,11 +29,8 @@ import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@@ -51,6 +45,7 @@ public class BookMetadataUpdater {
|
||||
private final AppSettingService appSettingService;
|
||||
private final MetadataWriterFactory metadataWriterFactory;
|
||||
private final MetadataBackupRestoreFactory metadataBackupRestoreFactory;
|
||||
private final BookReviewUpdateService bookReviewUpdateService;
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public void setBookMetadata(BookEntity bookEntity, MetadataUpdateWrapper wrapper, boolean setThumbnail, boolean mergeCategories) {
|
||||
@@ -94,6 +89,7 @@ public class BookMetadataUpdater {
|
||||
updateBasicFields(newMetadata, metadata, clearFlags);
|
||||
updateAuthorsIfNeeded(newMetadata, metadata, clearFlags);
|
||||
updateCategoriesIfNeeded(newMetadata, metadata, clearFlags, mergeCategories);
|
||||
bookReviewUpdateService.updateBookReviews(newMetadata, metadata, clearFlags, mergeCategories);
|
||||
updateThumbnailIfNeeded(bookId, newMetadata, metadata, setThumbnail);
|
||||
|
||||
try {
|
||||
@@ -175,30 +171,36 @@ public class BookMetadataUpdater {
|
||||
|
||||
private void updateCategoriesIfNeeded(BookMetadata m, BookMetadataEntity e, MetadataClearFlags clear, boolean merge) {
|
||||
if (Boolean.TRUE.equals(e.getCategoriesLocked())) {
|
||||
// Locked — do nothing
|
||||
} else if (clear.isCategories()) {
|
||||
e.setCategories(Set.of());
|
||||
return;
|
||||
}
|
||||
if (e.getCategories() == null) {
|
||||
e.setCategories(new HashSet<>());
|
||||
}
|
||||
if (clear.isCategories()) {
|
||||
e.getCategories().clear();
|
||||
} else if (shouldUpdateField(false, m.getCategories()) && m.getCategories() != null) {
|
||||
if (merge) {
|
||||
Set<CategoryEntity> existing = new HashSet<>(e.getCategories());
|
||||
Set<CategoryEntity> existing = e.getCategories();
|
||||
for (String name : m.getCategories()) {
|
||||
if (name == null || name.isBlank()) continue;
|
||||
CategoryEntity entity = categoryRepository.findByName(name)
|
||||
.orElseGet(() -> categoryRepository.save(CategoryEntity.builder().name(name).build()));
|
||||
existing.add(entity);
|
||||
}
|
||||
e.setCategories(existing);
|
||||
} else {
|
||||
Set<CategoryEntity> existing = e.getCategories();
|
||||
existing.clear();
|
||||
Set<CategoryEntity> result = m.getCategories().stream()
|
||||
.filter(n -> n != null && !n.isBlank())
|
||||
.map(name -> categoryRepository.findByName(name)
|
||||
.orElseGet(() -> categoryRepository.save(CategoryEntity.builder().name(name).build())))
|
||||
.collect(Collectors.toSet());
|
||||
e.setCategories(result);
|
||||
existing.addAll(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateThumbnailIfNeeded(long bookId, BookMetadata m, BookMetadataEntity e, boolean set) {
|
||||
if (Boolean.TRUE.equals(e.getCoverLocked())) {
|
||||
return; // Locked — do nothing
|
||||
@@ -243,19 +245,14 @@ public class BookMetadataUpdater {
|
||||
Pair.of(m.getHardcoverReviewCountLocked(), e::setHardcoverReviewCountLocked),
|
||||
Pair.of(m.getCoverLocked(), e::setCoverLocked),
|
||||
Pair.of(m.getAuthorsLocked(), e::setAuthorsLocked),
|
||||
Pair.of(m.getCategoriesLocked(), e::setCategoriesLocked)
|
||||
Pair.of(m.getCategoriesLocked(), e::setCategoriesLocked),
|
||||
Pair.of(m.getReviewsLocked(), e::setReviewsLocked)
|
||||
);
|
||||
lockMappings.forEach(pair -> {
|
||||
if (pair.getLeft() != null) pair.getRight().accept(pair.getLeft());
|
||||
});
|
||||
}
|
||||
|
||||
private <T> void updateFieldIfUnlocked(Supplier<Boolean> lock, T value, Consumer<T> setter) {
|
||||
if ((lock.get() == null || !lock.get()) && value != null) {
|
||||
setter.accept(value);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldUpdateField(Boolean locked, Object value) {
|
||||
return (locked == null || !locked) && value != null;
|
||||
}
|
||||
@@ -276,4 +273,4 @@ public class BookMetadataUpdater {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
package com.adityachandel.booklore.service.metadata;
|
||||
|
||||
import com.adityachandel.booklore.model.MetadataClearFlags;
|
||||
import com.adityachandel.booklore.model.dto.BookMetadata;
|
||||
import com.adityachandel.booklore.model.dto.BookReview;
|
||||
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookReviewEntity;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class BookReviewUpdateService {
|
||||
|
||||
public void addReviewsToBook(List<BookReview> bookReviews, BookMetadataEntity e) {
|
||||
BookMetadata tempMetadata = BookMetadata.builder()
|
||||
.bookReviews(bookReviews)
|
||||
.build();
|
||||
MetadataClearFlags clearFlags = new MetadataClearFlags();
|
||||
updateBookReviews(tempMetadata, e, clearFlags, true);
|
||||
}
|
||||
|
||||
public void updateBookReviews(BookMetadata metadata, BookMetadataEntity entity, MetadataClearFlags clearFlags, boolean mergeWithExisting) {
|
||||
if (Boolean.TRUE.equals(entity.getReviewsLocked())) {
|
||||
return;
|
||||
}
|
||||
if (clearFlags.isReviews()) {
|
||||
entity.getReviews().clear();
|
||||
return;
|
||||
}
|
||||
if (!isFieldUpdateAllowed(false, metadata.getBookReviews()) || metadata.getBookReviews() == null) {
|
||||
return;
|
||||
}
|
||||
if (mergeWithExisting) {
|
||||
addReviewsToEntity(metadata.getBookReviews(), entity);
|
||||
} else {
|
||||
replaceReviewsInEntity(metadata.getBookReviews(), entity);
|
||||
}
|
||||
|
||||
applyReviewLimitsAndUpdate(entity);
|
||||
}
|
||||
|
||||
private void addReviewsToEntity(List<BookReview> reviews, BookMetadataEntity entity) {
|
||||
for (var review : reviews) {
|
||||
if (review == null || review.getMetadataProvider() == null) continue;
|
||||
BookReviewEntity reviewEntity = createReviewEntity(review, entity);
|
||||
entity.getReviews().add(reviewEntity);
|
||||
}
|
||||
}
|
||||
|
||||
private void replaceReviewsInEntity(List<BookReview> reviews, BookMetadataEntity entity) {
|
||||
entity.getReviews().clear();
|
||||
Set<BookReviewEntity> newReviews = reviews.stream()
|
||||
.filter(review -> review != null && review.getMetadataProvider() != null)
|
||||
.map(review -> createReviewEntity(review, entity))
|
||||
.collect(Collectors.toSet());
|
||||
entity.getReviews().addAll(newReviews);
|
||||
}
|
||||
|
||||
private BookReviewEntity createReviewEntity(BookReview review, BookMetadataEntity entity) {
|
||||
return BookReviewEntity.builder()
|
||||
.bookMetadata(entity)
|
||||
.metadataProvider(review.getMetadataProvider())
|
||||
.reviewerName(review.getReviewerName())
|
||||
.title(review.getTitle())
|
||||
.rating(review.getRating())
|
||||
.date(review.getDate())
|
||||
.body(review.getBody())
|
||||
.spoiler(review.getSpoiler())
|
||||
.followersCount(review.getFollowersCount())
|
||||
.textReviewsCount(review.getTextReviewsCount())
|
||||
.country(review.getCountry())
|
||||
.build();
|
||||
}
|
||||
|
||||
private void applyReviewLimitsAndUpdate(BookMetadataEntity entity) {
|
||||
Set<BookReviewEntity> limitedReviews = applyReviewLimitsPerProvider(entity.getReviews());
|
||||
entity.getReviews().clear();
|
||||
entity.getReviews().addAll(limitedReviews);
|
||||
}
|
||||
|
||||
private Set<BookReviewEntity> applyReviewLimitsPerProvider(Set<BookReviewEntity> reviews) {
|
||||
return reviews.stream()
|
||||
.collect(Collectors.groupingBy(BookReviewEntity::getMetadataProvider))
|
||||
.entrySet()
|
||||
.stream()
|
||||
.flatMap(entry -> entry.getValue().stream()
|
||||
.sorted(Comparator.comparing(BookReviewEntity::getDate,
|
||||
Comparator.nullsLast(Comparator.reverseOrder())))
|
||||
.limit(5))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private boolean isFieldUpdateAllowed(Boolean isLocked, Object fieldValue) {
|
||||
return (isLocked == null || !isLocked) && fieldValue != null;
|
||||
}
|
||||
}
|
||||
+11
-7
@@ -3,14 +3,12 @@ package com.adityachandel.booklore.service.metadata;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.mapper.BookMapper;
|
||||
import com.adityachandel.booklore.model.MetadataUpdateWrapper;
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.dto.BookMetadata;
|
||||
import com.adityachandel.booklore.model.dto.TaskMessage;
|
||||
import com.adityachandel.booklore.model.dto.MetadataBatchProgressNotification;
|
||||
import com.adityachandel.booklore.model.dto.*;
|
||||
import com.adityachandel.booklore.model.dto.request.FetchMetadataRequest;
|
||||
import com.adityachandel.booklore.model.dto.request.MetadataRefreshOptions;
|
||||
import com.adityachandel.booklore.model.dto.request.MetadataRefreshRequest;
|
||||
import com.adityachandel.booklore.model.dto.settings.AppSettings;
|
||||
import com.adityachandel.booklore.model.dto.settings.MetadataPublicReviewsSettings;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.LibraryEntity;
|
||||
import com.adityachandel.booklore.model.entity.MetadataFetchJobEntity;
|
||||
@@ -171,7 +169,7 @@ public class MetadataRefreshService {
|
||||
));
|
||||
}
|
||||
|
||||
protected Map<MetadataProvider, BookMetadata> fetchMetadataForBook(List<MetadataProvider> providers, BookEntity bookEntity) {
|
||||
public Map<MetadataProvider, BookMetadata> fetchMetadataForBook(List<MetadataProvider> providers, BookEntity bookEntity) {
|
||||
Book book = bookMapper.toBook(bookEntity);
|
||||
return providers.stream()
|
||||
.map(provider -> createInterruptibleMetadataFuture(() -> fetchTopMetadataFromAProvider(provider, book)))
|
||||
@@ -363,6 +361,14 @@ public class MetadataRefreshService {
|
||||
metadata.setDescription(resolveFieldAsString(metadataMap, fieldOptions.getDescription(), BookMetadata::getDescription));
|
||||
metadata.setAuthors(resolveFieldAsList(metadataMap, fieldOptions.getAuthors(), BookMetadata::getAuthors));
|
||||
|
||||
List<BookReview> allReviews = metadataMap.values().stream()
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(md -> Optional.ofNullable(md.getBookReviews()).stream().flatMap(Collection::stream))
|
||||
.collect(Collectors.toList());
|
||||
if (!allReviews.isEmpty()) {
|
||||
metadata.setBookReviews(allReviews);
|
||||
}
|
||||
|
||||
if (metadataMap.containsKey(GoodReads)) {
|
||||
metadata.setGoodreadsId(metadataMap.get(GoodReads).getGoodreadsId());
|
||||
}
|
||||
@@ -376,7 +382,6 @@ public class MetadataRefreshService {
|
||||
metadata.setComicvineId(metadataMap.get(Comicvine).getComicvineId());
|
||||
}
|
||||
|
||||
|
||||
if (request.getRefreshOptions().isMergeCategories()) {
|
||||
metadata.setCategories(getAllCategories(metadataMap, fieldOptions.getCategories(), BookMetadata::getCategories));
|
||||
} else {
|
||||
@@ -400,7 +405,6 @@ public class MetadataRefreshService {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
|
||||
protected void setOtherUnspecifiedMetadata(Map<MetadataProvider, BookMetadata> metadataMap, BookMetadata metadataCombined, MetadataProvider provider) {
|
||||
if (metadataMap.containsKey(provider)) {
|
||||
BookMetadata metadata = metadataMap.get(provider);
|
||||
|
||||
+123
@@ -2,6 +2,7 @@ package com.adityachandel.booklore.service.metadata.parser;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.dto.BookMetadata;
|
||||
import com.adityachandel.booklore.model.dto.BookReview;
|
||||
import com.adityachandel.booklore.model.dto.request.FetchMetadataRequest;
|
||||
import com.adityachandel.booklore.model.enums.MetadataProvider;
|
||||
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
||||
@@ -16,9 +17,14 @@ import org.jsoup.select.Elements;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@@ -147,7 +153,22 @@ public class AmazonBookParser implements BookParser {
|
||||
|
||||
private BookMetadata getBookMetadata(String amazonBookId) {
|
||||
log.info("Amazon: Fetching metadata for: {}", amazonBookId);
|
||||
|
||||
Document doc = fetchDocument(BASE_BOOK_URL + amazonBookId);
|
||||
|
||||
List<BookReview> reviews = appSettingService.getAppSettings()
|
||||
.getMetadataPublicReviewsSettings()
|
||||
.getProviders()
|
||||
.stream()
|
||||
.filter(cfg -> cfg.getProvider() == MetadataProvider.Amazon && cfg.isEnabled())
|
||||
.findFirst()
|
||||
.map(cfg -> getReviews(doc, cfg.getMaxReviews()))
|
||||
.orElse(Collections.emptyList());
|
||||
|
||||
return buildBookMetadata(doc, amazonBookId, reviews);
|
||||
}
|
||||
|
||||
private BookMetadata buildBookMetadata(Document doc, String amazonBookId, List<BookReview> reviews) {
|
||||
return BookMetadata.builder()
|
||||
.provider(MetadataProvider.Amazon)
|
||||
.title(getTitle(doc))
|
||||
@@ -168,6 +189,7 @@ public class AmazonBookParser implements BookParser {
|
||||
.thumbnailUrl(getThumbnail(doc))
|
||||
.amazonRating(getRating(doc))
|
||||
.amazonReviewCount(getReviewCount(doc))
|
||||
.bookReviews(reviews)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -429,6 +451,107 @@ public class AmazonBookParser implements BookParser {
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<BookReview> getReviews(Document doc, int maxReviews) {
|
||||
List<BookReview> reviews = new ArrayList<>();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM d, yyyy", Locale.ENGLISH);
|
||||
|
||||
try {
|
||||
Elements reviewElements = doc.select("li[data-hook=review]");
|
||||
int count = 0;
|
||||
int index = 0;
|
||||
|
||||
while (count < maxReviews && index < reviewElements.size()) {
|
||||
Element reviewElement = reviewElements.get(index);
|
||||
index++;
|
||||
|
||||
Elements reviewerNameElements = reviewElement.select(".a-profile-name");
|
||||
String reviewerName = !reviewerNameElements.isEmpty() ? reviewerNameElements.first().text() : null;
|
||||
|
||||
String title = null;
|
||||
Elements titleElements = reviewElement.select("[data-hook=review-title] span");
|
||||
if (!titleElements.isEmpty()) {
|
||||
title = titleElements.last().text();
|
||||
if (title.isEmpty()) title = null;
|
||||
}
|
||||
|
||||
Float ratingValue = null;
|
||||
Elements ratingElements = reviewElement.select("[data-hook=review-star-rating] .a-icon-alt");
|
||||
String ratingText = !ratingElements.isEmpty() ? ratingElements.first().text() : "";
|
||||
if (!ratingText.isEmpty()) {
|
||||
try {
|
||||
Pattern ratingPattern = Pattern.compile("^([0-9]+(\\.[0-9]+)?)");
|
||||
Matcher ratingMatcher = ratingPattern.matcher(ratingText);
|
||||
if (ratingMatcher.find()) {
|
||||
ratingValue = Float.parseFloat(ratingMatcher.group(1));
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("Failed to parse rating '{}': {}", ratingText, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Elements fullDateElements = reviewElement.select("[data-hook=review-date]");
|
||||
String fullDateText = !fullDateElements.isEmpty() ? fullDateElements.first().text() : "";
|
||||
String country = null;
|
||||
Instant dateInstant = null;
|
||||
|
||||
if (!fullDateText.isEmpty()) {
|
||||
try {
|
||||
Pattern pattern = Pattern.compile("Reviewed in (.+?) on (.+)");
|
||||
Matcher matcher = pattern.matcher(fullDateText);
|
||||
String datePart = fullDateText;
|
||||
|
||||
if (matcher.find() && matcher.groupCount() == 2) {
|
||||
country = matcher.group(1).trim();
|
||||
if (country.toLowerCase().startsWith("the ")) {
|
||||
country = country.substring(4).trim();
|
||||
}
|
||||
datePart = matcher.group(2).trim();
|
||||
}
|
||||
|
||||
LocalDate localDate = LocalDate.parse(datePart, formatter);
|
||||
dateInstant = localDate.atStartOfDay(ZoneOffset.UTC).toInstant();
|
||||
|
||||
} catch (DateTimeParseException e) {
|
||||
log.warn("Failed to parse date '{}' in review: {}", fullDateText, e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.warn("Error parsing date string '{}': {}", fullDateText, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Elements bodyElements = reviewElement.select("[data-hook=review-body]");
|
||||
String body = !bodyElements.isEmpty() ? Objects.requireNonNull(bodyElements.first()).text() : null;
|
||||
if (body != null && body.isEmpty()) {
|
||||
body = null;
|
||||
} else if (body != null) {
|
||||
String toRemove = " Read more";
|
||||
int lastIndex = body.lastIndexOf(toRemove);
|
||||
if (lastIndex != -1) {
|
||||
body = body.substring(0, lastIndex) + body.substring(lastIndex + toRemove.length());
|
||||
}
|
||||
}
|
||||
|
||||
if (body == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
reviews.add(BookReview.builder()
|
||||
.metadataProvider(MetadataProvider.Amazon)
|
||||
.reviewerName(reviewerName != null ? reviewerName.trim() : null)
|
||||
.title(title != null ? title.trim() : null)
|
||||
.rating(ratingValue)
|
||||
.country(country != null ? country.trim() : null)
|
||||
.date(dateInstant)
|
||||
.body(body.trim())
|
||||
.build());
|
||||
|
||||
count++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to parse reviews: {}", e.getMessage());
|
||||
}
|
||||
return reviews;
|
||||
}
|
||||
|
||||
private Integer getReviewCount(Document doc) {
|
||||
try {
|
||||
Element reviewDiv = doc.select("div#averageCustomerReviews_feature_div").first();
|
||||
|
||||
+89
-2
@@ -2,9 +2,12 @@ package com.adityachandel.booklore.service.metadata.parser;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.dto.BookMetadata;
|
||||
import com.adityachandel.booklore.model.dto.BookReview;
|
||||
import com.adityachandel.booklore.model.dto.request.FetchMetadataRequest;
|
||||
import com.adityachandel.booklore.model.enums.MetadataProvider;
|
||||
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
||||
import com.adityachandel.booklore.util.BookUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.text.similarity.FuzzyScore;
|
||||
import org.jsoup.Connection;
|
||||
@@ -29,11 +32,13 @@ import java.util.regex.Pattern;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class GoodReadsParser implements BookParser {
|
||||
|
||||
private static final String BASE_SEARCH_URL = "https://www.goodreads.com/search?q=";
|
||||
private static final String BASE_BOOK_URL = "https://www.goodreads.com/book/show/";
|
||||
private static final int COUNT_DETAILED_METADATA_TO_GET = 3;
|
||||
private final AppSettingService appSettingService;
|
||||
|
||||
@Override
|
||||
public BookMetadata fetchTopMetadata(Book book, FetchMetadataRequest fetchMetadataRequest) {
|
||||
@@ -72,8 +77,10 @@ public class GoodReadsParser implements BookParser {
|
||||
}
|
||||
|
||||
private BookMetadata parseBookDetails(Document document, String goodreadsId) {
|
||||
BookMetadata.BookMetadataBuilder builder = BookMetadata.builder().goodreadsId(goodreadsId);
|
||||
builder.provider(MetadataProvider.GoodReads);
|
||||
BookMetadata.BookMetadataBuilder builder = BookMetadata.builder()
|
||||
.goodreadsId(goodreadsId)
|
||||
.provider(MetadataProvider.GoodReads);
|
||||
|
||||
try {
|
||||
JSONObject apolloStateJson = getJson(document)
|
||||
.getJSONObject("props")
|
||||
@@ -86,6 +93,15 @@ public class GoodReadsParser implements BookParser {
|
||||
extractSeriesDetails(apolloStateJson, keySet, builder);
|
||||
extractBookDetails(apolloStateJson, keySet, builder);
|
||||
extractWorkDetails(apolloStateJson, keySet, builder);
|
||||
|
||||
appSettingService.getAppSettings()
|
||||
.getMetadataPublicReviewsSettings()
|
||||
.getProviders()
|
||||
.stream()
|
||||
.filter(cfg -> cfg.getProvider() == MetadataProvider.GoodReads && cfg.isEnabled())
|
||||
.findFirst()
|
||||
.ifPresent(cfg -> extractReviews(apolloStateJson, keySet, builder, cfg.getMaxReviews()));
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Error parsing book details for providerBookId: {}", goodreadsId, e);
|
||||
return null;
|
||||
@@ -104,6 +120,77 @@ public class GoodReadsParser implements BookParser {
|
||||
}
|
||||
}
|
||||
|
||||
private void extractReviews(JSONObject apolloStateJson, LinkedHashSet<String> keySet, BookMetadata.BookMetadataBuilder builder, int maxReviews) {
|
||||
List<String> allReviewKeys = findKeysByPrefixAll(keySet, "Review:kca");
|
||||
List<BookReview> reviews = new ArrayList<>();
|
||||
|
||||
int count = 0;
|
||||
int index = 0;
|
||||
|
||||
while (count < maxReviews && index < allReviewKeys.size()) {
|
||||
String reviewKey = allReviewKeys.get(index);
|
||||
index++;
|
||||
try {
|
||||
JSONObject reviewJson = apolloStateJson.getJSONObject(reviewKey);
|
||||
String creatorRef = reviewJson.getJSONObject("creator").getString("__ref");
|
||||
JSONObject userJson = apolloStateJson.optJSONObject(creatorRef);
|
||||
|
||||
String reviewerName = null;
|
||||
Integer followersCount = null;
|
||||
Integer textReviewsCount = null;
|
||||
if (userJson != null) {
|
||||
reviewerName = userJson.optString("name", null);
|
||||
followersCount = userJson.has("followersCount") ? userJson.optInt("followersCount") : null;
|
||||
textReviewsCount = userJson.has("textReviewsCount") ? userJson.optInt("textReviewsCount") : null;
|
||||
}
|
||||
|
||||
String rawBody = reviewJson.optString("text", null);
|
||||
String plainBody = rawBody != null ? Jsoup.parse(rawBody).text() : null;
|
||||
|
||||
if (plainBody == null || plainBody.trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BookReview review = BookReview.builder()
|
||||
.metadataProvider(MetadataProvider.GoodReads)
|
||||
.date(parseEpochMillis(String.valueOf(reviewJson.getLong("updatedAt"))))
|
||||
.body(plainBody.trim())
|
||||
.rating(Float.valueOf(reviewJson.optString("rating", null)))
|
||||
.spoiler(reviewJson.optBoolean("spoilerStatus", false))
|
||||
.reviewerName(reviewerName != null ? reviewerName.trim() : null)
|
||||
.followersCount(followersCount)
|
||||
.textReviewsCount(textReviewsCount)
|
||||
.build();
|
||||
reviews.add(review);
|
||||
count++;
|
||||
} catch (Exception e) {
|
||||
log.error("Error fetching review: {}, Error: {}", reviewKey, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
builder.bookReviews(reviews);
|
||||
}
|
||||
|
||||
private Instant parseEpochMillis(String millisString) {
|
||||
try {
|
||||
long millis = Long.parseLong(millisString);
|
||||
return Instant.ofEpochMilli(millis);
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("Invalid epoch millis: {}", millisString, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> findKeysByPrefixAll(LinkedHashSet<String> keySet, String prefix) {
|
||||
List<String> matchingKeys = new ArrayList<>();
|
||||
for (String key : keySet) {
|
||||
if (key.startsWith(prefix)) {
|
||||
matchingKeys.add(key);
|
||||
}
|
||||
}
|
||||
return matchingKeys;
|
||||
}
|
||||
|
||||
private void extractSeriesDetails(JSONObject apolloStateJson, LinkedHashSet<String> keySet, BookMetadata.BookMetadataBuilder builder) {
|
||||
String seriesKey = findKeyByPrefix(keySet, "Series:kca");
|
||||
if (seriesKey != null) {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
CREATE TABLE IF NOT EXISTS public_book_review
|
||||
(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
metadata_provider VARCHAR(255) NOT NULL,
|
||||
book_id BIGINT NOT NULL,
|
||||
reviewer_name VARCHAR(512),
|
||||
title VARCHAR(512),
|
||||
rating FLOAT,
|
||||
date TIMESTAMP,
|
||||
body TEXT,
|
||||
country VARCHAR(255),
|
||||
spoiler BOOLEAN,
|
||||
followers_count INT,
|
||||
text_reviews_count INT,
|
||||
PRIMARY KEY (id),
|
||||
FOREIGN KEY (book_id) REFERENCES book_metadata (book_id) ON DELETE CASCADE
|
||||
);
|
||||
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE book_metadata
|
||||
ADD COLUMN IF NOT EXISTS reviews_locked BOOLEAN DEFAULT FALSE;
|
||||
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE book_metadata
|
||||
MODIFY hardcover_id VARCHAR(512);
|
||||
@@ -0,0 +1,16 @@
|
||||
CREATE TABLE book_notes
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id BIGINT NOT NULL,
|
||||
book_id BIGINT NOT NULL,
|
||||
title VARCHAR(255),
|
||||
content TEXT NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT fk_book_notes_user_id FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_book_notes_book_id FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX idx_book_notes_user_id ON book_notes (user_id);
|
||||
CREATE INDEX idx_book_notes_book_id ON book_notes (book_id);
|
||||
+187
@@ -0,0 +1,187 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
|
||||
import com.adityachandel.booklore.config.security.AuthenticationService;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.mapper.BookNoteMapper;
|
||||
import com.adityachandel.booklore.model.dto.BookLoreUser;
|
||||
import com.adityachandel.booklore.model.dto.BookNote;
|
||||
import com.adityachandel.booklore.model.dto.CreateBookNoteRequest;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookLoreUserEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookNoteEntity;
|
||||
import com.adityachandel.booklore.repository.BookNoteRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.repository.UserRepository;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class BookNoteServiceTest {
|
||||
|
||||
private BookNoteRepository bookNoteRepository;
|
||||
private BookRepository bookRepository;
|
||||
private UserRepository userRepository;
|
||||
private BookNoteMapper mapper;
|
||||
private BookNoteService service;
|
||||
|
||||
private final Long userId = 1L;
|
||||
private final Long bookId = 2L;
|
||||
private final Long noteId = 3L;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
bookNoteRepository = mock(BookNoteRepository.class);
|
||||
bookRepository = mock(BookRepository.class);
|
||||
userRepository = mock(UserRepository.class);
|
||||
mapper = mock(BookNoteMapper.class);
|
||||
AuthenticationService authenticationService = mock(AuthenticationService.class);
|
||||
service = new BookNoteService(bookNoteRepository, bookRepository, userRepository, mapper, authenticationService);
|
||||
|
||||
BookLoreUser user = new BookLoreUser();
|
||||
user.setId(userId);
|
||||
when(authenticationService.getAuthenticatedUser()).thenReturn(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getNotesForBook_returnsMappedNotes() {
|
||||
BookNoteEntity entity = BookNoteEntity.builder().id(noteId).build();
|
||||
BookNote dto = BookNote.builder().id(noteId).build();
|
||||
when(bookNoteRepository.findByBookIdAndUserIdOrderByUpdatedAtDesc(bookId, userId))
|
||||
.thenReturn(Collections.singletonList(entity));
|
||||
when(mapper.toDto(entity)).thenReturn(dto);
|
||||
|
||||
List<BookNote> result = service.getNotesForBook(bookId);
|
||||
|
||||
assertEquals(1, result.size());
|
||||
assertEquals(noteId, result.getFirst().getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createOrUpdateNote_createsNewNote_whenIdIsNull() {
|
||||
CreateBookNoteRequest req = CreateBookNoteRequest.builder()
|
||||
.bookId(bookId)
|
||||
.title("t")
|
||||
.content("c")
|
||||
.build();
|
||||
|
||||
BookEntity book = BookEntity.builder().id(bookId).build();
|
||||
BookLoreUserEntity userEntity = BookLoreUserEntity.builder().id(userId).build();
|
||||
BookNoteEntity savedEntity = BookNoteEntity.builder().id(noteId).build();
|
||||
BookNote dto = BookNote.builder().id(noteId).build();
|
||||
|
||||
when(bookRepository.findById(bookId)).thenReturn(Optional.of(book));
|
||||
when(userRepository.findById(userId)).thenReturn(Optional.of(userEntity));
|
||||
when(bookNoteRepository.save(any(BookNoteEntity.class))).thenReturn(savedEntity);
|
||||
when(mapper.toDto(savedEntity)).thenReturn(dto);
|
||||
|
||||
BookNote result = service.createOrUpdateNote(req);
|
||||
|
||||
assertEquals(noteId, result.getId());
|
||||
ArgumentCaptor<BookNoteEntity> captor = ArgumentCaptor.forClass(BookNoteEntity.class);
|
||||
verify(bookNoteRepository).save(captor.capture());
|
||||
BookNoteEntity entity = captor.getValue();
|
||||
assertEquals(book, entity.getBook());
|
||||
assertEquals(userEntity, entity.getUser());
|
||||
assertEquals("t", entity.getTitle());
|
||||
assertEquals("c", entity.getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createOrUpdateNote_updatesExistingNote_whenIdIsPresent() {
|
||||
CreateBookNoteRequest req = CreateBookNoteRequest.builder()
|
||||
.id(noteId)
|
||||
.bookId(bookId)
|
||||
.title("new title")
|
||||
.content("new content")
|
||||
.build();
|
||||
|
||||
BookNoteEntity existing = BookNoteEntity.builder().id(noteId).title("old").content("old").build();
|
||||
BookNoteEntity saved = BookNoteEntity.builder().id(noteId).title("new title").content("new content").build();
|
||||
BookNote dto = BookNote.builder().id(noteId).title("new title").content("new content").build();
|
||||
|
||||
when(bookRepository.findById(bookId)).thenReturn(Optional.of(BookEntity.builder().id(bookId).build()));
|
||||
when(userRepository.findById(userId)).thenReturn(Optional.of(BookLoreUserEntity.builder().id(userId).build()));
|
||||
when(bookNoteRepository.findByIdAndUserId(noteId, userId)).thenReturn(Optional.of(existing));
|
||||
when(bookNoteRepository.save(existing)).thenReturn(saved);
|
||||
when(mapper.toDto(saved)).thenReturn(dto);
|
||||
|
||||
BookNote result = service.createOrUpdateNote(req);
|
||||
|
||||
assertEquals(noteId, result.getId());
|
||||
assertEquals("new title", existing.getTitle());
|
||||
assertEquals("new content", existing.getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createOrUpdateNote_throwsIfBookNotFound() {
|
||||
CreateBookNoteRequest req = CreateBookNoteRequest.builder()
|
||||
.bookId(bookId)
|
||||
.title("t")
|
||||
.content("c")
|
||||
.build();
|
||||
|
||||
when(bookRepository.findById(bookId)).thenReturn(Optional.empty());
|
||||
|
||||
RuntimeException ex = assertThrows(RuntimeException.class, () -> service.createOrUpdateNote(req));
|
||||
|
||||
assertTrue(
|
||||
ex.getMessage().contains("BOOK_NOT_FOUND") || ex.getMessage().contains(String.valueOf(bookId)),
|
||||
"Exception message should contain 'BOOK_NOT_FOUND' or the book id"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createOrUpdateNote_throwsIfUserNotFound() {
|
||||
CreateBookNoteRequest req = CreateBookNoteRequest.builder()
|
||||
.bookId(bookId)
|
||||
.title("t")
|
||||
.content("c")
|
||||
.build();
|
||||
|
||||
when(bookRepository.findById(bookId)).thenReturn(Optional.of(BookEntity.builder().id(bookId).build()));
|
||||
when(userRepository.findById(userId)).thenReturn(Optional.empty());
|
||||
|
||||
assertThrows(EntityNotFoundException.class, () -> service.createOrUpdateNote(req));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createOrUpdateNote_throwsIfNoteNotFoundForUpdate() {
|
||||
CreateBookNoteRequest req = CreateBookNoteRequest.builder()
|
||||
.id(noteId)
|
||||
.bookId(bookId)
|
||||
.title("t")
|
||||
.content("c")
|
||||
.build();
|
||||
|
||||
when(bookRepository.findById(bookId)).thenReturn(Optional.of(BookEntity.builder().id(bookId).build()));
|
||||
when(userRepository.findById(userId)).thenReturn(Optional.of(BookLoreUserEntity.builder().id(userId).build()));
|
||||
when(bookNoteRepository.findByIdAndUserId(noteId, userId)).thenReturn(Optional.empty());
|
||||
|
||||
assertThrows(EntityNotFoundException.class, () -> service.createOrUpdateNote(req));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteNote_deletesIfExists() {
|
||||
BookNoteEntity entity = BookNoteEntity.builder().id(noteId).build();
|
||||
when(bookNoteRepository.findByIdAndUserId(noteId, userId)).thenReturn(Optional.of(entity));
|
||||
|
||||
service.deleteNote(noteId);
|
||||
|
||||
verify(bookNoteRepository).delete(entity);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteNote_throwsIfNotFound() {
|
||||
when(bookNoteRepository.findByIdAndUserId(noteId, userId)).thenReturn(Optional.empty());
|
||||
assertThrows(EntityNotFoundException.class, () -> service.deleteNote(noteId));
|
||||
}
|
||||
}
|
||||
+369
@@ -0,0 +1,369 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
|
||||
import com.adityachandel.booklore.config.security.AuthenticationService;
|
||||
import com.adityachandel.booklore.mapper.BookReviewMapper;
|
||||
import com.adityachandel.booklore.model.dto.BookLoreUser;
|
||||
import com.adityachandel.booklore.model.dto.BookMetadata;
|
||||
import com.adityachandel.booklore.model.dto.BookReview;
|
||||
import com.adityachandel.booklore.model.dto.settings.AppSettings;
|
||||
import com.adityachandel.booklore.model.dto.settings.MetadataPublicReviewsSettings;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookReviewEntity;
|
||||
import com.adityachandel.booklore.model.enums.MetadataProvider;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.repository.BookReviewRepository;
|
||||
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
||||
import com.adityachandel.booklore.service.metadata.BookReviewUpdateService;
|
||||
import com.adityachandel.booklore.service.metadata.MetadataRefreshService;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class BookReviewServiceTest {
|
||||
|
||||
@Mock
|
||||
private BookReviewRepository bookReviewRepository;
|
||||
@Mock
|
||||
private BookReviewMapper mapper;
|
||||
@Mock
|
||||
private BookReviewUpdateService bookReviewUpdateService;
|
||||
@Mock
|
||||
private BookRepository bookRepository;
|
||||
@Mock
|
||||
private AppSettingService appSettingService;
|
||||
@Mock
|
||||
private MetadataRefreshService metadataRefreshService;
|
||||
@Mock
|
||||
private AuthenticationService authenticationService;
|
||||
|
||||
private BookReviewService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new BookReviewService(
|
||||
bookReviewRepository,
|
||||
mapper,
|
||||
bookReviewUpdateService,
|
||||
bookRepository,
|
||||
appSettingService,
|
||||
metadataRefreshService,
|
||||
authenticationService
|
||||
);
|
||||
}
|
||||
|
||||
private BookReview createBookReview(MetadataProvider provider) {
|
||||
return BookReview.builder()
|
||||
.metadataProvider(provider)
|
||||
.reviewerName("Test Reviewer")
|
||||
.title("Great Book")
|
||||
.rating(4.5f)
|
||||
.date(Instant.now())
|
||||
.body("Excellent read")
|
||||
.build();
|
||||
}
|
||||
|
||||
private BookReviewEntity createBookReviewEntity(MetadataProvider provider) {
|
||||
return BookReviewEntity.builder()
|
||||
.metadataProvider(provider)
|
||||
.reviewerName("Test Reviewer")
|
||||
.title("Great Book")
|
||||
.rating(4.5f)
|
||||
.date(Instant.now())
|
||||
.body("Excellent read")
|
||||
.build();
|
||||
}
|
||||
|
||||
private BookLoreUser createUser(boolean isAdmin, boolean canManipulateLibrary) {
|
||||
BookLoreUser.UserPermissions permissions = new BookLoreUser.UserPermissions();
|
||||
permissions.setAdmin(isAdmin);
|
||||
permissions.setCanManipulateLibrary(canManipulateLibrary);
|
||||
|
||||
BookLoreUser user = new BookLoreUser();
|
||||
user.setPermissions(permissions);
|
||||
return user;
|
||||
}
|
||||
|
||||
private MetadataPublicReviewsSettings createReviewSettings(boolean enabled, MetadataProvider... providers) {
|
||||
Set<MetadataPublicReviewsSettings.ReviewProviderConfig> configs = new HashSet<>();
|
||||
for (MetadataProvider provider : providers) {
|
||||
MetadataPublicReviewsSettings.ReviewProviderConfig config =
|
||||
MetadataPublicReviewsSettings.ReviewProviderConfig.builder()
|
||||
.provider(provider)
|
||||
.enabled(true)
|
||||
.build();
|
||||
configs.add(config);
|
||||
}
|
||||
|
||||
return MetadataPublicReviewsSettings.builder()
|
||||
.downloadEnabled(enabled)
|
||||
.providers(configs)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getByBookId_returnsExistingReviews_whenReviewsExist() {
|
||||
Long bookId = 1L;
|
||||
BookReviewEntity entity = createBookReviewEntity(MetadataProvider.Amazon);
|
||||
BookReview dto = createBookReview(MetadataProvider.Amazon);
|
||||
AppSettings appSettings = new AppSettings();
|
||||
appSettings.setMetadataPublicReviewsSettings(createReviewSettings(true));
|
||||
|
||||
when(bookReviewRepository.findByBookMetadataBookId(bookId))
|
||||
.thenReturn(Collections.singletonList(entity));
|
||||
when(mapper.toDto(entity)).thenReturn(dto);
|
||||
when(appSettingService.getAppSettings()).thenReturn(appSettings);
|
||||
|
||||
List<BookReview> result = service.getByBookId(bookId);
|
||||
|
||||
assertEquals(1, result.size());
|
||||
assertEquals(dto, result.getFirst());
|
||||
verify(metadataRefreshService, never()).fetchMetadataForBook(anyList(), any(BookEntity.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getByBookId_returnsEmptyList_whenDownloadDisabled() {
|
||||
Long bookId = 1L;
|
||||
AppSettings appSettings = new AppSettings();
|
||||
appSettings.setMetadataPublicReviewsSettings(createReviewSettings(false));
|
||||
|
||||
when(bookReviewRepository.findByBookMetadataBookId(bookId))
|
||||
.thenReturn(Collections.emptyList());
|
||||
when(appSettingService.getAppSettings()).thenReturn(appSettings);
|
||||
|
||||
List<BookReview> result = service.getByBookId(bookId);
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
verify(metadataRefreshService, never()).fetchMetadataForBook(anyList(), any(BookEntity.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getByBookId_returnsEmptyList_whenUserLacksPermissions() {
|
||||
Long bookId = 1L;
|
||||
AppSettings appSettings = new AppSettings();
|
||||
appSettings.setMetadataPublicReviewsSettings(createReviewSettings(true, MetadataProvider.Amazon));
|
||||
BookLoreUser user = createUser(false, false);
|
||||
|
||||
when(bookReviewRepository.findByBookMetadataBookId(bookId))
|
||||
.thenReturn(Collections.emptyList());
|
||||
when(appSettingService.getAppSettings()).thenReturn(appSettings);
|
||||
when(authenticationService.getAuthenticatedUser()).thenReturn(user);
|
||||
|
||||
List<BookReview> result = service.getByBookId(bookId);
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
verify(metadataRefreshService, never()).fetchMetadataForBook(anyList(), any(BookEntity.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getByBookId_fetchesAndSavesReviews_whenAdminUserAndNoExistingReviews() {
|
||||
Long bookId = 1L;
|
||||
AppSettings appSettings = new AppSettings();
|
||||
appSettings.setMetadataPublicReviewsSettings(createReviewSettings(true, MetadataProvider.Amazon));
|
||||
BookLoreUser user = createUser(true, false);
|
||||
BookEntity bookEntity = new BookEntity();
|
||||
bookEntity.setMetadata(new BookMetadataEntity());
|
||||
BookReview freshReview = createBookReview(MetadataProvider.Amazon);
|
||||
BookReviewEntity savedEntity = createBookReviewEntity(MetadataProvider.Amazon);
|
||||
|
||||
when(bookReviewRepository.findByBookMetadataBookId(bookId))
|
||||
.thenReturn(Collections.emptyList())
|
||||
.thenReturn(Collections.singletonList(savedEntity));
|
||||
when(appSettingService.getAppSettings()).thenReturn(appSettings);
|
||||
when(authenticationService.getAuthenticatedUser()).thenReturn(user);
|
||||
when(bookRepository.findById(bookId)).thenReturn(Optional.of(bookEntity));
|
||||
when(mapper.toDto(savedEntity)).thenReturn(freshReview);
|
||||
|
||||
Map<MetadataProvider, BookMetadata> metadataMap = new HashMap<>();
|
||||
metadataMap.put(MetadataProvider.Amazon, BookMetadata.builder()
|
||||
.bookReviews(Collections.singletonList(freshReview))
|
||||
.build());
|
||||
when(metadataRefreshService.fetchMetadataForBook(
|
||||
eq(Collections.singletonList(MetadataProvider.Amazon)), eq(bookEntity)))
|
||||
.thenReturn(metadataMap);
|
||||
|
||||
List<BookReview> result = service.getByBookId(bookId);
|
||||
|
||||
assertEquals(1, result.size());
|
||||
assertEquals(freshReview, result.get(0));
|
||||
verify(bookReviewUpdateService).addReviewsToBook(
|
||||
Collections.singletonList(freshReview), bookEntity.getMetadata());
|
||||
verify(bookRepository).save(bookEntity);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getByBookId_fetchesAndSavesReviews_whenLibraryManipulatorAndNoExistingReviews() {
|
||||
Long bookId = 1L;
|
||||
AppSettings appSettings = new AppSettings();
|
||||
appSettings.setMetadataPublicReviewsSettings(createReviewSettings(true, MetadataProvider.GoodReads));
|
||||
BookLoreUser user = createUser(false, true);
|
||||
BookEntity bookEntity = new BookEntity();
|
||||
bookEntity.setMetadata(new BookMetadataEntity());
|
||||
BookReview freshReview = createBookReview(MetadataProvider.GoodReads);
|
||||
BookReviewEntity savedEntity = createBookReviewEntity(MetadataProvider.GoodReads);
|
||||
|
||||
when(bookReviewRepository.findByBookMetadataBookId(bookId))
|
||||
.thenReturn(Collections.emptyList())
|
||||
.thenReturn(Collections.singletonList(savedEntity));
|
||||
when(appSettingService.getAppSettings()).thenReturn(appSettings);
|
||||
when(authenticationService.getAuthenticatedUser()).thenReturn(user);
|
||||
when(bookRepository.findById(bookId)).thenReturn(Optional.of(bookEntity));
|
||||
when(mapper.toDto(savedEntity)).thenReturn(freshReview);
|
||||
|
||||
Map<MetadataProvider, BookMetadata> metadataMap = new HashMap<>();
|
||||
metadataMap.put(MetadataProvider.GoodReads, BookMetadata.builder()
|
||||
.bookReviews(Collections.singletonList(freshReview))
|
||||
.build());
|
||||
when(metadataRefreshService.fetchMetadataForBook(
|
||||
eq(Collections.singletonList(MetadataProvider.GoodReads)), eq(bookEntity)))
|
||||
.thenReturn(metadataMap);
|
||||
|
||||
List<BookReview> result = service.getByBookId(bookId);
|
||||
|
||||
assertEquals(1, result.size());
|
||||
verify(bookReviewUpdateService).addReviewsToBook(anyList(), any());
|
||||
verify(bookRepository).save(bookEntity);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getByBookId_throwsException_whenBookNotFound() {
|
||||
Long bookId = 1L;
|
||||
AppSettings appSettings = new AppSettings();
|
||||
appSettings.setMetadataPublicReviewsSettings(createReviewSettings(true, MetadataProvider.Amazon));
|
||||
BookLoreUser user = createUser(true, false);
|
||||
|
||||
when(bookReviewRepository.findByBookMetadataBookId(bookId))
|
||||
.thenReturn(Collections.emptyList());
|
||||
when(appSettingService.getAppSettings()).thenReturn(appSettings);
|
||||
when(authenticationService.getAuthenticatedUser()).thenReturn(user);
|
||||
when(bookRepository.findById(bookId)).thenReturn(Optional.empty());
|
||||
|
||||
RuntimeException exception = assertThrows(RuntimeException.class,
|
||||
() -> service.getByBookId(bookId));
|
||||
|
||||
assertNotNull(exception);
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchBookReviews_returnsEmptyList_whenDownloadDisabled() {
|
||||
BookEntity bookEntity = new BookEntity();
|
||||
AppSettings appSettings = new AppSettings();
|
||||
appSettings.setMetadataPublicReviewsSettings(createReviewSettings(false));
|
||||
|
||||
when(appSettingService.getAppSettings()).thenReturn(appSettings);
|
||||
|
||||
List<BookReview> result = service.fetchBookReviews(bookEntity);
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
verify(metadataRefreshService, never()).fetchMetadataForBook(anyList(), any(BookEntity.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchBookReviews_filtersEnabledProviders() {
|
||||
BookEntity bookEntity = new BookEntity();
|
||||
MetadataPublicReviewsSettings settings = createReviewSettings(true,
|
||||
MetadataProvider.Amazon, MetadataProvider.GoodReads);
|
||||
|
||||
// Disable GoodReads
|
||||
settings.getProviders().stream()
|
||||
.filter(config -> config.getProvider() == MetadataProvider.GoodReads)
|
||||
.findFirst()
|
||||
.ifPresent(config -> config.setEnabled(false));
|
||||
|
||||
AppSettings appSettings = new AppSettings();
|
||||
appSettings.setMetadataPublicReviewsSettings(settings);
|
||||
|
||||
when(appSettingService.getAppSettings()).thenReturn(appSettings);
|
||||
when(metadataRefreshService.fetchMetadataForBook(anyList(), any(BookEntity.class)))
|
||||
.thenReturn(Collections.emptyMap());
|
||||
|
||||
service.fetchBookReviews(bookEntity);
|
||||
|
||||
verify(metadataRefreshService).fetchMetadataForBook(
|
||||
eq(Collections.singletonList(MetadataProvider.Amazon)), eq(bookEntity));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchBookReviews_aggregatesReviewsFromMultipleProviders() {
|
||||
BookEntity bookEntity = new BookEntity();
|
||||
AppSettings appSettings = new AppSettings();
|
||||
appSettings.setMetadataPublicReviewsSettings(createReviewSettings(true,
|
||||
MetadataProvider.Amazon, MetadataProvider.GoodReads));
|
||||
|
||||
BookReview amazonReview = createBookReview(MetadataProvider.Amazon);
|
||||
BookReview goodreadsReview = createBookReview(MetadataProvider.GoodReads);
|
||||
|
||||
Map<MetadataProvider, BookMetadata> metadataMap = new HashMap<>();
|
||||
metadataMap.put(MetadataProvider.Amazon, BookMetadata.builder()
|
||||
.bookReviews(Collections.singletonList(amazonReview))
|
||||
.build());
|
||||
metadataMap.put(MetadataProvider.GoodReads, BookMetadata.builder()
|
||||
.bookReviews(Collections.singletonList(goodreadsReview))
|
||||
.build());
|
||||
|
||||
when(appSettingService.getAppSettings()).thenReturn(appSettings);
|
||||
when(metadataRefreshService.fetchMetadataForBook(anyList(), any(BookEntity.class)))
|
||||
.thenReturn(metadataMap);
|
||||
|
||||
List<BookReview> result = service.fetchBookReviews(bookEntity);
|
||||
|
||||
assertEquals(2, result.size());
|
||||
assertTrue(result.contains(amazonReview));
|
||||
assertTrue(result.contains(goodreadsReview));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchBookReviews_skipsMetadataWithNullReviews() {
|
||||
BookEntity bookEntity = new BookEntity();
|
||||
AppSettings appSettings = new AppSettings();
|
||||
appSettings.setMetadataPublicReviewsSettings(createReviewSettings(true, MetadataProvider.Amazon));
|
||||
|
||||
Map<MetadataProvider, BookMetadata> metadataMap = new HashMap<>();
|
||||
metadataMap.put(MetadataProvider.Amazon, BookMetadata.builder()
|
||||
.bookReviews(null)
|
||||
.build());
|
||||
|
||||
when(appSettingService.getAppSettings()).thenReturn(appSettings);
|
||||
when(metadataRefreshService.fetchMetadataForBook(anyList(), any(BookEntity.class)))
|
||||
.thenReturn(metadataMap);
|
||||
|
||||
List<BookReview> result = service.fetchBookReviews(bookEntity);
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_removesReview_whenReviewExists() {
|
||||
Long reviewId = 1L;
|
||||
|
||||
when(bookReviewRepository.existsById(reviewId)).thenReturn(true);
|
||||
|
||||
service.delete(reviewId);
|
||||
|
||||
verify(bookReviewRepository).deleteById(reviewId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_throwsException_whenReviewNotFound() {
|
||||
Long reviewId = 1L;
|
||||
|
||||
when(bookReviewRepository.existsById(reviewId)).thenReturn(false);
|
||||
|
||||
EntityNotFoundException exception = assertThrows(EntityNotFoundException.class,
|
||||
() -> service.delete(reviewId));
|
||||
|
||||
assertEquals("Review not found: " + reviewId, exception.getMessage());
|
||||
verify(bookReviewRepository, never()).deleteById(reviewId);
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -1,8 +1,10 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
|
||||
import com.adityachandel.booklore.exception.APIException;
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.dto.BookMetadata;
|
||||
import com.adityachandel.booklore.model.dto.settings.AppSettings;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookdropFileEntity;
|
||||
import com.adityachandel.booklore.model.enums.MetadataProvider;
|
||||
import com.adityachandel.booklore.repository.BookdropFileRepository;
|
||||
@@ -17,6 +19,7 @@ import com.adityachandel.booklore.util.ImageUtils;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -104,7 +107,7 @@ class BookdropMetadataServiceTest {
|
||||
when(appSettingService.getAppSettings()).thenReturn(settings);
|
||||
when(metadataRefreshService.prepareProviders(any())).thenReturn(List.of());
|
||||
when(objectMapper.readValue(sampleFile.getOriginalMetadata(), BookMetadata.class)).thenReturn(fetched);
|
||||
when(metadataRefreshService.fetchMetadataForBook(any(), any())).thenReturn(Map.of());
|
||||
when(metadataRefreshService.fetchMetadataForBook(any(), any(Book.class))).thenReturn(Map.of());
|
||||
when(metadataRefreshService.buildFetchMetadata(any(), any(), any())).thenReturn(fetched);
|
||||
when(objectMapper.writeValueAsString(fetched)).thenReturn("{\"title\":\"New Title\"}");
|
||||
|
||||
@@ -155,7 +158,7 @@ class BookdropMetadataServiceTest {
|
||||
when(appSettingService.getAppSettings()).thenReturn(settings);
|
||||
when(metadataRefreshService.prepareProviders(any())).thenReturn(List.of(MetadataProvider.GoodReads));
|
||||
when(objectMapper.readValue(anyString(), eq(BookMetadata.class))).thenReturn(fetched);
|
||||
when(metadataRefreshService.fetchMetadataForBook(any(), any())).thenReturn(Map.of());
|
||||
when(metadataRefreshService.fetchMetadataForBook(any(), any(Book.class))).thenReturn(Map.of());
|
||||
when(metadataRefreshService.buildFetchMetadata(any(), any(), any())).thenReturn(fetched);
|
||||
when(objectMapper.writeValueAsString(fetched)).thenReturn("{\"title\":\"Fetched Book\"}");
|
||||
when(bookdropFileRepository.save(any())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
package com.adityachandel.booklore.service.metadata;
|
||||
|
||||
import com.adityachandel.booklore.model.MetadataClearFlags;
|
||||
import com.adityachandel.booklore.model.dto.BookMetadata;
|
||||
import com.adityachandel.booklore.model.dto.BookReview;
|
||||
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookReviewEntity;
|
||||
import com.adityachandel.booklore.model.enums.MetadataProvider;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class BookReviewUpdateServiceTest {
|
||||
|
||||
private BookReviewUpdateService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new BookReviewUpdateService();
|
||||
}
|
||||
|
||||
private BookReview buildDto(MetadataProvider provider, Instant date) {
|
||||
return BookReview.builder()
|
||||
.metadataProvider(provider)
|
||||
.reviewerName("alice")
|
||||
.title("Great Book")
|
||||
.rating(4.5f)
|
||||
.date(date)
|
||||
.body("insightful")
|
||||
.spoiler(false)
|
||||
.followersCount(42)
|
||||
.textReviewsCount(3)
|
||||
.country("US")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void lockedEntityShouldRemainUnchanged() {
|
||||
BookMetadataEntity entity = new BookMetadataEntity();
|
||||
entity.setReviewsLocked(true);
|
||||
|
||||
BookReviewEntity existing = BookReviewEntity.builder()
|
||||
.metadataProvider(MetadataProvider.Amazon)
|
||||
.build();
|
||||
entity.getReviews().add(existing);
|
||||
|
||||
List<BookReview> incoming = Collections.singletonList(buildDto(MetadataProvider.Amazon, Instant.now()));
|
||||
|
||||
service.updateBookReviews(BookMetadata.builder()
|
||||
.bookReviews(incoming)
|
||||
.build(), entity, new MetadataClearFlags(), true);
|
||||
|
||||
assertEquals(1, entity.getReviews().size());
|
||||
assertTrue(entity.getReviews().stream().anyMatch(r -> r.getMetadataProvider() == MetadataProvider.Amazon));
|
||||
}
|
||||
|
||||
@Test
|
||||
void clearFlagRemovesAllReviews() {
|
||||
BookMetadataEntity entity = new BookMetadataEntity();
|
||||
entity.setReviewsLocked(false);
|
||||
|
||||
entity.getReviews().add(BookReviewEntity.builder()
|
||||
.metadataProvider(MetadataProvider.GoodReads)
|
||||
.build()
|
||||
);
|
||||
|
||||
MetadataClearFlags flags = new MetadataClearFlags();
|
||||
flags.setReviews(true);
|
||||
|
||||
service.updateBookReviews(BookMetadata.builder()
|
||||
.bookReviews(Collections.singletonList(
|
||||
buildDto(MetadataProvider.GoodReads, Instant.now())
|
||||
))
|
||||
.build(), entity, flags, true);
|
||||
|
||||
assertTrue(entity.getReviews().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void nullOrEmptyReviewsDoNothing() {
|
||||
BookMetadataEntity entity = new BookMetadataEntity();
|
||||
entity.setReviewsLocked(false);
|
||||
|
||||
entity.getReviews().add(BookReviewEntity.builder()
|
||||
.metadataProvider(MetadataProvider.Google)
|
||||
.build()
|
||||
);
|
||||
|
||||
service.updateBookReviews(BookMetadata.builder().build(), entity, new MetadataClearFlags(), true);
|
||||
assertEquals(1, entity.getReviews().size());
|
||||
|
||||
service.updateBookReviews(BookMetadata.builder()
|
||||
.bookReviews(Collections.emptyList())
|
||||
.build(), entity, new MetadataClearFlags(), true);
|
||||
assertEquals(1, entity.getReviews().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void mergeWithExistingAddsReviews() {
|
||||
BookMetadataEntity entity = new BookMetadataEntity();
|
||||
entity.setReviewsLocked(false);
|
||||
|
||||
BookReviewEntity existing = BookReviewEntity.builder()
|
||||
.metadataProvider(MetadataProvider.Google)
|
||||
.build();
|
||||
entity.getReviews().add(existing);
|
||||
|
||||
List<BookReview> incoming = Arrays.asList(
|
||||
buildDto(MetadataProvider.Hardcover, Instant.now()),
|
||||
buildDto(MetadataProvider.Comicvine, Instant.now())
|
||||
);
|
||||
|
||||
service.updateBookReviews(BookMetadata.builder()
|
||||
.bookReviews(incoming)
|
||||
.build(), entity, new MetadataClearFlags(), true);
|
||||
|
||||
Set<MetadataProvider> providers = entity.getReviews().stream()
|
||||
.map(BookReviewEntity::getMetadataProvider)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
assertEquals(3, providers.size());
|
||||
assertTrue(providers.containsAll(Arrays.asList(
|
||||
MetadataProvider.Google,
|
||||
MetadataProvider.Hardcover,
|
||||
MetadataProvider.Comicvine
|
||||
)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void replaceClearsAndAddsOnlyIncoming() {
|
||||
BookMetadataEntity entity = new BookMetadataEntity();
|
||||
entity.setReviewsLocked(false);
|
||||
|
||||
entity.getReviews().add(BookReviewEntity.builder()
|
||||
.metadataProvider(MetadataProvider.Amazon)
|
||||
.build()
|
||||
);
|
||||
|
||||
List<BookReview> incoming = Collections.singletonList(
|
||||
buildDto(MetadataProvider.GoodReads, Instant.now())
|
||||
);
|
||||
|
||||
service.updateBookReviews(BookMetadata.builder()
|
||||
.bookReviews(incoming)
|
||||
.build(), entity, new MetadataClearFlags(), false);
|
||||
|
||||
assertEquals(1, entity.getReviews().size());
|
||||
assertTrue(entity.getReviews().stream()
|
||||
.allMatch(r -> r.getMetadataProvider() == MetadataProvider.GoodReads));
|
||||
}
|
||||
|
||||
@Test
|
||||
void limitsReviewsPerProviderToFiveNewest() {
|
||||
BookMetadataEntity entity = new BookMetadataEntity();
|
||||
entity.setReviewsLocked(false);
|
||||
|
||||
List<BookReview> incoming = new ArrayList<>();
|
||||
long now = System.currentTimeMillis();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
incoming.add(buildDto(
|
||||
MetadataProvider.Amazon,
|
||||
Instant.ofEpochMilli(now - (i * 1000L))
|
||||
));
|
||||
}
|
||||
|
||||
service.updateBookReviews(BookMetadata.builder()
|
||||
.bookReviews(incoming)
|
||||
.build(), entity, new MetadataClearFlags(), false);
|
||||
|
||||
assertEquals(5, entity.getReviews().size());
|
||||
|
||||
List<Instant> keptDates = entity.getReviews().stream()
|
||||
.map(BookReviewEntity::getDate)
|
||||
.sorted(Comparator.reverseOrder())
|
||||
.toList();
|
||||
|
||||
assertFalse(keptDates.contains(
|
||||
Instant.ofEpochMilli(now - (5 * 1000L))
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,12 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {BehaviorSubject} from 'rxjs';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class AuthInitializationService {
|
||||
private initialized = new BehaviorSubject<boolean>(false);
|
||||
initialized$ = this.initialized.asObservable();
|
||||
|
||||
private oidcFailed = new BehaviorSubject<boolean>(false);
|
||||
oidcFailed$ = this.oidcFailed.asObservable();
|
||||
|
||||
markAsInitialized() {
|
||||
this.initialized.next(true);
|
||||
}
|
||||
|
||||
setOidcFailed(failed: boolean) {
|
||||
this.oidcFailed.next(failed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,59 +16,51 @@ export function initializeAuthFactory() {
|
||||
|
||||
return new Promise<void>((resolve) => {
|
||||
const sub = appSettingsService.appSettings$.subscribe(settings => {
|
||||
if (!settings) return;
|
||||
if (settings) {
|
||||
if (settings.oidcEnabled && settings.oidcProviderDetails) {
|
||||
const details = settings.oidcProviderDetails;
|
||||
|
||||
sub.unsubscribe();
|
||||
|
||||
if (settings.oidcEnabled && settings.oidcProviderDetails) {
|
||||
const details = settings.oidcProviderDetails;
|
||||
|
||||
oauthService.configure({
|
||||
issuer: details.issuerUri,
|
||||
clientId: details.clientId,
|
||||
scope: 'openid profile email offline_access',
|
||||
redirectUri: window.location.origin + '/oauth2-callback',
|
||||
responseType: 'code',
|
||||
showDebugInformation: false,
|
||||
requireHttps: false,
|
||||
strictDiscoveryDocumentValidation: false,
|
||||
});
|
||||
|
||||
oauthService.loadDiscoveryDocumentAndTryLogin()
|
||||
.then(() => {
|
||||
if (oauthService.hasValidAccessToken()) {
|
||||
console.log('[OIDC] Valid access token found');
|
||||
oauthService.setupAutomaticSilentRefresh();
|
||||
websocketInitializer(authService);
|
||||
} else {
|
||||
console.warn('[OIDC] No valid access token. Will proceed to app and show login page.');
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('[OIDC] Failed to load discovery document or login:', err);
|
||||
authInitService.setOidcFailed(true);
|
||||
})
|
||||
.finally(() => {
|
||||
authInitService.markAsInitialized();
|
||||
resolve();
|
||||
oauthService.configure({
|
||||
issuer: details.issuerUri,
|
||||
clientId: details.clientId,
|
||||
scope: 'openid profile email offline_access',
|
||||
redirectUri: window.location.origin + '/oauth2-callback',
|
||||
responseType: 'code',
|
||||
showDebugInformation: false,
|
||||
requireHttps: false,
|
||||
strictDiscoveryDocumentValidation: false,
|
||||
});
|
||||
|
||||
} else if (settings.remoteAuthEnabled) {
|
||||
authService.remoteLogin().subscribe({
|
||||
next: () => {
|
||||
authInitService.markAsInitialized();
|
||||
resolve();
|
||||
},
|
||||
error: err => {
|
||||
console.error('[Remote Login] failed:', err);
|
||||
authInitService.markAsInitialized();
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
authInitService.markAsInitialized();
|
||||
resolve();
|
||||
oauthService.loadDiscoveryDocumentAndTryLogin()
|
||||
.then(() => {
|
||||
console.log('[OIDC] Discovery document loaded and login attempted');
|
||||
if (oauthService.hasValidAccessToken()) {
|
||||
authService.tokenSubject.next(oauthService.getAccessToken())
|
||||
console.log('[OIDC] Valid access token found after tryLogin');
|
||||
oauthService.setupAutomaticSilentRefresh();
|
||||
websocketInitializer(authService);
|
||||
authInitService.markAsInitialized();
|
||||
resolve();
|
||||
} else {
|
||||
console.log('[OIDC] No valid access token found, attempting silent login with prompt=none');
|
||||
oauthService.initImplicitFlow();
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
authInitService.markAsInitialized();
|
||||
console.error(
|
||||
'OIDC initialization failed: Unable to complete OpenID Connect discovery or login. ' +
|
||||
'This may be due to an incorrect issuer URL, client ID, or network issue. ' +
|
||||
'Falling back to local login. Details:', err
|
||||
);
|
||||
resolve();
|
||||
});
|
||||
} else {
|
||||
authInitService.markAsInitialized();
|
||||
resolve();
|
||||
}
|
||||
sub.unsubscribe();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from './config/api-config';
|
||||
|
||||
export interface BookReview {
|
||||
id?: number;
|
||||
metadataProvider?: string;
|
||||
reviewerName?: string;
|
||||
title?: string;
|
||||
rating?: number;
|
||||
date?: string;
|
||||
body?: string;
|
||||
country?: string;
|
||||
spoiler?: boolean;
|
||||
followersCount?: number;
|
||||
textReviewsCount?: number;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class BookReviewService {
|
||||
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/reviews`;
|
||||
private http = inject(HttpClient);
|
||||
|
||||
getByBookId(bookId: number): Observable<BookReview[]> {
|
||||
return this.http.get<BookReview[]>(`${this.url}/book/${bookId}`);
|
||||
}
|
||||
|
||||
refreshReviews(bookId: number): Observable<BookReview[]> {
|
||||
return this.http.post<BookReview[]>(`${this.url}/book/${bookId}/refresh`, {});
|
||||
}
|
||||
|
||||
delete(reviewId: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.url}/${reviewId}`);
|
||||
}
|
||||
|
||||
deleteAllByBookId(bookId: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.url}/book/${bookId}`);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@
|
||||
}
|
||||
|
||||
<p-button [rounded]="true" icon="pi pi-info" class="info-btn" (click)="openBookInfo(book)"></p-button>
|
||||
|
||||
<p-button [hidden]="readButtonHidden" [rounded]="true" icon="pi pi-book" class="read-btn" (click)="readBook(book)"></p-button>
|
||||
|
||||
@if (isCheckboxEnabled) {
|
||||
@@ -66,7 +67,12 @@
|
||||
|
||||
<div [hidden]="bottomBarHidden">
|
||||
<div class="book-title-container flex items-center">
|
||||
<h4 class="book-title m-0 pl-2" [title]="book.metadata?.title">{{ book.metadata?.title }}</h4>
|
||||
<h4 class="book-title m-0 pl-2"
|
||||
tooltipPosition="bottom"
|
||||
tooltipStyleClass="text-xs text-center"
|
||||
[pTooltip]="book.metadata?.title">
|
||||
{{ book.metadata?.title }}
|
||||
</h4>
|
||||
<p-tieredmenu #menu [model]="items" [popup]="true" appendTo="body"></p-tieredmenu>
|
||||
<p-button
|
||||
class="custom-button-padding"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {Component, ElementRef, EventEmitter, inject, Input, OnDestroy, OnInit, Output, ViewChild} from '@angular/core';
|
||||
import {TooltipModule} from "primeng/tooltip";
|
||||
import {Book, ReadStatus} from '../../../model/book.model';
|
||||
import {Button} from 'primeng/button';
|
||||
import {MenuModule} from 'primeng/menu';
|
||||
@@ -29,7 +30,7 @@ import {ResetProgressTypes} from '../../../../shared/constants/reset-progress-ty
|
||||
selector: 'app-book-card',
|
||||
templateUrl: './book-card.component.html',
|
||||
styleUrls: ['./book-card.component.scss'],
|
||||
imports: [Button, MenuModule, CheckboxModule, FormsModule, NgClass, TieredMenu, ProgressBar],
|
||||
imports: [Button, MenuModule, CheckboxModule, FormsModule, NgClass, TieredMenu, ProgressBar, TooltipModule],
|
||||
standalone: true
|
||||
})
|
||||
export class BookCardComponent implements OnInit, OnDestroy {
|
||||
|
||||
+3
-2
@@ -48,7 +48,7 @@
|
||||
(click)="toggleMetadataLock(metadata)">
|
||||
</p-button>
|
||||
</td>
|
||||
<td (click)="openMetadataCenter(book.id)">
|
||||
<td (click)="openMetadataCenter(book.id)" class="cursor-pointer">
|
||||
<img [attr.src]="urlHelper.getCoverUrl(metadata.bookId, metadata.coverUpdatedOn)" alt="Book Cover" class="size-7"/>
|
||||
</td>
|
||||
|
||||
@@ -68,7 +68,8 @@
|
||||
</span>
|
||||
</td>
|
||||
} @else {
|
||||
<td [title]="getCellValue(metadata, book, col.field)" class="overflow-hidden truncate text-right min-w-[6rem] max-w-[12rem]">
|
||||
<td [title]="getCellValue(metadata, book, col.field)"
|
||||
class="overflow-hidden truncate text-right min-w-[6rem] max-w-[12rem]">
|
||||
{{ getCellValue(metadata, book, col.field) }}
|
||||
</td>
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import {TableModule} from 'primeng/table';
|
||||
import {DatePipe} from '@angular/common';
|
||||
import {Rating} from 'primeng/rating';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {TooltipModule} from "primeng/tooltip";
|
||||
import {Book, BookMetadata} from '../../../model/book.model';
|
||||
import {SortOption} from '../../../model/sort.model';
|
||||
import {UrlHelperService} from '../../../../utilities/service/url-helper.service';
|
||||
@@ -24,7 +25,8 @@ import {take, takeUntil} from 'rxjs/operators';
|
||||
TableModule,
|
||||
Rating,
|
||||
FormsModule,
|
||||
Button
|
||||
Button,
|
||||
TooltipModule
|
||||
],
|
||||
styleUrls: ['./book-table.component.scss'],
|
||||
providers: [DatePipe]
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
<div class="book-cover-wrapper"
|
||||
(mouseenter)="isHovered = true"
|
||||
(mouseleave)="isHovered = false">
|
||||
<div class="book-cover-wrapper" (mouseenter)="isHovered = true" (mouseleave)="isHovered = false">
|
||||
<img
|
||||
[src]="urlHelper.getCoverUrl(book.id, book.metadata?.coverUpdatedOn)"
|
||||
class="book-cover"
|
||||
alt="Cover of {{ book.metadata?.title }}"
|
||||
loading="lazy"
|
||||
/>
|
||||
loading="lazy"/>
|
||||
|
||||
<p-button
|
||||
icon="pi pi-info"
|
||||
class="info-btn"
|
||||
[rounded]="true"
|
||||
[pTooltip]="book.metadata?.title"
|
||||
tooltipPosition="top"
|
||||
[ngClass]="{ 'visible': isHovered }"
|
||||
(onClick)="openBookInfo(book)">
|
||||
</p-button>
|
||||
|
||||
@@ -8,12 +8,14 @@ import {filter, Subject} from 'rxjs';
|
||||
import {NgClass} from '@angular/common';
|
||||
import {BookMetadataHostService} from '../../../utilities/service/book-metadata-host-service';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
import {TooltipModule} from 'primeng/tooltip';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-card-lite-component',
|
||||
imports: [
|
||||
Button,
|
||||
NgClass
|
||||
NgClass,
|
||||
TooltipModule
|
||||
],
|
||||
templateUrl: './book-card-lite-component.html',
|
||||
styleUrl: './book-card-lite-component.scss'
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
<div class="book-notes-container">
|
||||
<div class="notes-content">
|
||||
@if (loading) {
|
||||
<div class="flex flex-col items-center justify-center p-8 gap-4">
|
||||
<p-progressSpinner/>
|
||||
<span class="text-gray-400">Loading notes...</span>
|
||||
</div>
|
||||
} @else if (notes.length === 0) {
|
||||
<div class="text-center p-8 text-gray-400 empty-state">
|
||||
<div class="empty-state-icon">
|
||||
<p-button
|
||||
outlined
|
||||
rounded
|
||||
icon="pi pi-plus"
|
||||
severity="primary"
|
||||
(click)="openCreateDialog()"
|
||||
pTooltip="Add New Note"
|
||||
tooltipPosition="top"
|
||||
class="action-btn floating-btn">
|
||||
</p-button>
|
||||
</div>
|
||||
<p class="text-gray-200 empty-state-title">No notes yet for this book</p>
|
||||
<p class="text-sm text-gray-400 mt-2 empty-state-subtitle">
|
||||
Click "Add Note" to create your first note and start capturing your thoughts
|
||||
</p>
|
||||
<div class="empty-state-decoration"></div>
|
||||
</div>
|
||||
} @else {
|
||||
<div class="notes-scroll-container">
|
||||
<div class="notes-horizontal-list">
|
||||
@for (note of notes; track note.id + '-' + note.createdAt + '-' + $index) {
|
||||
<div class="note-card border border-zinc-700">
|
||||
<div class="note-header">
|
||||
<div class="flex justify-between items-start p-3">
|
||||
<div class="flex flex-col gap-1">
|
||||
<h4 class="note-title font-medium text-lg text-gray-200 m-0">{{ note.title }}</h4>
|
||||
<div class="note-meta">
|
||||
<i class="pi pi-clock text-xs mr-1"></i>
|
||||
<span class="text-sm text-gray-400">
|
||||
@if (note.createdAt !== note.updatedAt) {
|
||||
Updated {{ formatDate(note.updatedAt) }}
|
||||
} @else {
|
||||
Created {{ formatDate(note.createdAt) }}
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="note-actions">
|
||||
<p-button
|
||||
icon="pi pi-pencil"
|
||||
size="small"
|
||||
severity="secondary"
|
||||
text
|
||||
(onClick)="openEditDialog(note)"
|
||||
pTooltip="Edit note"
|
||||
tooltipPosition="top"
|
||||
class="action-btn-hover">
|
||||
</p-button>
|
||||
<p-button
|
||||
icon="pi pi-trash"
|
||||
size="small"
|
||||
severity="danger"
|
||||
text
|
||||
(onClick)="deleteNote(note)"
|
||||
pTooltip="Delete note"
|
||||
tooltipPosition="top"
|
||||
class="action-btn-hover">
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="note-content-area px-3 pb-3">
|
||||
<div class="text-zinc-300 note-body">{{ note.content }}</div>
|
||||
<div class="note-fade-overlay"></div>
|
||||
</div>
|
||||
<div class="note-bottom-glow"></div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (notes.length > 0) {
|
||||
<div class="action-bar">
|
||||
<p-button
|
||||
outlined
|
||||
icon="pi pi-plus"
|
||||
severity="success"
|
||||
(click)="openCreateDialog()"
|
||||
pTooltip="Add New Note"
|
||||
tooltipPosition="left">
|
||||
</p-button>
|
||||
</div>
|
||||
}
|
||||
|
||||
<p-dialog
|
||||
header="Add New Note"
|
||||
[(visible)]="showCreateDialog"
|
||||
[modal]="true"
|
||||
[style]="{width: '500px'}"
|
||||
[closable]="true"
|
||||
[dismissableMask]="true">
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="field">
|
||||
<label for="create-title" class="block text-sm font-medium mb-2">Title</label>
|
||||
<input
|
||||
id="create-title"
|
||||
pInputText
|
||||
[(ngModel)]="newNote.title"
|
||||
placeholder="Enter note title"
|
||||
class="w-full"
|
||||
maxlength="255"/>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="create-content" class="block text-sm font-medium mb-2">Content</label>
|
||||
<textarea
|
||||
id="create-content"
|
||||
pTextarea
|
||||
[(ngModel)]="newNote.content"
|
||||
placeholder="Enter your note content..."
|
||||
[rows]="8"
|
||||
class="w-full"
|
||||
[autoResize]="true">
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ng-template #footer>
|
||||
<div class="flex gap-2 justify-end">
|
||||
<p-button
|
||||
label="Cancel"
|
||||
severity="secondary"
|
||||
outlined
|
||||
(onClick)="cancelCreate()">
|
||||
</p-button>
|
||||
<p-button
|
||||
outlined
|
||||
severity="success"
|
||||
label="Save Note"
|
||||
icon="pi pi-save"
|
||||
(onClick)="createNote()">
|
||||
</p-button>
|
||||
</div>
|
||||
</ng-template>
|
||||
</p-dialog>
|
||||
|
||||
<p-dialog
|
||||
header="Edit Note"
|
||||
[(visible)]="showEditDialog"
|
||||
[modal]="true"
|
||||
[style]="{width: '500px'}"
|
||||
[closable]="true"
|
||||
[dismissableMask]="true">
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="field">
|
||||
<label for="edit-title" class="block text-sm font-medium mb-2">Title</label>
|
||||
<input
|
||||
id="edit-title"
|
||||
pInputText
|
||||
[(ngModel)]="editNote.title"
|
||||
placeholder="Enter note title"
|
||||
class="w-full"
|
||||
maxlength="255"/>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="edit-content" class="block text-sm font-medium mb-2">Content</label>
|
||||
<textarea
|
||||
id="edit-content"
|
||||
pTextarea
|
||||
[(ngModel)]="editNote.content"
|
||||
placeholder="Enter your note content..."
|
||||
[rows]="8"
|
||||
class="w-full"
|
||||
[autoResize]="true">
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ng-template #footer>
|
||||
<div class="flex gap-2 justify-end">
|
||||
<p-button
|
||||
label="Cancel"
|
||||
severity="secondary"
|
||||
outlined
|
||||
(onClick)="cancelEdit()">
|
||||
</p-button>
|
||||
<p-button
|
||||
outlined
|
||||
severity="success"
|
||||
label="Update Note"
|
||||
icon="pi pi-save"
|
||||
(onClick)="updateNote()">
|
||||
</p-button>
|
||||
</div>
|
||||
</ng-template>
|
||||
</p-dialog>
|
||||
|
||||
<p-confirmDialog key="deleteNote"></p-confirmDialog>
|
||||
</div>
|
||||
@@ -0,0 +1,254 @@
|
||||
.book-notes-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
display: flex;
|
||||
min-height: 250px;
|
||||
|
||||
.notes-content {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: 0;
|
||||
transform: translateY(-50%);
|
||||
z-index: 1000;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
position: relative;
|
||||
padding: 3rem !important;
|
||||
|
||||
.empty-state-title {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.empty-state-subtitle {
|
||||
max-width: 400px;
|
||||
margin: 0 auto;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.empty-state-decoration {
|
||||
position: absolute;
|
||||
top: 20%;
|
||||
right: 15%;
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
border-radius: 50%;
|
||||
filter: blur(40px);
|
||||
animation: float 4s ease-in-out infinite;
|
||||
}
|
||||
}
|
||||
|
||||
.notes-scroll-container {
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
height: 100%;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
height: 10px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: rgba(30, 30, 30, 0.5);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.notes-horizontal-list {
|
||||
display: flex;
|
||||
gap: 1.5rem;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.note-card {
|
||||
width: 500px;
|
||||
height: 240px;
|
||||
flex-shrink: 0;
|
||||
padding: 0;
|
||||
border-radius: 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
|
||||
|
||||
@media (max-width: 768px) {
|
||||
width: 340px;
|
||||
height: 220px;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
width: 290px;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
border-color: color-mix(in srgb, var(--primary-color), transparent 50%);
|
||||
|
||||
.note-bottom-glow {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.action-btn-hover {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
.note-header {
|
||||
flex-shrink: 0;
|
||||
background: linear-gradient(135deg, rgba(40, 40, 40, 0.8), rgba(30, 30, 30, 0.8));
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||
position: relative;
|
||||
|
||||
.note-title {
|
||||
max-width: 350px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
background: linear-gradient(135deg, #f8fafc, #e2e8f0);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
max-width: 200px;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
max-width: 180px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
}
|
||||
|
||||
.note-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
opacity: 0.8;
|
||||
|
||||
i {
|
||||
color: #3b82f6;
|
||||
}
|
||||
}
|
||||
|
||||
.note-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
.action-btn-hover {
|
||||
opacity: 0.7;
|
||||
transition: all 0.3s ease;
|
||||
transform: scale(0.9);
|
||||
|
||||
::ng-deep .p-button {
|
||||
border-radius: 8px;
|
||||
|
||||
&:hover {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.note-content-area {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
padding: 1rem !important;
|
||||
|
||||
.note-fade-overlay {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 30px;
|
||||
background: linear-gradient(transparent, rgba(20, 20, 20, 0.9));
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.note-bottom-glow {
|
||||
position: absolute;
|
||||
bottom: -5px;
|
||||
left: 20%;
|
||||
right: 20%;
|
||||
height: 10px;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
color-mix(in srgb, var(--primary-color), transparent 60%),
|
||||
transparent
|
||||
);
|
||||
border-radius: 50%;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
filter: blur(5px);
|
||||
}
|
||||
}
|
||||
|
||||
.note-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
max-height: 180px;
|
||||
overflow-y: auto;
|
||||
word-wrap: break-word;
|
||||
white-space: pre-wrap;
|
||||
padding-right: 8px;
|
||||
box-sizing: border-box;
|
||||
line-height: 1.6;
|
||||
color: #e2e8f0;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
max-height: 140px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
max-height: 120px;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes float {
|
||||
0%, 100% {
|
||||
transform: translateY(0px);
|
||||
}
|
||||
50% {
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% {
|
||||
transform: scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
transform: scale(1.05);
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
import {Component, DestroyRef, inject, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Dialog} from 'primeng/dialog';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {Textarea} from 'primeng/textarea';
|
||||
import {ConfirmDialog} from 'primeng/confirmdialog';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||
import {BookNote, BookNoteService, CreateBookNoteRequest} from '../../../core/service/book-note.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-notes-component',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
Button,
|
||||
Dialog,
|
||||
InputText,
|
||||
Textarea,
|
||||
ConfirmDialog,
|
||||
ProgressSpinner,
|
||||
Tooltip
|
||||
],
|
||||
templateUrl: './book-notes-component.html',
|
||||
styleUrl: './book-notes-component.scss'
|
||||
})
|
||||
export class BookNotesComponent implements OnInit, OnChanges {
|
||||
@Input() bookId!: number;
|
||||
|
||||
private bookNoteService = inject(BookNoteService);
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
private messageService = inject(MessageService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
notes: BookNote[] = [];
|
||||
loading = false;
|
||||
showCreateDialog = false;
|
||||
showEditDialog = false;
|
||||
selectedNote: BookNote | null = null;
|
||||
|
||||
newNote: CreateBookNoteRequest = {
|
||||
bookId: 0,
|
||||
title: '',
|
||||
content: ''
|
||||
};
|
||||
|
||||
editNote: CreateBookNoteRequest = {
|
||||
bookId: 0,
|
||||
title: '',
|
||||
content: ''
|
||||
};
|
||||
|
||||
ngOnInit(): void {
|
||||
if (this.bookId) {
|
||||
this.loadNotes();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['bookId'] && changes['bookId'].currentValue) {
|
||||
this.loadNotes();
|
||||
}
|
||||
}
|
||||
|
||||
loadNotes(): void {
|
||||
if (!this.bookId) return;
|
||||
|
||||
this.loading = true;
|
||||
this.bookNoteService.getNotesForBook(this.bookId)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: (notes) => {
|
||||
this.notes = notes.sort((a, b) =>
|
||||
new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
|
||||
);
|
||||
this.loading = false;
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to load notes:', error);
|
||||
this.loading = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to load notes for this book.'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
openCreateDialog(): void {
|
||||
this.newNote = {
|
||||
bookId: this.bookId,
|
||||
title: '',
|
||||
content: ''
|
||||
};
|
||||
this.showCreateDialog = true;
|
||||
}
|
||||
|
||||
openEditDialog(note: BookNote): void {
|
||||
this.selectedNote = note;
|
||||
this.editNote = {
|
||||
id: note.id,
|
||||
bookId: note.bookId,
|
||||
title: note.title,
|
||||
content: note.content
|
||||
};
|
||||
this.showEditDialog = true;
|
||||
}
|
||||
|
||||
createNote(): void {
|
||||
if (!this.newNote.title.trim() || !this.newNote.content.trim()) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: 'Validation Error',
|
||||
detail: 'Both title and content are required.'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.bookNoteService.createOrUpdateNote(this.newNote)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: (note) => {
|
||||
this.notes.unshift(note);
|
||||
this.showCreateDialog = false;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Success',
|
||||
detail: 'Note created successfully.'
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to create note:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to create note.'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updateNote(): void {
|
||||
if (!this.editNote.title?.trim() || !this.editNote.content?.trim()) {
|
||||
this.messageService.add({
|
||||
severity: 'warn',
|
||||
summary: 'Validation Error',
|
||||
detail: 'Both title and content are required.'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.bookNoteService.createOrUpdateNote(this.editNote)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: (updatedNote) => {
|
||||
const index = this.notes.findIndex(n => n.id === this.selectedNote?.id);
|
||||
if (index !== -1) {
|
||||
this.notes[index] = updatedNote;
|
||||
this.notes.sort((a, b) =>
|
||||
new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
|
||||
);
|
||||
}
|
||||
this.showEditDialog = false;
|
||||
this.selectedNote = null;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Success',
|
||||
detail: 'Note updated successfully.'
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to update note:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to update note.'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
deleteNote(note: BookNote): void {
|
||||
this.confirmationService.confirm({
|
||||
key: 'deleteNote',
|
||||
message: `Are you sure you want to delete the note "${note.title}"?`,
|
||||
header: 'Confirm Deletion',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-trash',
|
||||
rejectIcon: 'pi pi-times',
|
||||
acceptButtonStyleClass: 'p-button-danger, p-button-outlined p-button-danger',
|
||||
rejectButtonStyleClass: 'p-button-danger, p-button-outlined p-button-info',
|
||||
accept: () => {
|
||||
this.performDelete(note.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private performDelete(noteId: number): void {
|
||||
this.bookNoteService.deleteNote(noteId).subscribe({
|
||||
next: () => {
|
||||
this.notes = this.notes.filter(n => n.id !== noteId);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Success',
|
||||
detail: 'Note deleted successfully.'
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to delete note:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to delete note.'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
cancelCreate(): void {
|
||||
this.showCreateDialog = false;
|
||||
this.newNote = {
|
||||
bookId: this.bookId,
|
||||
title: '',
|
||||
content: ''
|
||||
};
|
||||
}
|
||||
|
||||
cancelEdit(): void {
|
||||
this.showEditDialog = false;
|
||||
this.selectedNote = null;
|
||||
this.editNote = {
|
||||
bookId: this.bookId,
|
||||
title: '',
|
||||
content: ''
|
||||
};
|
||||
}
|
||||
|
||||
formatDate(dateString: string): string {
|
||||
return new Date(dateString).toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
<div class="book-reviews-container">
|
||||
<div class="reviews-content">
|
||||
@if (loading) {
|
||||
<div class="flex flex-col items-center justify-center p-8 gap-4">
|
||||
<p-progressSpinner/>
|
||||
<span class="text-gray-400">Getting latest reviews...</span>
|
||||
</div>
|
||||
} @else if (reviews?.length === 0) {
|
||||
<div class="text-center p-8 text-gray-400">
|
||||
<i class="pi pi-comments text-4xl mb-4 block"></i>
|
||||
<p class="text-gray-200">No reviews available for this book</p>
|
||||
@if (!reviewDownloadEnabled) {
|
||||
<p class="text-sm text-amber-400 mt-2">
|
||||
Book review downloads are currently disabled. Enable this in Metadata Settings to fetch reviews.
|
||||
</p>
|
||||
}
|
||||
</div>
|
||||
} @else {
|
||||
<div class="reviews-scroll-container">
|
||||
<div class="reviews-horizontal-list">
|
||||
@for (review of reviews; track review.id || $index) {
|
||||
<div [class]="'review-card border border-zinc-700' + (!review.title ? ' no-title' : '') + (review.spoiler && !isSpoilerRevealed(review.id!) ? ' has-spoiler' : '')">
|
||||
@if (review.spoiler && !isSpoilerRevealed(review.id!)) {
|
||||
<p-button
|
||||
label="Show Spoiler"
|
||||
icon="pi pi-eye"
|
||||
severity="warn"
|
||||
size="small"
|
||||
class="spoiler-overlay-button"
|
||||
(onClick)="revealSpoiler(review.id!)"/>
|
||||
}
|
||||
|
||||
<div class="review-header">
|
||||
<div class="flex justify-between items-start p-3">
|
||||
<div class="flex flex-col gap-1">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="font-medium text-sm reviewer-name">{{ review.reviewerName || 'Anonymous' }}</span>
|
||||
@if (review.metadataProvider) {
|
||||
<p-tag
|
||||
[rounded]="true"
|
||||
[value]="review.metadataProvider"
|
||||
[severity]="getProviderSeverity(review.metadataProvider)"/>
|
||||
}
|
||||
@if (review.country) {
|
||||
<p-tag [rounded]="true" [value]="review.country" severity="info"/>
|
||||
}
|
||||
@if (review.spoiler) {
|
||||
<p-tag [rounded]="true" value="Spoiler" severity="warn" icon="pi pi-exclamation-triangle"/>
|
||||
}
|
||||
</div>
|
||||
<div class="review-meta">
|
||||
<i class="pi pi-clock text-xs mr-1"></i>
|
||||
@if (review.date) {
|
||||
<span class="text-sm text-gray-400">{{ formatDate(review.date) }}</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2">
|
||||
@if (review.rating) {
|
||||
<div class="flex items-center gap-1">
|
||||
<p-rating
|
||||
[ngModel]="review.rating"
|
||||
[readonly]="true"
|
||||
[stars]="5"/>
|
||||
<span class="text-sm font-medium">{{ review.rating }}/5</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (hasPermission) {
|
||||
@if (reviewsLocked) {
|
||||
<div class="flex items-center justify-center w-8 h-8">
|
||||
<i class="pi pi-lock text-amber-500 text-sm"
|
||||
pTooltip="Reviews are locked"
|
||||
tooltipPosition="top"></i>
|
||||
</div>
|
||||
} @else {
|
||||
<p-button
|
||||
icon="pi pi-trash"
|
||||
size="small"
|
||||
severity="danger"
|
||||
text
|
||||
(onClick)="deleteReview(review)"
|
||||
pTooltip="Delete Review"
|
||||
tooltipPosition="top"
|
||||
class="action-btn-hover"/>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (review.title && (!review.spoiler || isSpoilerRevealed(review.id!))) {
|
||||
<div class="review-title-section">
|
||||
<h4 class="font-medium text-xl text-gray-200 leading-tight m-0 review-title"
|
||||
[pTooltip]="review.title"
|
||||
tooltipPosition="top">{{ review.title }}
|
||||
</h4>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="review-content-area">
|
||||
@if (review.spoiler && !isSpoilerRevealed(review.id!)) {
|
||||
<div class="spoiler-blur-content">
|
||||
@if (review.title) {
|
||||
<h4 class="font-medium text-gray-200 leading-tight m-0 review-title blur-sm mb-2">{{ review.title }}</h4>
|
||||
}
|
||||
@if (review.body) {
|
||||
<div class="text-zinc-300 review-body blur-sm">{{ review.body }}</div>
|
||||
} @else {
|
||||
<div class="text-zinc-400 italic text-sm blur-sm">No review content available</div>
|
||||
}
|
||||
</div>
|
||||
} @else {
|
||||
@if (review.body) {
|
||||
<div class="text-zinc-300 review-body">{{ review.body }}</div>
|
||||
} @else {
|
||||
<div class="text-zinc-400 italic text-sm">No review content available</div>
|
||||
}
|
||||
}
|
||||
<div class="review-fade-overlay"></div>
|
||||
</div>
|
||||
<div class="review-bottom-glow"></div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="action-bar">
|
||||
<div class="action-buttons">
|
||||
|
||||
@if (hasPermission) {
|
||||
<p-button
|
||||
outlined
|
||||
[icon]="reviewsLocked ? 'pi pi-lock' : 'pi pi-lock-open'"
|
||||
size="small"
|
||||
[severity]="reviewsLocked ? 'danger' : 'success'"
|
||||
[disabled]="!reviewDownloadEnabled || loading"
|
||||
(click)="toggleReviewsLock()"
|
||||
[pTooltip]="loading ? 'Please wait while reviews are being fetched' : (!reviewDownloadEnabled ? 'Enable review downloads in settings to use this feature' : (reviewsLocked ? 'Unlock Reviews' : 'Lock Reviews'))"
|
||||
tooltipPosition="left"
|
||||
class="action-btn"/>
|
||||
|
||||
<p-button
|
||||
outlined
|
||||
icon="pi pi-refresh"
|
||||
size="small"
|
||||
severity="primary"
|
||||
[loading]="loading"
|
||||
[disabled]="reviewsLocked || !reviewDownloadEnabled || loading"
|
||||
(click)="fetchNewReviews()"
|
||||
[pTooltip]="loading ? 'Please wait while reviews are being fetched' : (!reviewDownloadEnabled ? 'Enable review downloads in settings to use this feature' : (reviewsLocked ? 'Reviews are locked' : 'Fetch New Reviews'))"
|
||||
tooltipPosition="left"
|
||||
class="action-btn"/>
|
||||
}
|
||||
|
||||
@if (hasPermission && reviews && reviews.length > 0) {
|
||||
<p-button
|
||||
outlined
|
||||
icon="pi pi-trash"
|
||||
size="small"
|
||||
severity="danger"
|
||||
[disabled]="reviewsLocked || loading"
|
||||
(click)="deleteAllReviews()"
|
||||
[pTooltip]="loading ? 'Please wait while reviews are being fetched' : (reviewsLocked ? 'Reviews are locked' : 'Delete All Reviews')"
|
||||
tooltipPosition="left"
|
||||
class="action-btn"/>
|
||||
}
|
||||
|
||||
@if (reviews && reviews.length > 0) {
|
||||
<p-button
|
||||
outlined
|
||||
[icon]="allSpoilersRevealed ? 'pi pi-eye-slash' : 'pi pi-eye'"
|
||||
size="small"
|
||||
[severity]="allSpoilersRevealed ? 'warn' : 'info'"
|
||||
[disabled]="loading"
|
||||
(click)="toggleSpoilerVisibility()"
|
||||
[pTooltip]="loading ? 'Please wait while reviews are being fetched' : (allSpoilersRevealed ? 'Hide All Spoilers' : 'Reveal All Spoilers')"
|
||||
tooltipPosition="left"
|
||||
class="action-btn"/>
|
||||
|
||||
<p-button
|
||||
outlined
|
||||
icon="pi pi-sort-amount-down"
|
||||
size="small"
|
||||
severity="contrast"
|
||||
[disabled]="loading"
|
||||
(click)="toggleSortOrder()"
|
||||
[pTooltip]="loading ? 'Please wait while reviews are being fetched' : (sortAscending ? 'Sort by Newest First' : 'Sort by Oldest First')"
|
||||
tooltipPosition="left"
|
||||
class="action-btn"/>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,247 @@
|
||||
.book-reviews-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
display: flex;
|
||||
min-height: 250px;
|
||||
|
||||
.reviews-content {
|
||||
flex: 1;
|
||||
padding-right: 60px;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
right: 0;
|
||||
transform: translateY(-50%);
|
||||
width: 50px;
|
||||
z-index: 1000;
|
||||
pointer-events: none;
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
padding: 16px 8px;
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
backdrop-filter: blur(8px);
|
||||
pointer-events: auto;
|
||||
position: relative;
|
||||
top: -50%;
|
||||
|
||||
.action-btn {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
|
||||
::ng-deep {
|
||||
.p-button {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
|
||||
.p-button-icon {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.reviews-scroll-container {
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
padding-bottom: 8px;
|
||||
height: 100%;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
height: 8px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: var(--surface-ground);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: var(--surface-border);
|
||||
border-radius: 4px;
|
||||
|
||||
&:hover {
|
||||
background: var(--primary-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.reviews-horizontal-list {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.review-card {
|
||||
width: 500px;
|
||||
height: 250px;
|
||||
flex-shrink: 0;
|
||||
padding: 0;
|
||||
border-radius: 16px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
|
||||
@media (max-width: 768px) {
|
||||
width: 340px;
|
||||
height: 220px;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
width: 290px;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
border-color: color-mix(in srgb, var(--primary-color), transparent 50%);
|
||||
|
||||
.action-btn-hover {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
&.no-title {
|
||||
.review-content-area {
|
||||
height: calc(100% - 80px);
|
||||
}
|
||||
}
|
||||
|
||||
&.has-spoiler {
|
||||
.review-content-area {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
z-index: 50;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.review-header {
|
||||
flex-shrink: 0;
|
||||
background: linear-gradient(135deg, rgba(40, 40, 40, 0.8), rgba(30, 30, 30, 0.8));
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
||||
position: relative;
|
||||
|
||||
.reviewer-name {
|
||||
max-width: 120px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
background: linear-gradient(135deg, #f8fafc, #e2e8f0);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
}
|
||||
|
||||
.review-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
opacity: 0.8;
|
||||
|
||||
i {
|
||||
color: #3b82f6;
|
||||
}
|
||||
}
|
||||
|
||||
.action-btn-hover {
|
||||
opacity: 0.7;
|
||||
transition: all 0.3s ease;
|
||||
transform: scale(0.9);
|
||||
|
||||
::ng-deep .p-button {
|
||||
border-radius: 8px;
|
||||
|
||||
&:hover {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.review-title-section {
|
||||
flex-shrink: 0;
|
||||
border-bottom: 1px solid var(--surface-border);
|
||||
padding: 8px 16px 4px 16px;
|
||||
}
|
||||
|
||||
.review-content-area {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
padding: 8px 16px 16px 16px;
|
||||
|
||||
.review-fade-overlay {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 30px;
|
||||
background: linear-gradient(transparent, rgba(20, 20, 20, 0.9));
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.review-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
max-height: 210px;
|
||||
overflow-y: auto;
|
||||
word-wrap: break-word;
|
||||
white-space: pre-wrap;
|
||||
box-sizing: border-box;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 4px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: var(--surface-ground);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: var(--surface-border);
|
||||
border-radius: 2px;
|
||||
|
||||
&:hover {
|
||||
background: var(--primary-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.review-title {
|
||||
max-width: 450px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
cursor: help;
|
||||
}
|
||||
@@ -0,0 +1,332 @@
|
||||
import {Component, DestroyRef, inject, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
|
||||
import {BookReview, BookReviewService} from '../../../book-review-service';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {Rating} from 'primeng/rating';
|
||||
import {Tag} from 'primeng/tag';
|
||||
import {Button} from 'primeng/button';
|
||||
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {BookService} from '../../service/book.service';
|
||||
import {AppSettingsService} from '../../../core/service/app-settings.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-reviews',
|
||||
standalone: true,
|
||||
imports: [CommonModule, ProgressSpinner, Rating, Tag, Button, FormsModule, Tooltip],
|
||||
templateUrl: './book-reviews.component.html',
|
||||
styleUrl: './book-reviews.component.scss'
|
||||
})
|
||||
export class BookReviewsComponent implements OnInit, OnChanges {
|
||||
@Input() bookId!: number;
|
||||
@Input() reviews: BookReview[] | undefined = [];
|
||||
@Input() active: boolean = false;
|
||||
|
||||
private reviewService = inject(BookReviewService);
|
||||
private bookService = inject(BookService);
|
||||
private confirmationService = inject(ConfirmationService);
|
||||
private messageService = inject(MessageService);
|
||||
private userService = inject(UserService);
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
loading = false;
|
||||
hasPermission = false;
|
||||
revealedSpoilers = new Set<number>();
|
||||
sortAscending = false;
|
||||
reviewsLocked = false;
|
||||
allSpoilersRevealed = false;
|
||||
reviewDownloadEnabled = true;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.checkUserPermissions();
|
||||
this.subscribeToBookState();
|
||||
this.subscribeToAppSettings();
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['bookId'] && changes['bookId'].currentValue) {
|
||||
this.loadReviews();
|
||||
}
|
||||
}
|
||||
|
||||
private subscribeToBookState(): void {
|
||||
this.bookService.bookState$
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(state => {
|
||||
if (state.books && this.bookId) {
|
||||
const book = state.books.find(b => b.id === this.bookId);
|
||||
this.reviewsLocked = book?.metadata?.reviewsLocked ?? false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private loadReviews(): void {
|
||||
if (this.loading || !this.bookId) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.loading = true;
|
||||
this.reviewService.getByBookId(this.bookId)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: (reviews) => {
|
||||
this.reviews = this.sortReviewsByDate(reviews || []);
|
||||
this.loading = false;
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to load reviews for bookId', this.bookId, ':', error);
|
||||
this.reviews = [];
|
||||
this.loading = false;
|
||||
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Failed to Load Reviews',
|
||||
detail: 'Could not load reviews for this book.',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fetchNewReviews(): void {
|
||||
if (!this.bookId || this.loading || this.reviewsLocked) return;
|
||||
|
||||
this.loading = true;
|
||||
this.revealedSpoilers.clear();
|
||||
|
||||
this.reviewService.refreshReviews(this.bookId)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: (reviews) => {
|
||||
this.reviews = this.sortReviewsByDate(reviews || []);
|
||||
this.loading = false;
|
||||
this.updateSpoilerState();
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Reviews Updated',
|
||||
detail: 'Latest reviews have been fetched successfully.',
|
||||
life: 3000
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to fetch new reviews:', error);
|
||||
this.loading = false;
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Fetch Failed',
|
||||
detail: 'Could not fetch new reviews for this book.',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
deleteAllReviews(): void {
|
||||
if (!this.reviews || this.reviews.length === 0 || this.reviewsLocked) return;
|
||||
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to delete all ${this.reviews.length} reviews for this book? This action cannot be undone.`,
|
||||
header: 'Confirm Delete All',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-trash',
|
||||
rejectIcon: 'pi pi-times',
|
||||
acceptButtonStyleClass: 'p-button-danger',
|
||||
accept: () => {
|
||||
if (!this.bookId) return;
|
||||
|
||||
this.reviewService.deleteAllByBookId(this.bookId).subscribe({
|
||||
next: () => {
|
||||
this.reviews = [];
|
||||
this.revealedSpoilers.clear();
|
||||
this.allSpoilersRevealed = false;
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'All Reviews Deleted',
|
||||
detail: 'All reviews have been successfully deleted.',
|
||||
life: 3000
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to delete all reviews:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Delete Failed',
|
||||
detail: 'Could not delete all reviews.',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleSpoilerVisibility(): void {
|
||||
if (this.allSpoilersRevealed) {
|
||||
this.hideAllSpoilers();
|
||||
} else {
|
||||
this.revealAllSpoilers();
|
||||
}
|
||||
}
|
||||
|
||||
hideAllSpoilers(): void {
|
||||
this.revealedSpoilers.clear();
|
||||
this.allSpoilersRevealed = false;
|
||||
}
|
||||
|
||||
revealAllSpoilers(): void {
|
||||
if (this.reviews) {
|
||||
this.reviews.forEach(review => {
|
||||
if (review.spoiler && review.id) {
|
||||
this.revealedSpoilers.add(review.id);
|
||||
}
|
||||
});
|
||||
this.allSpoilersRevealed = true;
|
||||
}
|
||||
}
|
||||
|
||||
toggleReviewsLock(): void {
|
||||
if (!this.bookId) return;
|
||||
|
||||
const newLockState = !this.reviewsLocked;
|
||||
const fieldActions: Record<string, 'LOCK' | 'UNLOCK'> = {
|
||||
'reviewsLocked': newLockState ? 'LOCK' : 'UNLOCK'
|
||||
};
|
||||
|
||||
this.bookService.toggleFieldLocks([this.bookId], fieldActions)
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe({
|
||||
next: () => {
|
||||
const action = newLockState ? 'locked' : 'unlocked';
|
||||
this.messageService.add({
|
||||
severity: 'info',
|
||||
summary: `Reviews ${action.charAt(0).toUpperCase() + action.slice(1)}`,
|
||||
detail: newLockState
|
||||
? 'Reviews are now protected from modifications and refreshes.'
|
||||
: 'Reviews can now be modified and refreshed.',
|
||||
life: 3000
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to toggle lock status:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Lock Toggle Failed',
|
||||
detail: 'Could not change the lock status for reviews.',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleSortOrder(): void {
|
||||
this.sortAscending = !this.sortAscending;
|
||||
if (this.reviews) {
|
||||
this.reviews = this.sortReviewsByDate([...this.reviews]);
|
||||
}
|
||||
}
|
||||
|
||||
private sortReviewsByDate(reviews: BookReview[]): BookReview[] {
|
||||
return reviews.sort((a, b) => {
|
||||
if (!a.date && !b.date) return 0;
|
||||
if (!a.date) return this.sortAscending ? -1 : 1;
|
||||
if (!b.date) return this.sortAscending ? 1 : -1;
|
||||
|
||||
const dateA = new Date(a.date).getTime();
|
||||
const dateB = new Date(b.date).getTime();
|
||||
|
||||
return this.sortAscending ? dateA - dateB : dateB - dateA;
|
||||
});
|
||||
}
|
||||
|
||||
private checkUserPermissions(): void {
|
||||
this.userService.userState$
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(userState => {
|
||||
this.hasPermission = userState?.user?.permissions?.admin ||
|
||||
userState?.user?.permissions?.canEditMetadata || false;
|
||||
});
|
||||
}
|
||||
|
||||
deleteReview(review: BookReview): void {
|
||||
if (!review.id || this.reviewsLocked) return;
|
||||
|
||||
this.confirmationService.confirm({
|
||||
message: `Are you sure you want to delete this review by ${review.reviewerName || 'Anonymous'}?`,
|
||||
header: 'Confirm Deletion',
|
||||
icon: 'pi pi-exclamation-triangle',
|
||||
acceptIcon: 'pi pi-trash',
|
||||
rejectIcon: 'pi pi-times',
|
||||
acceptButtonStyleClass: 'p-button-danger',
|
||||
accept: () => {
|
||||
this.reviewService.delete(review.id!).subscribe({
|
||||
next: () => {
|
||||
this.reviews = this.reviews?.filter(r => r.id !== review.id);
|
||||
this.updateSpoilerState();
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Review Deleted',
|
||||
detail: 'The review has been successfully deleted.',
|
||||
life: 2000
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error('Failed to delete review:', error);
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Delete Failed',
|
||||
detail: 'Could not delete the review.',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
revealSpoiler(reviewId: number): void {
|
||||
if (reviewId) {
|
||||
this.revealedSpoilers.add(reviewId);
|
||||
this.updateSpoilerState();
|
||||
}
|
||||
}
|
||||
|
||||
private updateSpoilerState(): void {
|
||||
const spoilerReviews = this.reviews?.filter(r => r.spoiler) || [];
|
||||
const revealedSpoilerReviews = spoilerReviews.filter(r => r.id && this.revealedSpoilers.has(r.id));
|
||||
this.allSpoilersRevealed = spoilerReviews.length > 0 && spoilerReviews.length === revealedSpoilerReviews.length;
|
||||
}
|
||||
|
||||
formatDate(dateString: string): string {
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric'
|
||||
});
|
||||
}
|
||||
|
||||
isSpoilerRevealed(reviewId: number): boolean {
|
||||
return this.revealedSpoilers.has(reviewId);
|
||||
}
|
||||
|
||||
private subscribeToAppSettings(): void {
|
||||
this.appSettingsService.appSettings$
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(settings => {
|
||||
this.reviewDownloadEnabled = settings?.metadataPublicReviewsSettings?.downloadEnabled ?? true;
|
||||
});
|
||||
}
|
||||
|
||||
getProviderSeverity(provider: string): 'success' | 'warn' {
|
||||
switch (provider?.toLowerCase()) {
|
||||
case 'amazon':
|
||||
return 'warn';
|
||||
default:
|
||||
return 'success';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import {Shelf} from './shelf.model';
|
||||
import {NewPdfReaderSetting} from '../../settings/user-management/user.service';
|
||||
import {BookReview} from '../../book-review-service';
|
||||
|
||||
export type BookType = "PDF" | "EPUB" | "CBX";
|
||||
|
||||
@@ -79,6 +80,7 @@ export interface BookMetadata {
|
||||
provider?: string;
|
||||
providerBookId?: string;
|
||||
thumbnailUrl?: string | null;
|
||||
reviews?: BookReview[];
|
||||
|
||||
titleLocked?: boolean;
|
||||
subtitleLocked?: boolean;
|
||||
@@ -108,6 +110,7 @@ export interface BookMetadata {
|
||||
authorsLocked?: boolean;
|
||||
categoriesLocked?: boolean;
|
||||
coverLocked?: boolean;
|
||||
reviewsLocked?: boolean;
|
||||
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
@@ -67,16 +67,29 @@ export interface Hardcover {
|
||||
enabled: boolean;
|
||||
apiKey: string;
|
||||
}
|
||||
|
||||
export interface Comicvine {
|
||||
enabled: boolean;
|
||||
apiKey: string;
|
||||
}
|
||||
|
||||
export interface MetadataPersistenceSettings {
|
||||
saveToOriginalFile: boolean;
|
||||
backupMetadata: boolean;
|
||||
backupCover: boolean;
|
||||
}
|
||||
|
||||
export interface ReviewProviderConfig {
|
||||
provider: string;
|
||||
enabled: boolean;
|
||||
maxReviews: number;
|
||||
}
|
||||
|
||||
export interface PublicReviewSettings {
|
||||
downloadEnabled: boolean;
|
||||
providers: ReviewProviderConfig[];
|
||||
}
|
||||
|
||||
export interface AppSettings {
|
||||
autoBookSearch: boolean;
|
||||
similarBookRecommendation: boolean;
|
||||
@@ -93,6 +106,7 @@ export interface AppSettings {
|
||||
metadataProviderSettings: MetadataProviderSettings;
|
||||
metadataMatchWeights: MetadataMatchWeights;
|
||||
metadataPersistenceSettings: MetadataPersistenceSettings;
|
||||
metadataPublicReviewsSettings: PublicReviewSettings;
|
||||
metadataDownloadOnBookdrop: boolean;
|
||||
}
|
||||
|
||||
@@ -111,5 +125,6 @@ export enum AppSettingKey {
|
||||
METADATA_PROVIDER_SETTINGS = 'METADATA_PROVIDER_SETTINGS',
|
||||
METADATA_MATCH_WEIGHTS = 'METADATA_MATCH_WEIGHTS',
|
||||
METADATA_PERSISTENCE_SETTINGS = 'METADATA_PERSISTENCE_SETTINGS',
|
||||
METADATA_DOWNLOAD_ON_BOOKDROP = 'METADATA_DOWNLOAD_ON_BOOKDROP'
|
||||
METADATA_DOWNLOAD_ON_BOOKDROP = 'METADATA_DOWNLOAD_ON_BOOKDROP',
|
||||
METADATA_PUBLIC_REVIEWS_SETTINGS = 'METADATA_PUBLIC_REVIEWS_SETTINGS'
|
||||
}
|
||||
|
||||
@@ -22,6 +22,40 @@ export class AppConfigService {
|
||||
private initialized = false;
|
||||
|
||||
readonly surfaces: Palette[] = [
|
||||
{
|
||||
name: 'slate',
|
||||
palette: {
|
||||
0: '#ffffff',
|
||||
50: '#f8fafc',
|
||||
100: '#f1f5f9',
|
||||
200: '#e2e8f0',
|
||||
300: '#cbd5e1',
|
||||
400: '#94a3b8',
|
||||
500: '#64748b',
|
||||
600: '#475569',
|
||||
700: '#334155',
|
||||
800: '#1e293b',
|
||||
900: '#0f172a',
|
||||
950: '#020617'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'gray',
|
||||
palette: {
|
||||
0: '#ffffff',
|
||||
50: '#fafafa',
|
||||
100: '#f4f4f5',
|
||||
200: '#e4e4e7',
|
||||
300: '#d4d4d8',
|
||||
400: '#a1a1aa',
|
||||
500: '#71717a',
|
||||
600: '#52525b',
|
||||
700: '#3f3f46',
|
||||
800: '#27272a',
|
||||
900: '#18181b',
|
||||
950: '#09090b'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'neutral',
|
||||
palette: {
|
||||
|
||||
@@ -20,11 +20,9 @@ export class AuthService {
|
||||
private oAuthService = inject(OAuthService);
|
||||
private router = inject(Router);
|
||||
|
||||
private tokenSubject = new BehaviorSubject<string | null>(this.getOidcAccessToken() || this.getInternalAccessToken());
|
||||
public tokenSubject = new BehaviorSubject<string | null>(this.getOidcAccessToken() || this.getInternalAccessToken());
|
||||
public token$ = this.tokenSubject.asObservable();
|
||||
|
||||
private logoutSubject = new Subject<void>();
|
||||
public logout$ = this.logoutSubject.asObservable();
|
||||
|
||||
internalLogin(credentials: { username: string; password: string }): Observable<{ accessToken: string; refreshToken: string, isDefaultPassword: string }> {
|
||||
return this.http.post<{ accessToken: string; refreshToken: string, isDefaultPassword: string }>(`${this.apiUrl}/login`, credentials).pipe(
|
||||
@@ -48,17 +46,6 @@ export class AuthService {
|
||||
);
|
||||
}
|
||||
|
||||
remoteLogin(): Observable<{ accessToken: string; refreshToken: string, isDefaultPassword: string }> {
|
||||
return this.http.get<{ accessToken: string; refreshToken: string, isDefaultPassword: string }>(`${this.apiUrl}/remote`).pipe(
|
||||
tap((response) => {
|
||||
if (response.accessToken && response.refreshToken) {
|
||||
this.saveInternalTokens(response.accessToken, response.refreshToken);
|
||||
this.initializeWebSocketConnection();
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
saveInternalTokens(accessToken: string, refreshToken: string): void {
|
||||
localStorage.setItem('accessToken_Internal', accessToken);
|
||||
localStorage.setItem('refreshToken_Internal', refreshToken);
|
||||
@@ -81,13 +68,8 @@ export class AuthService {
|
||||
localStorage.removeItem('accessToken_Internal');
|
||||
localStorage.removeItem('refreshToken_Internal');
|
||||
this.tokenSubject.next(null);
|
||||
this.logoutSubject.next();
|
||||
this.getRxStompService().deactivate();
|
||||
if (this.oAuthService.clientId) {
|
||||
this.oAuthService.logOut();
|
||||
} else {
|
||||
this.router.navigate(['/login']);
|
||||
}
|
||||
this.router.navigate(['/login']);
|
||||
}
|
||||
|
||||
getRxStompService(): RxStompService {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import {Injectable, inject} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../config/api-config';
|
||||
|
||||
export interface BookNote {
|
||||
id: number;
|
||||
userId: number;
|
||||
bookId: number;
|
||||
title: string;
|
||||
content: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface CreateBookNoteRequest {
|
||||
id?: number;
|
||||
bookId: number;
|
||||
title: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class BookNoteService {
|
||||
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/book-notes`;
|
||||
private readonly http = inject(HttpClient);
|
||||
|
||||
getNotesForBook(bookId: number): Observable<BookNote[]> {
|
||||
return this.http.get<BookNote[]>(`${this.url}/book/${bookId}`);
|
||||
}
|
||||
|
||||
createOrUpdateNote(request: CreateBookNoteRequest): Observable<BookNote> {
|
||||
return this.http.post<BookNote>(this.url, request);
|
||||
}
|
||||
|
||||
deleteNote(noteId: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.url}/${noteId}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import {Injectable, inject} from '@angular/core';
|
||||
import {AppSettingsService} from './app-settings.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Observable} from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SettingsHelperService {
|
||||
|
||||
private readonly appSettingsService = inject(AppSettingsService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
|
||||
saveSetting(key: string, value: unknown): Observable<void> {
|
||||
const observable = this.appSettingsService.saveSettings([{key, newValue: value}]);
|
||||
|
||||
observable.subscribe({
|
||||
next: () => this.showSuccessMessage(),
|
||||
error: (error) => {
|
||||
console.error('Failed to save setting:', error);
|
||||
this.showErrorMessage();
|
||||
}
|
||||
});
|
||||
|
||||
return observable;
|
||||
}
|
||||
|
||||
saveMultipleSettings(settings: { key: string, newValue: unknown }[]): Observable<void> {
|
||||
const observable = this.appSettingsService.saveSettings(settings);
|
||||
observable.subscribe({
|
||||
next: () => this.showSuccessMessage(),
|
||||
error: (error) => {
|
||||
console.error('Failed to save settings:', error);
|
||||
this.showErrorMessage();
|
||||
}
|
||||
});
|
||||
return observable;
|
||||
}
|
||||
|
||||
private showSuccessMessage(): void {
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Settings Saved',
|
||||
detail: 'The settings were successfully saved!'
|
||||
});
|
||||
}
|
||||
|
||||
private showErrorMessage(): void {
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'There was an error saving the settings.'
|
||||
});
|
||||
}
|
||||
|
||||
showMessage(severity: 'success' | 'error', summary: string, detail: string): void {
|
||||
this.messageService.add({severity, summary, detail});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { AuthService } from './auth.service';
|
||||
import { UserService } from '../../settings/user-management/user.service';
|
||||
import { filter, catchError } from 'rxjs/operators';
|
||||
import { of } from 'rxjs';
|
||||
import {Injectable, inject} from '@angular/core';
|
||||
import {AuthService} from './auth.service';
|
||||
import {UserService} from '../../settings/user-management/user.service';
|
||||
import {filter, catchError} from 'rxjs/operators';
|
||||
import {of} from 'rxjs';
|
||||
import {OAuthService} from 'angular-oauth2-oidc';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class StartupService {
|
||||
private auth = inject(AuthService);
|
||||
private userSvc = inject(UserService);
|
||||
private authService = inject(AuthService);
|
||||
private userService = inject(UserService);
|
||||
|
||||
load(): Promise<void> {
|
||||
this.auth.token$
|
||||
this.authService.token$
|
||||
.pipe(filter(t => !!t))
|
||||
.subscribe(() => {
|
||||
this.userSvc.getMyself()
|
||||
this.userService.getMyself()
|
||||
.pipe(catchError(() => of(null)))
|
||||
.subscribe(user => {
|
||||
if (user) {
|
||||
this.userSvc.setInitialUser(user);
|
||||
this.userService.setInitialUser(user);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
+35
-27
@@ -1,30 +1,38 @@
|
||||
<p class="dashboard-scroller-title">{{ title }}</p>
|
||||
<div class="dashboard-scroller-container">
|
||||
<h2 class="dashboard-scroller-title">{{ title }}</h2>
|
||||
|
||||
@if (!books || books.length === 0) {
|
||||
<div class="dashboard-scroller-no-books">
|
||||
<p class="text-sm">
|
||||
{{ bookListType === 'lastRead' ? "You haven't read any books yet!" : "No books have been added to BookLore!" }}
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (books) {
|
||||
<div class="dashboard-scroller-infinite"
|
||||
infiniteScroll
|
||||
[infiniteScrollDistance]="2"
|
||||
[infiniteScrollThrottle]="50"
|
||||
#scrollContainer
|
||||
[horizontal]="true">
|
||||
@for (book of books; track book) {
|
||||
<div class="dashboard-scroller-card">
|
||||
<app-book-card [book]="book" [isCheckboxEnabled]="false"></app-book-card>
|
||||
@if (!books || books.length === 0) {
|
||||
<div class="dashboard-scroller-no-books">
|
||||
<div class="empty-state-icon">
|
||||
<i class="pi pi-book"></i>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
<p>
|
||||
{{ bookListType === 'lastRead' ? "You haven't read any books yet! Start your reading journey." : "No books have been added to BookLore yet! Add your first book to get started." }}
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if ( books === null) {
|
||||
<div>
|
||||
<p class="text-sm">Failed to load books! :(</p>
|
||||
</div>
|
||||
}
|
||||
@if (books) {
|
||||
<div class="dashboard-scroller-infinite"
|
||||
infiniteScroll
|
||||
[infiniteScrollDistance]="2"
|
||||
[infiniteScrollThrottle]="50"
|
||||
#scrollContainer
|
||||
[horizontal]="true">
|
||||
@for (book of books; track book) {
|
||||
<div class="dashboard-scroller-card">
|
||||
<app-book-card [book]="book" [isCheckboxEnabled]="false"></app-book-card>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (books === null) {
|
||||
<div class="dashboard-scroller-error">
|
||||
<div class="error-icon">
|
||||
<i class="pi pi-exclamation-triangle"></i>
|
||||
</div>
|
||||
<p>Failed to load books! Please try refreshing the page.</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
+161
-16
@@ -1,16 +1,74 @@
|
||||
.dashboard-scroller-container {
|
||||
border-radius: 20px;
|
||||
padding: 1rem 2rem 0rem 2rem;
|
||||
margin-bottom: 2rem;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
backdrop-filter: blur(20px);
|
||||
border: color-mix(in srgb, var(--p-surface-500), transparent 50%) 1px solid;
|
||||
}
|
||||
|
||||
.dashboard-scroller-title {
|
||||
text-align: left;
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: 0.625rem;
|
||||
padding: 0.3125rem;
|
||||
font-weight: 800;
|
||||
margin-bottom: 1rem;
|
||||
padding: 0;
|
||||
background: linear-gradient(135deg, #ffffff, #e2e8f0, #3b82f6);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
letter-spacing: -0.02em;
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: -6px;
|
||||
left: 0;
|
||||
width: 80px;
|
||||
height: 4px;
|
||||
background: linear-gradient(90deg, var(--primary-color), var(--primary-color));
|
||||
border-radius: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.dashboard-scroller-no-books {
|
||||
padding-top: 5rem;
|
||||
padding-bottom: 5rem;
|
||||
padding: 3rem 2rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
|
||||
.empty-state-icon {
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 2rem;
|
||||
position: relative;
|
||||
|
||||
i {
|
||||
font-size: 2rem;
|
||||
color: white;
|
||||
filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
|
||||
}
|
||||
}
|
||||
|
||||
p {
|
||||
color: #e2e8f0;
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
max-width: 400px;
|
||||
line-height: 1.7;
|
||||
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
.dashboard-scroller-infinite {
|
||||
@@ -18,35 +76,122 @@
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
scroll-snap-type: x mandatory;
|
||||
padding: 0.25rem;
|
||||
gap: 1.25rem;
|
||||
padding: 1rem 0.5rem 1rem 0.5rem;
|
||||
gap: 2rem;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
|
||||
scrollbar-color: var(--primary-color) rgba(20, 20, 30, 0.5);
|
||||
}
|
||||
|
||||
.dashboard-scroller-card {
|
||||
height: 220px;
|
||||
width: 135px;
|
||||
height: 200px;
|
||||
width: 116px;
|
||||
flex-basis: 124px;
|
||||
flex-shrink: 0;
|
||||
flex-grow: 0;
|
||||
flex-basis: 135px;
|
||||
scroll-snap-align: start;
|
||||
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
position: relative;
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-4px) scale(1.04);
|
||||
filter: drop-shadow(0 25px 50px rgba(0, 0, 0, 0.4));
|
||||
|
||||
&::after {
|
||||
opacity: 1;
|
||||
transform: scale(1.2);
|
||||
}
|
||||
|
||||
&::before {
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: -2px;
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
color-mix(in srgb, var(--p-primary-400), transparent 70%),
|
||||
color-mix(in srgb, var(--p-primary-800), transparent 70%)
|
||||
);
|
||||
border-radius: 12px;
|
||||
z-index: -1;
|
||||
opacity: 0;
|
||||
transition: opacity 0.4s ease;
|
||||
filter: blur(8px);
|
||||
}
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: -12px;
|
||||
left: 15%;
|
||||
right: 15%;
|
||||
height: 5px;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
var(--p-primary-500),
|
||||
transparent
|
||||
);
|
||||
border-radius: 50%;
|
||||
opacity: 0;
|
||||
transition: all 0.4s ease;
|
||||
filter: blur(6px);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.dashboard-scroller-container {
|
||||
padding: 1.5rem;
|
||||
margin-bottom: 2rem;
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
.dashboard-scroller-title {
|
||||
font-size: 1.25rem;
|
||||
padding: 0.25rem;
|
||||
font-size: 1.75rem;
|
||||
margin-bottom: 1rem;
|
||||
|
||||
&::after {
|
||||
width: 50px;
|
||||
height: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
.dashboard-scroller-card {
|
||||
height: 200px;
|
||||
width: 120px;
|
||||
flex-basis: 110px;
|
||||
height: 230px;
|
||||
width: 135px;
|
||||
flex-basis: 135px;
|
||||
}
|
||||
|
||||
.dashboard-scroller-infinite {
|
||||
gap: 1rem;
|
||||
padding: 0.25rem 0.5rem;
|
||||
gap: 1.5rem;
|
||||
padding: 0.75rem 0.25rem 1.5rem 0.25rem;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
height: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.dashboard-scroller-no-books {
|
||||
padding: 4rem 1rem;
|
||||
|
||||
.empty-state-icon {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
|
||||
i {
|
||||
font-size: 2rem;
|
||||
}
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -13,7 +13,7 @@ import {Book} from '../../../book/model/book.model';
|
||||
InfiniteScrollDirective,
|
||||
BookCardComponent,
|
||||
ProgressSpinnerModule
|
||||
],
|
||||
],
|
||||
standalone: true
|
||||
})
|
||||
export class DashboardScrollerComponent {
|
||||
@@ -23,5 +23,4 @@ export class DashboardScrollerComponent {
|
||||
@Input() books!: Book[] | null;
|
||||
|
||||
@ViewChild('scrollContainer') scrollContainer!: ElementRef;
|
||||
|
||||
}
|
||||
|
||||
+23
-13
@@ -1,19 +1,33 @@
|
||||
<div class="dashboard-container">
|
||||
@if ((bookState$ | async)?.loaded === false) {
|
||||
<p-progressSpinner styleClass="spinner center-spinner"></p-progressSpinner>
|
||||
<div class="flex items-center justify-center h-full">
|
||||
<p-progressSpinner
|
||||
styleClass="spinner center-spinner"
|
||||
[style]="{'width': '60px', 'height': '60px'}"
|
||||
strokeWidth="3"
|
||||
fill="transparent"
|
||||
animationDuration="1.5s">
|
||||
</p-progressSpinner>
|
||||
</div>
|
||||
}
|
||||
@if ((bookState$ | async)?.loaded === true) {
|
||||
<div class="dashboard">
|
||||
<div>
|
||||
<div class="w-full">
|
||||
@if (isLibrariesEmpty$ | async) {
|
||||
<div class="dashboard-no-library">
|
||||
@if ((userService.userState$ | async)?.user?.permissions; as permissions) {
|
||||
<div>
|
||||
@if (permissions.admin || permissions.canManipulateLibrary) {
|
||||
<div>
|
||||
<h1 class="no-library-header">Looks like you haven't added a library yet. Let's add one!</h1>
|
||||
<h1 class="no-library-header">
|
||||
Welcome to BookLore! 📚<br>
|
||||
Let's create your first library
|
||||
</h1>
|
||||
<p class="text-gray-300 text-lg mb-8 max-w-md mx-auto leading-relaxed">
|
||||
A library is where all your books live. Start building your digital collection today!
|
||||
</p>
|
||||
<p-button
|
||||
label="Add a Library"
|
||||
label="Create Your Library"
|
||||
icon="pi pi-plus"
|
||||
styleClass="p-button-rounded p-button-outlined"
|
||||
(click)="createNewLibrary()">
|
||||
@@ -27,21 +41,17 @@
|
||||
<app-dashboard-scroller
|
||||
[books]="lastReadBooks$ | async"
|
||||
[bookListType]="'lastRead'"
|
||||
[title]="'Last Read Books'">
|
||||
[title]="'Continue Reading'">
|
||||
</app-dashboard-scroller>
|
||||
<div class="mb-6">
|
||||
<p-divider></p-divider>
|
||||
</div>
|
||||
|
||||
<app-dashboard-scroller
|
||||
[books]="latestAddedBooks$ | async"
|
||||
[title]="'Latest Added Books'">
|
||||
[title]="'Recently Added'">
|
||||
</app-dashboard-scroller>
|
||||
<div class="mb-6">
|
||||
<p-divider></p-divider>
|
||||
</div>
|
||||
|
||||
<app-dashboard-scroller
|
||||
[books]="randomBooks$ | async"
|
||||
[title]="'Discover Random Reads'">
|
||||
[title]="'Discover Something New'">
|
||||
</app-dashboard-scroller>
|
||||
}
|
||||
</div>
|
||||
|
||||
+46
-5
@@ -1,11 +1,39 @@
|
||||
.dashboard-container {
|
||||
height: calc(100dvh - 6.7rem);
|
||||
overflow-y: auto;
|
||||
position: relative;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
pointer-events: none;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: rgba(20, 20, 30, 0.5);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: var(--primary-color) rgba(20, 20, 30, 0.5);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.dashboard-container {
|
||||
height: calc(100dvh - 5rem);
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,17 +42,30 @@
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.dashboard .no-library-header {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 1rem;
|
||||
color: var(--text-color);
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
margin-bottom: 2rem;
|
||||
background: linear-gradient(135deg, #ffffff, #e2e8f0, var(--p-primary-500));
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.dashboard-no-library {
|
||||
margin-top: 3rem;
|
||||
padding: 3rem;
|
||||
background: var(--p-surface-900);
|
||||
border-radius: 24px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
backdrop-filter: blur(20px);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.dashboard .p-dialog {
|
||||
|
||||
@@ -2,15 +2,14 @@ import {Component, inject, OnInit} from '@angular/core';
|
||||
import {LibraryCreatorComponent} from '../../../book/components/library-creator/library-creator.component';
|
||||
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {LibraryService} from '../../../book/service/library.service';
|
||||
import {filter, Observable, take} from 'rxjs';
|
||||
import {Observable} from 'rxjs';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {Button} from 'primeng/button';
|
||||
import { AsyncPipe } from '@angular/common';
|
||||
import {AsyncPipe} from '@angular/common';
|
||||
import {DashboardScrollerComponent} from '../dashboard-scroller/dashboard-scroller.component';
|
||||
import {BookService} from '../../../book/service/book.service';
|
||||
import {BookState} from '../../../book/model/state/book-state.model';
|
||||
import {Book} from '../../../book/model/book.model';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
|
||||
@@ -22,9 +21,8 @@ import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
Button,
|
||||
DashboardScrollerComponent,
|
||||
AsyncPipe,
|
||||
Divider,
|
||||
ProgressSpinner
|
||||
],
|
||||
],
|
||||
providers: [DialogService],
|
||||
standalone: true
|
||||
})
|
||||
|
||||
+60
-35
@@ -465,10 +465,10 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="px-4 pb-2 pt-4 border border-[var(--border-color)] rounded-xl">
|
||||
<div class="px-4 pb-2 pt-4 mb-6 mx-2 border border-[var(--border-color)] rounded-xl">
|
||||
<div [ngClass]="{ 'line-clamp-5': !isExpanded, 'line-clamp-none': isExpanded }" class="transition-all duration-300 overflow-hidden description-container">
|
||||
<div class="readonly-editor px-2">
|
||||
<p-editor #quillEditor [readonly]="true" [style]="{height: '225px'}" [(ngModel)]="book.metadata!.description">
|
||||
<p-editor #quillEditor [readonly]="true" [style]="{height: '200px'}" [(ngModel)]="book.metadata!.description">
|
||||
<ng-template #header>
|
||||
</ng-template>
|
||||
</p-editor>
|
||||
@@ -486,44 +486,69 @@
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="pt-4 space-y-4 pb-6">
|
||||
@if (bookInSeries.length > 0) {
|
||||
<div>
|
||||
<h3 class="text-xl font-semibold pt-2">More in the Series</h3>
|
||||
<div class="dashboard-scroller-infinite"
|
||||
infiniteScroll
|
||||
[infiniteScrollDistance]="2"
|
||||
[infiniteScrollThrottle]="50"
|
||||
[horizontal]="true">
|
||||
@for (book of bookInSeries; track book) {
|
||||
<div class="dashboard-scroller-card">
|
||||
<app-book-card-lite-component
|
||||
[book]="book"
|
||||
></app-book-card-lite-component>
|
||||
<p-tabs lazy="true" class="custom-p-tabs" [value]="defaultTabValue" scrollable>
|
||||
<p-tablist>
|
||||
@if (bookInSeries.length > 0) {
|
||||
<p-tab [value]="1">
|
||||
<i class="pi pi-ethereum"></i> More in Series
|
||||
</p-tab>
|
||||
}
|
||||
<p-tab [value]="2">
|
||||
<i class="pi pi-bookmark"></i> Similar Books
|
||||
</p-tab>
|
||||
<p-tab [value]="3">
|
||||
<i class="pi pi-pen-to-square"></i> Notes
|
||||
</p-tab>
|
||||
<p-tab [value]="4">
|
||||
<i class="pi pi-comments"></i> Reviews
|
||||
</p-tab>
|
||||
</p-tablist>
|
||||
<p-tabpanels>
|
||||
<p-tabpanel [value]="1">
|
||||
<div class="pt-2">
|
||||
@if (bookInSeries.length > 0) {
|
||||
<div>
|
||||
<div class="dashboard-scroller-infinite"
|
||||
infiniteScroll
|
||||
[infiniteScrollDistance]="2"
|
||||
[infiniteScrollThrottle]="50"
|
||||
[horizontal]="true">
|
||||
@for (book of bookInSeries; track book) {
|
||||
<div class="dashboard-scroller-card">
|
||||
<app-book-card-lite-component [book]="book"></app-book-card-lite-component>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p-divider></p-divider>
|
||||
}
|
||||
@if (recommendedBooks.length > 0) {
|
||||
<div>
|
||||
<h3 class="text-xl font-semibold">Similar Books</h3>
|
||||
<div class="dashboard-scroller-infinite"
|
||||
infiniteScroll
|
||||
[infiniteScrollDistance]="2"
|
||||
[infiniteScrollThrottle]="50"
|
||||
[horizontal]="true">
|
||||
@for (book of recommendedBooks; track book) {
|
||||
<div class="dashboard-scroller-card">
|
||||
<app-book-card-lite-component
|
||||
[book]="book.book"
|
||||
></app-book-card-lite-component>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="2">
|
||||
<div class="pt-2">
|
||||
@if (recommendedBooks.length > 0) {
|
||||
<div>
|
||||
<div class="dashboard-scroller-infinite"
|
||||
infiniteScroll
|
||||
[infiniteScrollDistance]="2"
|
||||
[infiniteScrollThrottle]="50"
|
||||
[horizontal]="true">
|
||||
@for (book of recommendedBooks; track book) {
|
||||
<div class="dashboard-scroller-card">
|
||||
<app-book-card-lite-component [book]="book.book"></app-book-card-lite-component>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="3">
|
||||
<app-book-notes-component [bookId]="book.id"></app-book-notes-component>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="4">
|
||||
<app-book-reviews [bookId]="book.id"></app-book-reviews>
|
||||
</p-tabpanel>
|
||||
</p-tabpanels>
|
||||
</p-tabs>
|
||||
}
|
||||
</div>
|
||||
|
||||
+10
-3
@@ -46,14 +46,14 @@
|
||||
}
|
||||
|
||||
.dashboard-scroller-card {
|
||||
width: 101px;
|
||||
width: 115px;
|
||||
flex-shrink: 0;
|
||||
flex-grow: 0;
|
||||
flex-basis: 101px;
|
||||
flex-basis: 115px;
|
||||
}
|
||||
|
||||
.description-container {
|
||||
max-height: 58px;
|
||||
max-height: 60px;
|
||||
overflow: hidden;
|
||||
transition: max-height 0.3s ease-in-out;
|
||||
}
|
||||
@@ -104,6 +104,13 @@
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.custom-p-tabs > .p-tabpanels {
|
||||
padding-top: 10px !important;
|
||||
padding-bottom: 0 !important;
|
||||
padding-left: 0 !important;
|
||||
padding-right: 0 !important;
|
||||
}
|
||||
|
||||
::ng-deep .p-inputchips {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
+10
-4
@@ -7,7 +7,6 @@ import {Rating, RatingRateEvent} from 'primeng/rating';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Tag} from 'primeng/tag';
|
||||
import {Book, BookMetadata, BookRecommendation, ReadStatus} from '../../../book/model/book.model';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {UrlHelperService} from '../../../utilities/service/url-helper.service';
|
||||
import {UserService} from '../../../settings/user-management/user.service';
|
||||
import {SplitButton} from 'primeng/splitbutton';
|
||||
@@ -30,13 +29,16 @@ import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
|
||||
import {BookCardLiteComponent} from '../../../book/components/book-card-lite/book-card-lite-component';
|
||||
import {ResetProgressType, ResetProgressTypes} from '../../../shared/constants/reset-progress-type';
|
||||
import {DatePicker} from 'primeng/datepicker';
|
||||
import {Tab, TabList, TabPanel, TabPanels, Tabs} from 'primeng/tabs';
|
||||
import {BookReviewsComponent} from '../../../book/components/book-reviews/book-reviews.component';
|
||||
import {BookNotesComponent} from '../../../book/components/book-notes-component/book-notes-component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-viewer',
|
||||
standalone: true,
|
||||
templateUrl: './metadata-viewer.component.html',
|
||||
styleUrl: './metadata-viewer.component.scss',
|
||||
imports: [Button, AsyncPipe, Rating, FormsModule, Tag, Divider, SplitButton, NgClass, Tooltip, DecimalPipe, Editor, ProgressBar, Menu, InfiniteScrollDirective, BookCardLiteComponent, DatePicker]
|
||||
imports: [Button, AsyncPipe, Rating, FormsModule, Tag, SplitButton, NgClass, Tooltip, DecimalPipe, Editor, ProgressBar, Menu, InfiniteScrollDirective, BookCardLiteComponent, DatePicker, Tab, TabList, TabPanel, TabPanels, Tabs, BookReviewsComponent, BookNotesComponent]
|
||||
})
|
||||
export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
@Input() book$!: Observable<Book | null>;
|
||||
@@ -221,6 +223,10 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
);
|
||||
}
|
||||
|
||||
get defaultTabValue(): number {
|
||||
return this.bookInSeries && this.bookInSeries.length > 0 ? 1 : 2;
|
||||
}
|
||||
|
||||
toggleExpand(): void {
|
||||
this.isExpanded = !this.isExpanded;
|
||||
}
|
||||
@@ -607,9 +613,9 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
|
||||
saveDateFinished(book: Book): void {
|
||||
if (!book) return;
|
||||
|
||||
|
||||
const dateToSave = this.editDateFinished ? this.editDateFinished.toISOString() : null;
|
||||
|
||||
|
||||
this.bookService.updateDateFinished(book.id, dateToSave).subscribe({
|
||||
next: () => {
|
||||
this.messageService.add({
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<div class="p-4 min-w-[50rem]">
|
||||
<p class="text-lg pb-4 pt-2">Metadata Persistence:</p>
|
||||
<div class="flex flex-col gap-4 pl-6 ">
|
||||
|
||||
<div class="pl-4 md:pl-6 border-l-2 border-zinc-600">
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="flex items-center gap-4">
|
||||
<label>Write to File</label>
|
||||
<p-toggleswitch
|
||||
[ngModel]="metadataPersistence.saveToOriginalFile"
|
||||
(onChange)="onPersistenceToggle('saveToOriginalFile')">
|
||||
</p-toggleswitch>
|
||||
<div class="text-sm text-gray-400 flex items-start gap-2">
|
||||
<i class="pi pi-exclamation-triangle text-yellow-500 mt-0.5"></i>
|
||||
<span>
|
||||
Writes metadata directly into the original file. A backup of the metadata and/or cover is created <b>only if enabled below</b>. Proceed with caution, restoration may fail if the file is moved or renamed.
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-4">
|
||||
<label>Backup Metadata</label>
|
||||
<p-toggleswitch
|
||||
[ngModel]="metadataPersistence.backupMetadata"
|
||||
(onChange)="onPersistenceToggle('backupMetadata')"
|
||||
[disabled]="!metadataPersistence.saveToOriginalFile">
|
||||
</p-toggleswitch>
|
||||
<span class="text-sm text-gray-400">
|
||||
Save a JSON copy of the current metadata before writing new data to the file.
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<label>Backup Cover</label>
|
||||
<p-toggleswitch
|
||||
[ngModel]="metadataPersistence.backupCover"
|
||||
(onChange)="onPersistenceToggle('backupCover')"
|
||||
[disabled]="!metadataPersistence.saveToOriginalFile">
|
||||
</p-toggleswitch>
|
||||
<span class="text-sm text-gray-400">
|
||||
Save a copy of the existing embedded cover image before it is replaced.
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
.enclosing-container {
|
||||
border-color: var(--p-content-border-color);
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {AppSettingKey, AppSettings, MetadataPersistenceSettings} from '../../../core/model/app-settings.model';
|
||||
import {AppSettingsService} from '../../../core/service/app-settings.service';
|
||||
import {SettingsHelperService} from '../../../core/service/settings-helper.service';
|
||||
import {Observable} from 'rxjs';
|
||||
import {filter, take} from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-persistence-settings-component',
|
||||
imports: [
|
||||
ToggleSwitch,
|
||||
FormsModule
|
||||
],
|
||||
templateUrl: './metadata-persistence-settings-component.html',
|
||||
styleUrl: './metadata-persistence-settings-component.scss'
|
||||
})
|
||||
export class MetadataPersistenceSettingsComponent implements OnInit {
|
||||
|
||||
metadataPersistence: MetadataPersistenceSettings = {
|
||||
saveToOriginalFile: false,
|
||||
backupMetadata: true,
|
||||
backupCover: true
|
||||
};
|
||||
|
||||
private readonly appSettingsService = inject(AppSettingsService);
|
||||
private readonly settingsHelper = inject(SettingsHelperService);
|
||||
|
||||
readonly appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadSettings();
|
||||
}
|
||||
|
||||
onPersistenceToggle(key: keyof MetadataPersistenceSettings): void {
|
||||
this.updatePersistenceSettings(key);
|
||||
this.settingsHelper.saveSetting(AppSettingKey.METADATA_PERSISTENCE_SETTINGS, this.metadataPersistence);
|
||||
}
|
||||
|
||||
private loadSettings(): void {
|
||||
this.appSettings$.pipe(
|
||||
filter((settings): settings is AppSettings => !!settings),
|
||||
take(1)
|
||||
).subscribe({
|
||||
next: (settings) => this.initializeSettings(settings),
|
||||
error: (error) => {
|
||||
console.error('Failed to load settings:', error);
|
||||
this.settingsHelper.showMessage('error', 'Error', 'Failed to load settings.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private initializeSettings(settings: AppSettings): void {
|
||||
if (settings.metadataPersistenceSettings) {
|
||||
this.metadataPersistence = {...settings.metadataPersistenceSettings};
|
||||
}
|
||||
}
|
||||
|
||||
private updatePersistenceSettings(key: keyof MetadataPersistenceSettings): void {
|
||||
if (key === 'saveToOriginalFile') {
|
||||
this.metadataPersistence.saveToOriginalFile = !this.metadataPersistence.saveToOriginalFile;
|
||||
|
||||
if (!this.metadataPersistence.saveToOriginalFile) {
|
||||
this.metadataPersistence.backupMetadata = false;
|
||||
this.metadataPersistence.backupCover = false;
|
||||
}
|
||||
} else {
|
||||
this.metadataPersistence[key] = !this.metadataPersistence[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
-47
@@ -2,9 +2,7 @@
|
||||
|
||||
<div class="p-4 pt-6 min-w-[50rem]">
|
||||
<p class="text-lg pb-4 pt-2">Auto-Download Metadata for Files in BookDrop Folder:</p>
|
||||
|
||||
<div class="flex flex-col gap-4 pl-6">
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="metadataDownloadOnBookdrop"
|
||||
@@ -24,50 +22,8 @@
|
||||
<p-divider></p-divider>
|
||||
</div>
|
||||
|
||||
<div class="p-4 pt-6 min-w-[50rem]">
|
||||
<p class="text-lg pb-4 pt-2">Metadata Persistence:</p>
|
||||
|
||||
<div class="flex flex-col gap-4 pl-6">
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<label>Write to File</label>
|
||||
<p-toggleswitch
|
||||
[ngModel]="metadataPersistence.saveToOriginalFile"
|
||||
(onChange)="onPersistenceToggle('saveToOriginalFile')">
|
||||
</p-toggleswitch>
|
||||
<div class="text-sm text-gray-400 flex items-start gap-2">
|
||||
<i class="pi pi-exclamation-triangle text-yellow-500 mt-0.5"></i>
|
||||
<span>
|
||||
Writes metadata directly into the original file. A backup of the metadata and/or cover is created <b>only if enabled below</b>. Proceed with caution, restoration may fail if the file is moved or renamed.
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<label>Backup Metadata</label>
|
||||
<p-toggleswitch
|
||||
[ngModel]="metadataPersistence.backupMetadata"
|
||||
(onChange)="onPersistenceToggle('backupMetadata')"
|
||||
[disabled]="!metadataPersistence.saveToOriginalFile">
|
||||
</p-toggleswitch>
|
||||
<span class="text-sm text-gray-400">
|
||||
Save a JSON copy of the current metadata before writing new data to the file.
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<label>Backup Cover</label>
|
||||
<p-toggleswitch
|
||||
[ngModel]="metadataPersistence.backupCover"
|
||||
(onChange)="onPersistenceToggle('backupCover')"
|
||||
[disabled]="!metadataPersistence.saveToOriginalFile">
|
||||
</p-toggleswitch>
|
||||
<span class="text-sm text-gray-400">
|
||||
Save a copy of the existing embedded cover image before it is replaced.
|
||||
</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div>
|
||||
<app-metadata-persistence-settings-component></app-metadata-persistence-settings-component>
|
||||
</div>
|
||||
|
||||
<div class="pb-4">
|
||||
@@ -82,11 +38,19 @@
|
||||
<p-divider></p-divider>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<app-public-reviews-settings-component></app-public-reviews-settings-component>
|
||||
</div>
|
||||
|
||||
<div class="pb-4">
|
||||
<p-divider></p-divider>
|
||||
</div>
|
||||
|
||||
<div class="p-4">
|
||||
<p class="text-lg ">
|
||||
Quick Book Match Preferences
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Choose how metadata fields (title, description, authors, categories, cover) are retrieved by setting priority providers. You can apply the same provider settings to all fields or customize them individually. Enable ‘Refresh Covers’ to update book covers, and ‘Merge Categories’ to consolidate categories/genres from all sources while preserving the existing categories/genres in the book."
|
||||
pTooltip="Choose how metadata fields (title, description, authors, categories, cover) are retrieved by setting priority providers. You can apply the same provider settings to all fields or customize them individually. Enable 'Refresh Covers' to update book covers, and 'Merge Categories' to consolidate categories/genres from all sources while preserving the existing categories/genres in the book."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
|
||||
+33
-52
@@ -6,12 +6,14 @@ import {FormsModule, ReactiveFormsModule} from '@angular/forms';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {MetadataRefreshOptions} from '../../metadata/model/request/metadata-refresh-options.model';
|
||||
import {AppSettingsService} from '../../core/service/app-settings.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {SettingsHelperService} from '../../core/service/settings-helper.service';
|
||||
import {Observable} from 'rxjs';
|
||||
import {AppSettingKey, AppSettings, MetadataPersistenceSettings} from '../../core/model/app-settings.model';
|
||||
import {AppSettingKey, AppSettings} from '../../core/model/app-settings.model';
|
||||
import {filter, take} from 'rxjs/operators';
|
||||
import {MetadataMatchWeightsComponent} from '../global-preferences/metadata-match-weights-component/metadata-match-weights-component';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {MetadataPersistenceSettingsComponent} from './metadata-persistence-settings-component/metadata-persistence-settings-component';
|
||||
import {PublicReviewsSettingsComponent} from './public-reviews-settings-component/public-reviews-settings-component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-metadata-settings-component',
|
||||
@@ -24,7 +26,9 @@ import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
Tooltip,
|
||||
FormsModule,
|
||||
MetadataMatchWeightsComponent,
|
||||
ToggleSwitch
|
||||
ToggleSwitch,
|
||||
MetadataPersistenceSettingsComponent,
|
||||
PublicReviewsSettingsComponent
|
||||
],
|
||||
templateUrl: './metadata-settings-component.html',
|
||||
styleUrl: './metadata-settings-component.scss'
|
||||
@@ -32,68 +36,45 @@ import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
export class MetadataSettingsComponent implements OnInit {
|
||||
|
||||
currentMetadataOptions!: MetadataRefreshOptions;
|
||||
metadataPersistence: MetadataPersistenceSettings = {
|
||||
saveToOriginalFile: false,
|
||||
backupMetadata: true,
|
||||
backupCover: true
|
||||
};
|
||||
metadataDownloadOnBookdrop: boolean = true;
|
||||
metadataDownloadOnBookdrop = true;
|
||||
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
private messageService = inject(MessageService);
|
||||
private readonly appSettingsService = inject(AppSettingsService);
|
||||
private readonly settingsHelper = inject(SettingsHelperService);
|
||||
|
||||
appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
||||
readonly appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.appSettings$.pipe(
|
||||
filter(settings => !!settings),
|
||||
take(1)
|
||||
).subscribe(settings => {
|
||||
if (settings?.metadataRefreshOptions) {
|
||||
this.currentMetadataOptions = settings.metadataRefreshOptions;
|
||||
}
|
||||
if (settings?.metadataPersistenceSettings) {
|
||||
this.metadataPersistence = {...settings.metadataPersistenceSettings};
|
||||
}
|
||||
this.metadataDownloadOnBookdrop = settings?.metadataDownloadOnBookdrop;
|
||||
});
|
||||
this.loadSettings();
|
||||
}
|
||||
|
||||
onMetadataDownloadOnBookdropToggle(checked: boolean) {
|
||||
this.saveSetting(AppSettingKey.METADATA_DOWNLOAD_ON_BOOKDROP, checked);
|
||||
}
|
||||
|
||||
onPersistenceToggle(key: keyof MetadataPersistenceSettings): void {
|
||||
if (key === 'saveToOriginalFile') {
|
||||
this.metadataPersistence.saveToOriginalFile = !this.metadataPersistence.saveToOriginalFile;
|
||||
|
||||
if (!this.metadataPersistence.saveToOriginalFile) {
|
||||
this.metadataPersistence.backupMetadata = false;
|
||||
this.metadataPersistence.backupCover = false;
|
||||
}
|
||||
} else {
|
||||
this.metadataPersistence[key] = !this.metadataPersistence[key];
|
||||
}
|
||||
|
||||
this.saveSetting(AppSettingKey.METADATA_PERSISTENCE_SETTINGS, this.metadataPersistence);
|
||||
onMetadataDownloadOnBookdropToggle(checked: boolean): void {
|
||||
this.metadataDownloadOnBookdrop = checked;
|
||||
this.settingsHelper.saveSetting(AppSettingKey.METADATA_DOWNLOAD_ON_BOOKDROP, checked);
|
||||
}
|
||||
|
||||
onMetadataSubmit(metadataRefreshOptions: MetadataRefreshOptions): void {
|
||||
this.saveSetting(AppSettingKey.QUICK_BOOK_MATCH, metadataRefreshOptions);
|
||||
this.currentMetadataOptions = metadataRefreshOptions;
|
||||
this.settingsHelper.saveSetting(AppSettingKey.QUICK_BOOK_MATCH, metadataRefreshOptions);
|
||||
}
|
||||
|
||||
private saveSetting(key: string, value: unknown): void {
|
||||
this.appSettingsService.saveSettings([{key, newValue: value}]).subscribe({
|
||||
next: () =>
|
||||
this.showMessage('success', 'Settings Saved', 'The settings were successfully saved!'),
|
||||
error: () =>
|
||||
this.showMessage('error', 'Error', 'There was an error saving the settings.')
|
||||
private loadSettings(): void {
|
||||
this.appSettings$.pipe(
|
||||
filter((settings): settings is AppSettings => !!settings),
|
||||
take(1)
|
||||
).subscribe({
|
||||
next: (settings) => this.initializeSettings(settings),
|
||||
error: (error) => {
|
||||
console.error('Failed to load settings:', error);
|
||||
this.settingsHelper.showMessage('error', 'Error', 'Failed to load settings.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private showMessage(severity: 'success' | 'error', summary: string, detail: string): void {
|
||||
this.messageService.add({severity, summary, detail});
|
||||
}
|
||||
private initializeSettings(settings: AppSettings): void {
|
||||
if (settings.metadataRefreshOptions) {
|
||||
this.currentMetadataOptions = settings.metadataRefreshOptions;
|
||||
}
|
||||
|
||||
protected readonly AppSettingKey = AppSettingKey;
|
||||
this.metadataDownloadOnBookdrop = settings.metadataDownloadOnBookdrop ?? true;
|
||||
}
|
||||
}
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
<div class="p-4 min-w-[50rem]">
|
||||
<p class="text-lg pb-4 pt-2">Public Reviews:</p>
|
||||
<div class="flex flex-col gap-4 pl-6">
|
||||
<div class="flex items-center gap-4">
|
||||
<label>Download Public Reviews</label>
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="publicReviewSettings.downloadEnabled"
|
||||
(onChange)="onPublicReviewsToggle($event.checked)">
|
||||
</p-toggleswitch>
|
||||
<span class="text-sm text-gray-400">
|
||||
Automatically download user reviews from enabled platforms (Amazon, Goodreads, Hardcover) when fetching book metadata. Reviews will be stored with your books for offline access.
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@if (publicReviewSettings.downloadEnabled) {
|
||||
<div class="pl-4 md:pl-6 border-l-2 border-zinc-600">
|
||||
<div class="space-y-4">
|
||||
<div class="space-y-2">
|
||||
<p class="text-md font-medium text-gray-300">Review Sources:</p>
|
||||
<p class="text-sm text-gray-400">Configure which platforms to download reviews from and set limits for each source.</p>
|
||||
</div>
|
||||
|
||||
@for (provider of publicReviewSettings.providers; track provider.provider) {
|
||||
<div class="flex items-center justify-between gap-4 p-2 bg-zinc-800/50 rounded-lg border border-zinc-700 max-w-[22rem]">
|
||||
<div class="flex items-center gap-2 min-w-[8rem]">
|
||||
<p-toggleswitch
|
||||
[(ngModel)]="provider.enabled"
|
||||
(onChange)="onProviderToggle(provider.provider, $event.checked)">
|
||||
</p-toggleswitch>
|
||||
<label class="font-medium text-gray-200">{{ provider.provider }}</label>
|
||||
</div>
|
||||
|
||||
@if (provider.enabled) {
|
||||
<div class="flex items-center gap-2">
|
||||
<label class="text-sm text-gray-400">Max Reviews:</label>
|
||||
<input
|
||||
type="number"
|
||||
class="w-20 px-2 py-1 border border-gray-600 bg-gray-800 text-gray-200 rounded text-sm focus:border-blue-500 focus:outline-none"
|
||||
min="1"
|
||||
max="10"
|
||||
[(ngModel)]="provider.maxReviews"
|
||||
(blur)="onMaxReviewsChange(provider.provider, provider.maxReviews)"
|
||||
title="Number of reviews to download (1-10)">
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (publicReviewSettings.providers.length === 0) {
|
||||
<div class="text-sm text-gray-500 italic">
|
||||
No review sources available. Please ensure metadata providers are configured in the Provider Settings section above.
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {FormsModule} from "@angular/forms";
|
||||
import {ToggleSwitch} from "primeng/toggleswitch";
|
||||
import {AppSettingKey, AppSettings, PublicReviewSettings, ReviewProviderConfig} from '../../../core/model/app-settings.model';
|
||||
import {AppSettingsService} from '../../../core/service/app-settings.service';
|
||||
import {SettingsHelperService} from '../../../core/service/settings-helper.service';
|
||||
import {Observable} from 'rxjs';
|
||||
import {filter, take} from 'rxjs/operators';
|
||||
|
||||
const DEFAULT_PROVIDERS: readonly ReviewProviderConfig[] = [
|
||||
{provider: 'Amazon', enabled: true, maxReviews: 5},
|
||||
{provider: 'GoodReads', enabled: false, maxReviews: 5}
|
||||
] as const;
|
||||
|
||||
const REQUIRED_PROVIDERS = ['Amazon', 'GoodReads'] as const;
|
||||
|
||||
@Component({
|
||||
selector: 'app-public-reviews-settings-component',
|
||||
imports: [FormsModule, ToggleSwitch],
|
||||
templateUrl: './public-reviews-settings-component.html',
|
||||
styleUrl: './public-reviews-settings-component.scss'
|
||||
})
|
||||
export class PublicReviewsSettingsComponent implements OnInit {
|
||||
|
||||
publicReviewSettings: PublicReviewSettings = {
|
||||
downloadEnabled: true,
|
||||
providers: [...DEFAULT_PROVIDERS]
|
||||
};
|
||||
|
||||
private readonly appSettingsService = inject(AppSettingsService);
|
||||
private readonly settingsHelper = inject(SettingsHelperService);
|
||||
|
||||
readonly appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadSettings();
|
||||
}
|
||||
|
||||
onPublicReviewsToggle(checked: boolean): void {
|
||||
this.publicReviewSettings.downloadEnabled = checked;
|
||||
this.settingsHelper.saveSetting(AppSettingKey.METADATA_PUBLIC_REVIEWS_SETTINGS, this.publicReviewSettings);
|
||||
}
|
||||
|
||||
onProviderToggle(providerName: string, enabled: boolean): void {
|
||||
this.updateProviderProperty(providerName, 'enabled', enabled);
|
||||
}
|
||||
|
||||
onMaxReviewsChange(providerName: string, maxReviews: number): void {
|
||||
this.updateProviderProperty(providerName, 'maxReviews', maxReviews);
|
||||
}
|
||||
|
||||
private loadSettings(): void {
|
||||
this.appSettings$.pipe(
|
||||
filter((settings): settings is AppSettings => !!settings),
|
||||
take(1)
|
||||
).subscribe({
|
||||
next: (settings) => this.initializeSettings(settings),
|
||||
error: (error) => {
|
||||
console.error('Failed to load settings:', error);
|
||||
this.settingsHelper.showMessage('error', 'Error', 'Failed to load settings.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private initializeSettings(settings: AppSettings): void {
|
||||
if (settings.metadataPublicReviewsSettings) {
|
||||
this.publicReviewSettings = {...settings.metadataPublicReviewsSettings};
|
||||
}
|
||||
|
||||
this.ensureAllProviders();
|
||||
}
|
||||
|
||||
private updateProviderProperty<T extends keyof ReviewProviderConfig>(
|
||||
providerName: string,
|
||||
property: T,
|
||||
value: ReviewProviderConfig[T]
|
||||
): void {
|
||||
const provider = this.findProvider(providerName);
|
||||
if (provider) {
|
||||
provider[property] = value;
|
||||
this.settingsHelper.saveSetting(AppSettingKey.METADATA_PUBLIC_REVIEWS_SETTINGS, this.publicReviewSettings);
|
||||
}
|
||||
}
|
||||
|
||||
private findProvider(providerName: string): ReviewProviderConfig | undefined {
|
||||
return this.publicReviewSettings.providers.find(p => p.provider === providerName);
|
||||
}
|
||||
|
||||
private ensureAllProviders(): void {
|
||||
REQUIRED_PROVIDERS.forEach(providerName => {
|
||||
const exists = this.findProvider(providerName);
|
||||
if (!exists) {
|
||||
this.publicReviewSettings.providers.push({
|
||||
provider: providerName,
|
||||
enabled: false,
|
||||
maxReviews: 10
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,82 +1,80 @@
|
||||
@if (userService.userState$ | async; as userState) {
|
||||
@if (userState.user) {
|
||||
<div>
|
||||
<div class="rounded-xl overflow-hidden">
|
||||
<p-tabs [(value)]="activeTab" scrollable>
|
||||
<p-tablist>
|
||||
<p-tab [value]="SettingsTab.ReaderSettings">
|
||||
<i class="pi pi-book"></i> Reader
|
||||
<div class="rounded-xl overflow-hidden">
|
||||
<p-tabs [(value)]="activeTab" scrollable>
|
||||
<p-tablist>
|
||||
<p-tab [value]="SettingsTab.ReaderSettings">
|
||||
<i class="pi pi-book"></i> Reader
|
||||
</p-tab>
|
||||
<p-tab [value]="SettingsTab.ViewPreferences">
|
||||
<i class="pi pi-desktop"></i> View
|
||||
</p-tab>
|
||||
@if (userState.user.permissions.admin) {
|
||||
<p-tab [value]="SettingsTab.MetadataSettings">
|
||||
<i class="pi pi-sliders-h"></i> Metadata
|
||||
</p-tab>
|
||||
<p-tab [value]="SettingsTab.ViewPreferences">
|
||||
<i class="pi pi-desktop"></i> View
|
||||
<p-tab [value]="SettingsTab.ApplicationSettings">
|
||||
<i class="pi pi-cog"></i> Application
|
||||
</p-tab>
|
||||
@if (userState.user.permissions.admin) {
|
||||
<p-tab [value]="SettingsTab.MetadataSettings">
|
||||
<i class="pi pi-sliders-h"></i> Metadata
|
||||
</p-tab>
|
||||
<p-tab [value]="SettingsTab.ApplicationSettings">
|
||||
<i class="pi pi-cog"></i> Application
|
||||
</p-tab>
|
||||
<p-tab [value]="SettingsTab.UserManagement">
|
||||
<i class="pi pi-users"></i> User
|
||||
</p-tab>
|
||||
<p-tab [value]="SettingsTab.EmailSettings">
|
||||
<i class="pi pi-envelope"></i> Email
|
||||
</p-tab>
|
||||
<p-tab [value]="SettingsTab.NamingPattern">
|
||||
<i class="pi pi-sitemap"></i> Patterns
|
||||
</p-tab>
|
||||
<p-tab [value]="SettingsTab.AuthenticationSettings">
|
||||
<i class="pi pi-lock"></i> Authentication
|
||||
</p-tab>
|
||||
<p-tab [value]="SettingsTab.Opds">
|
||||
<i class="pi pi-globe"></i> OPDS
|
||||
</p-tab>
|
||||
}
|
||||
@if (userState.user.permissions.admin || userState.user.permissions.canSyncKoReader) {
|
||||
<p-tab [value]="SettingsTab.DeviceSettings">
|
||||
<i class="pi pi-mobile"></i> Devices
|
||||
</p-tab>
|
||||
}
|
||||
</p-tablist>
|
||||
<p-tabpanels>
|
||||
<p-tabpanel [value]="SettingsTab.ReaderSettings">
|
||||
<app-reader-preferences></app-reader-preferences>
|
||||
<p-tab [value]="SettingsTab.UserManagement">
|
||||
<i class="pi pi-users"></i> User
|
||||
</p-tab>
|
||||
<p-tab [value]="SettingsTab.EmailSettings">
|
||||
<i class="pi pi-envelope"></i> Email
|
||||
</p-tab>
|
||||
<p-tab [value]="SettingsTab.NamingPattern">
|
||||
<i class="pi pi-sitemap"></i> Patterns
|
||||
</p-tab>
|
||||
<p-tab [value]="SettingsTab.AuthenticationSettings">
|
||||
<i class="pi pi-lock"></i> Authentication
|
||||
</p-tab>
|
||||
<p-tab [value]="SettingsTab.Opds">
|
||||
<i class="pi pi-globe"></i> OPDS
|
||||
</p-tab>
|
||||
}
|
||||
@if (userState.user.permissions.admin || userState.user.permissions.canSyncKoReader) {
|
||||
<p-tab [value]="SettingsTab.DeviceSettings">
|
||||
<i class="pi pi-mobile"></i> Devices
|
||||
</p-tab>
|
||||
}
|
||||
</p-tablist>
|
||||
<p-tabpanels>
|
||||
<p-tabpanel [value]="SettingsTab.ReaderSettings">
|
||||
<app-reader-preferences></app-reader-preferences>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.ViewPreferences">
|
||||
<app-view-preferences-parent></app-view-preferences-parent>
|
||||
</p-tabpanel>
|
||||
@if (userState.user.permissions.admin) {
|
||||
<p-tabpanel [value]="SettingsTab.MetadataSettings">
|
||||
<app-metadata-settings-component></app-metadata-settings-component>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.ViewPreferences">
|
||||
<app-view-preferences-parent></app-view-preferences-parent>
|
||||
<p-tabpanel [value]="SettingsTab.ApplicationSettings">
|
||||
<app-global-preferences></app-global-preferences>
|
||||
</p-tabpanel>
|
||||
@if (userState.user.permissions.admin) {
|
||||
<p-tabpanel [value]="SettingsTab.MetadataSettings">
|
||||
<app-metadata-settings-component></app-metadata-settings-component>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.ApplicationSettings">
|
||||
<app-global-preferences></app-global-preferences>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.UserManagement">
|
||||
<app-user-management></app-user-management>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.EmailSettings">
|
||||
<app-email></app-email>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.NamingPattern">
|
||||
<app-file-naming-pattern></app-file-naming-pattern>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.AuthenticationSettings">
|
||||
<app-authentication-settings></app-authentication-settings>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.Opds">
|
||||
<app-opds-settings></app-opds-settings>
|
||||
</p-tabpanel>
|
||||
}
|
||||
@if (userState.user.permissions.admin || userState.user.permissions.canSyncKoReader) {
|
||||
<p-tabpanel [value]="SettingsTab.DeviceSettings">
|
||||
<app-device-settings-component></app-device-settings-component>
|
||||
</p-tabpanel>
|
||||
}
|
||||
</p-tabpanels>
|
||||
</p-tabs>
|
||||
</div>
|
||||
<p-tabpanel [value]="SettingsTab.UserManagement">
|
||||
<app-user-management></app-user-management>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.EmailSettings">
|
||||
<app-email></app-email>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.NamingPattern">
|
||||
<app-file-naming-pattern></app-file-naming-pattern>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.AuthenticationSettings">
|
||||
<app-authentication-settings></app-authentication-settings>
|
||||
</p-tabpanel>
|
||||
<p-tabpanel [value]="SettingsTab.Opds">
|
||||
<app-opds-settings></app-opds-settings>
|
||||
</p-tabpanel>
|
||||
}
|
||||
@if (userState.user.permissions.admin || userState.user.permissions.canSyncKoReader) {
|
||||
<p-tabpanel [value]="SettingsTab.DeviceSettings">
|
||||
<app-device-settings-component></app-device-settings-component>
|
||||
</p-tabpanel>
|
||||
}
|
||||
</p-tabpanels>
|
||||
</p-tabs>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name: booklore
|
||||
services:
|
||||
booklore:
|
||||
image: ghcr.io/adityachandelgit/booklore-app:${BOOKLORE_IMAGE_TAG}
|
||||
image: booklore/booklore:${BOOKLORE_IMAGE_TAG}
|
||||
container_name: booklore_server
|
||||
env_file:
|
||||
- .env
|
||||
@@ -30,4 +30,4 @@ services:
|
||||
test: ["CMD", "mariadb-admin", "ping", "-h", "localhost"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
retries: 5
|
||||
|
||||
Reference in New Issue
Block a user