Per user book preferences
This commit is contained in:
+7
-1
@@ -1,8 +1,10 @@
|
||||
package com.adityachandel.booklore.config.security;
|
||||
|
||||
import com.adityachandel.booklore.model.BookPreferences;
|
||||
import com.adityachandel.booklore.model.entity.BookLoreUserEntity;
|
||||
import com.adityachandel.booklore.model.entity.UserPermissionsEntity;
|
||||
import com.adityachandel.booklore.repository.UserRepository;
|
||||
import com.adityachandel.booklore.service.UserService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
@@ -13,9 +15,10 @@ import org.springframework.stereotype.Component;
|
||||
@AllArgsConstructor
|
||||
@Component
|
||||
public class ApplicationStartupRunner implements CommandLineRunner {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
@@ -34,6 +37,9 @@ public class ApplicationStartupRunner implements CommandLineRunner {
|
||||
permissions.setPermissionEditMetadata(true);
|
||||
permissions.setPermissionAdmin(true);
|
||||
|
||||
BookPreferences bookPreferences = userService.buildDefaultBookPreferences();
|
||||
admin.setBookPreferences(bookPreferences);
|
||||
|
||||
admin.setPermissions(permissions);
|
||||
userRepository.save(admin);
|
||||
|
||||
|
||||
+8
@@ -20,6 +20,14 @@ public class SecurityUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSelf(Long userId) {
|
||||
var authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication != null && authentication.getPrincipal() instanceof BookLoreUser user) {
|
||||
return user.getId().equals(userId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canUpload() {
|
||||
var authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication != null && authentication.getPrincipal() instanceof BookLoreUser user) {
|
||||
|
||||
+3
-2
@@ -23,8 +23,9 @@ public class AuthController {
|
||||
|
||||
@PostMapping("/register")
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public ResponseEntity<Map<String, String>> registerUser(@RequestBody @Valid UserCreateRequest userCreateRequest) {
|
||||
return userService.registerUser(userCreateRequest);
|
||||
public ResponseEntity<?> registerUser(@RequestBody @Valid UserCreateRequest userCreateRequest) {
|
||||
userService.registerUser(userCreateRequest);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/login")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.BookPreferences;
|
||||
import com.adityachandel.booklore.model.dto.BookLoreUser;
|
||||
import com.adityachandel.booklore.model.dto.UserCreateRequest;
|
||||
import com.adityachandel.booklore.model.dto.request.UserLoginRequest;
|
||||
@@ -46,4 +47,11 @@ public class UserController {
|
||||
public void deleteUser(@PathVariable Long id) {
|
||||
userService.deleteUser(id);
|
||||
}
|
||||
|
||||
@PutMapping("/{id}/book-preferences")
|
||||
@PreAuthorize("@securityUtil.isSelf(#id)")
|
||||
public void updateUserBookPreferences(@PathVariable Long id, @RequestBody BookPreferences bookPreferences) {
|
||||
userService.updateBookPreferences(id, bookPreferences);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.adityachandel.booklore.convertor;
|
||||
|
||||
import com.adityachandel.booklore.model.BookPreferences;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
import jakarta.persistence.Converter;
|
||||
|
||||
@Converter(autoApply = true)
|
||||
public class BookPreferencesConverter implements AttributeConverter<BookPreferences, String> {
|
||||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
public String convertToDatabaseColumn(BookPreferences preferences) {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(preferences);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException("Error converting BookPreferences to JSON", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookPreferences convertToEntityAttribute(String json) {
|
||||
try {
|
||||
return objectMapper.readValue(json, BookPreferences.class);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error converting JSON to BookPreferences", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.adityachandel.booklore.model;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BookPreferences {
|
||||
|
||||
private PerBookSetting perBookSetting;
|
||||
private PdfReaderSetting pdfReaderSetting;
|
||||
private EpubReaderSetting epubReaderSetting;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class EpubReaderSetting {
|
||||
private String theme;
|
||||
private String font;
|
||||
private int fontSize;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class PdfReaderSetting {
|
||||
private String pageSpread;
|
||||
private String pageZoom;
|
||||
private boolean showSidebar;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class PerBookSetting {
|
||||
private GlobalOrIndividual pdf;
|
||||
private GlobalOrIndividual epub;
|
||||
}
|
||||
|
||||
public enum GlobalOrIndividual {
|
||||
Global, Individual
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.adityachandel.booklore.model.dto;
|
||||
|
||||
import com.adityachandel.booklore.model.BookPreferences;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
@@ -12,6 +13,7 @@ public class BookLoreUser {
|
||||
private String email;
|
||||
private List<Library> assignedLibraries;
|
||||
private UserPermissions permissions;
|
||||
private BookPreferences bookPreferences;
|
||||
|
||||
@Data
|
||||
public static class UserPermissions {
|
||||
|
||||
+7
@@ -1,5 +1,8 @@
|
||||
package com.adityachandel.booklore.model.entity;
|
||||
|
||||
import com.adityachandel.booklore.convertor.BookPreferencesConverter;
|
||||
import com.adityachandel.booklore.convertor.SortConverter;
|
||||
import com.adityachandel.booklore.model.BookPreferences;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
@@ -39,6 +42,10 @@ public class BookLoreUserEntity {
|
||||
@Column(name = "updated_at")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Column(name = "book_preferences")
|
||||
@Convert(converter = BookPreferencesConverter.class)
|
||||
private BookPreferences bookPreferences;
|
||||
|
||||
@OneToOne(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private UserPermissionsEntity permissions;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.adityachandel.booklore.service;
|
||||
import com.adityachandel.booklore.config.security.JwtUtils;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.mapper.BookLoreUserMapper;
|
||||
import com.adityachandel.booklore.model.BookPreferences;
|
||||
import com.adityachandel.booklore.model.dto.BookLoreUser;
|
||||
import com.adityachandel.booklore.model.dto.UserCreateRequest;
|
||||
import com.adityachandel.booklore.model.dto.request.UserLoginRequest;
|
||||
@@ -35,7 +36,7 @@ public class UserService {
|
||||
private final JwtUtils jwtUtils;
|
||||
|
||||
@Transactional
|
||||
public ResponseEntity<Map<String, String>> registerUser(UserCreateRequest request) {
|
||||
public void registerUser(UserCreateRequest request) {
|
||||
Optional<BookLoreUserEntity> existingUser = userRepository.findByUsername(request.getUsername());
|
||||
if (existingUser.isPresent()) {
|
||||
throw ApiError.USERNAME_ALREADY_TAKEN.createException(request.getUsername());
|
||||
@@ -55,19 +56,14 @@ public class UserService {
|
||||
permissions.setPermissionManipulateLibrary(request.isPermissionManipulateLibrary());
|
||||
bookLoreUserEntity.setPermissions(permissions);
|
||||
|
||||
bookLoreUserEntity.setBookPreferences(buildDefaultBookPreferences());
|
||||
|
||||
if (request.getSelectedLibraries() != null && !request.getSelectedLibraries().isEmpty()) {
|
||||
List<LibraryEntity> libraries = libraryRepository.findAllById(request.getSelectedLibraries());
|
||||
bookLoreUserEntity.setLibraries(new ArrayList<>(libraries));
|
||||
}
|
||||
|
||||
userRepository.save(bookLoreUserEntity);
|
||||
|
||||
String token = jwtUtils.generateToken(bookLoreUserEntity);
|
||||
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("token", token);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(response);
|
||||
}
|
||||
|
||||
public ResponseEntity<Map<String, String>> loginUser(UserLoginRequest loginRequest) {
|
||||
@@ -124,9 +120,36 @@ public class UserService {
|
||||
userRepository.delete(user);
|
||||
}
|
||||
|
||||
|
||||
public BookLoreUser getBookLoreUser(Long id) {
|
||||
BookLoreUserEntity user = userRepository.findById(id).orElseThrow(() -> ApiError.USER_NOT_FOUND.createException(id));
|
||||
return bookLoreUserMapper.toDto(user);
|
||||
}
|
||||
|
||||
|
||||
public BookPreferences buildDefaultBookPreferences() {
|
||||
return BookPreferences.builder()
|
||||
.perBookSetting(BookPreferences.PerBookSetting.builder()
|
||||
.epub(BookPreferences.GlobalOrIndividual.Individual)
|
||||
.pdf(BookPreferences.GlobalOrIndividual.Individual)
|
||||
.build())
|
||||
.pdfReaderSetting(BookPreferences.PdfReaderSetting.builder()
|
||||
.showSidebar(false)
|
||||
.pageSpread("odd")
|
||||
.pageZoom("page-fit")
|
||||
.build())
|
||||
.epubReaderSetting(BookPreferences.EpubReaderSetting.builder()
|
||||
.theme("white")
|
||||
.font("serif")
|
||||
.fontSize(150)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
public void updateBookPreferences(long userId, BookPreferences bookPreferences) {
|
||||
BookLoreUserEntity user = userRepository.findById(userId).orElseThrow(() -> ApiError.USER_NOT_FOUND.createException(userId));
|
||||
user.setBookPreferences(bookPreferences);
|
||||
userRepository.save(user);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -140,13 +140,14 @@ CREATE INDEX IF NOT EXISTS idx_author_id ON book_metadata_author_mapping (author
|
||||
|
||||
CREATE TABLE IF NOT EXISTS users
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(255) NOT NULL UNIQUE,
|
||||
password_hash VARCHAR(255) NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
email VARCHAR(255) UNIQUE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(255) NOT NULL UNIQUE,
|
||||
password_hash VARCHAR(255) NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
email VARCHAR(255) UNIQUE,
|
||||
book_preferences TEXT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS user_permissions
|
||||
@@ -204,11 +205,9 @@ CREATE TABLE IF NOT EXISTS user_book_progress
|
||||
CONSTRAINT fk_user_book_progress_book FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE,
|
||||
CONSTRAINT unique_user_book_progress UNIQUE (user_id, book_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_user_book_progress_user ON user_book_progress (user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_user_book_progress_book ON user_book_progress (book_id);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS user_library_mapping
|
||||
(
|
||||
user_id BIGINT NOT NULL,
|
||||
|
||||
@@ -1,20 +1,3 @@
|
||||
INSERT INTO app_settings (category, name, val)
|
||||
VALUES
|
||||
('epub', 'theme', 'white'),
|
||||
('epub', 'fontSize', '150'),
|
||||
('epub', 'font', 'serif');
|
||||
|
||||
INSERT INTO app_settings (category, name, val)
|
||||
VALUES
|
||||
('pdf', 'spread', 'odd'),
|
||||
('pdf', 'zoom', 'page-fit'),
|
||||
('pdf', 'sidebar', 'true');
|
||||
|
||||
INSERT INTO app_settings (category, name, val)
|
||||
VALUES
|
||||
('reader_setting', 'pdf', 'individual'),
|
||||
('reader_setting', 'epub', 'individual');
|
||||
|
||||
INSERT INTO app_settings (category, name, val)
|
||||
VALUES
|
||||
(
|
||||
|
||||
+73
-76
@@ -1,123 +1,120 @@
|
||||
import {Component, inject, OnInit} from '@angular/core';
|
||||
import {AppSettingsService} from '../../../service/app-settings.service';
|
||||
import {Observable} from 'rxjs';
|
||||
import {AppSettings} from '../../../model/app-settings.model';
|
||||
import {Select} from 'primeng/select';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {NgForOf} from '@angular/common';
|
||||
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {MetadataAdvancedFetchOptionsComponent} from '../../../../metadata/metadata-options-dialog/metadata-advanced-fetch-options/metadata-advanced-fetch-options.component';
|
||||
import {MetadataRefreshOptions} from '../../../../metadata/model/request/metadata-refresh-options.model';
|
||||
import { Component, inject, OnInit } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { NgForOf } from '@angular/common';
|
||||
import { Select } from 'primeng/select';
|
||||
import { ToggleSwitch } from 'primeng/toggleswitch';
|
||||
import { RadioButton } from 'primeng/radiobutton';
|
||||
import { Divider } from 'primeng/divider';
|
||||
import { Button } from 'primeng/button';
|
||||
import { Tooltip } from 'primeng/tooltip';
|
||||
import { User, UserBookPreferences, UserService } from '../../../../user.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-preferences',
|
||||
templateUrl: './book-preferences.component.html',
|
||||
imports: [Select, FormsModule, NgForOf, ToggleSwitch, RadioButton, Divider, Button, Tooltip],
|
||||
standalone: true,
|
||||
styleUrls: ['./book-preferences.component.scss']
|
||||
styleUrls: ['./book-preferences.component.scss'],
|
||||
imports: [Select, FormsModule, NgForOf, ToggleSwitch, RadioButton, Divider, Button, Tooltip]
|
||||
})
|
||||
export class BookPreferences implements OnInit {
|
||||
spreads = [
|
||||
{name: 'Even Spread', key: 'even'},
|
||||
{name: 'Odd Spread', key: 'odd'},
|
||||
{name: 'No Spread', key: 'off'}
|
||||
];
|
||||
zooms = [
|
||||
{name: 'Auto Zoom', key: 'auto'},
|
||||
{name: 'Page Fit', key: 'page-fit'},
|
||||
{name: 'Page Width', key: 'page-width'},
|
||||
{name: 'Actual Size', key: 'page-actual'}
|
||||
];
|
||||
themes = [
|
||||
{name: 'White', key: 'white'},
|
||||
{name: 'Black', key: 'black'},
|
||||
{name: 'Grey', key: 'grey'},
|
||||
{name: 'Sepia', key: 'sepia'}
|
||||
];
|
||||
fonts = [
|
||||
{name: 'Serif', key: 'serif'},
|
||||
{name: 'Sans Serif', key: 'sans-serif'},
|
||||
{name: 'Roboto', key: 'roboto'},
|
||||
{name: 'Cursive', key: 'cursive'},
|
||||
{name: 'Monospace', key: 'monospace'}
|
||||
readonly spreads = [
|
||||
{ name: 'Even Spread', key: 'even' },
|
||||
{ name: 'Odd Spread', key: 'odd' },
|
||||
{ name: 'No Spread', key: 'off' }
|
||||
];
|
||||
|
||||
selectedSpread: any;
|
||||
selectedZoom: any;
|
||||
readonly zooms = [
|
||||
{ name: 'Auto Zoom', key: 'auto' },
|
||||
{ name: 'Page Fit', key: 'page-fit' },
|
||||
{ name: 'Page Width', key: 'page-width' },
|
||||
{ name: 'Actual Size', key: 'page-actual' }
|
||||
];
|
||||
|
||||
readonly themes = [
|
||||
{ name: 'White', key: 'white' },
|
||||
{ name: 'Black', key: 'black' },
|
||||
{ name: 'Grey', key: 'grey' },
|
||||
{ name: 'Sepia', key: 'sepia' }
|
||||
];
|
||||
|
||||
readonly fonts = [
|
||||
{ name: 'Serif', key: 'serif' },
|
||||
{ name: 'Sans Serif', key: 'sans-serif' },
|
||||
{ name: 'Roboto', key: 'roboto' },
|
||||
{ name: 'Cursive', key: 'cursive' },
|
||||
{ name: 'Monospace', key: 'monospace' }
|
||||
];
|
||||
|
||||
readonly individualOrGlobal = ['Global', 'Individual'];
|
||||
|
||||
selectedSpread!: string;
|
||||
selectedZoom!: string;
|
||||
showSidebar = false;
|
||||
selectedTheme!: any;
|
||||
fontSize: number = 100;
|
||||
selectedFont: any;
|
||||
selectedTheme!: string;
|
||||
fontSize = 100;
|
||||
selectedFont!: string;
|
||||
selectedPdfScope!: string;
|
||||
selectedEpubScope!: string;
|
||||
|
||||
private appSettingsService = inject(AppSettingsService);
|
||||
appSettings$: Observable<AppSettings | null> = this.appSettingsService.appSettings$;
|
||||
individualOrGlobal = ['global', 'individual'];
|
||||
private readonly userService = inject(UserService);
|
||||
userData$: Observable<User | null> = this.userService.userData$;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.appSettings$.subscribe(settings => {
|
||||
if (settings) {
|
||||
this.populateSettings(settings);
|
||||
}
|
||||
this.userData$.subscribe(userData => {
|
||||
if (userData) this.populateSettings(userData.bookPreferences);
|
||||
});
|
||||
}
|
||||
|
||||
populateSettings(settings: AppSettings): void {
|
||||
if (settings.pdf) {
|
||||
const pdfSettings = settings.pdf;
|
||||
this.selectedSpread = this.spreads.find(s => s.key === pdfSettings.spread)?.key;
|
||||
this.selectedZoom = this.zooms.find(z => z.key === pdfSettings.zoom)?.key;
|
||||
this.showSidebar = pdfSettings.sidebar;
|
||||
}
|
||||
private populateSettings(prefs: UserBookPreferences): void {
|
||||
this.selectedPdfScope = prefs.perBookSetting.pdf;
|
||||
this.selectedEpubScope = prefs.perBookSetting.epub;
|
||||
this.selectedSpread = prefs.pdfReaderSetting.pageSpread;
|
||||
this.selectedZoom = prefs.pdfReaderSetting.pageZoom;
|
||||
this.showSidebar = prefs.pdfReaderSetting.showSidebar;
|
||||
this.selectedTheme = prefs.epubReaderSetting.theme;
|
||||
this.fontSize = prefs.epubReaderSetting.fontSize;
|
||||
this.selectedFont = prefs.epubReaderSetting.font;
|
||||
}
|
||||
|
||||
if (settings.epub) {
|
||||
const epubSettings = settings.epub;
|
||||
this.selectedTheme = this.themes.find(t => t.key === epubSettings.theme)?.key;
|
||||
this.fontSize = Number(epubSettings.fontSize);
|
||||
this.selectedFont = this.fonts.find(f => f.key === epubSettings.font)?.key;
|
||||
}
|
||||
|
||||
if (settings.readerSettings) {
|
||||
this.selectedPdfScope = settings.readerSettings.pdfScope;
|
||||
this.selectedEpubScope = settings.readerSettings.epubScope;
|
||||
private updatePreference<T>(updateFn: (prefs: UserBookPreferences) => void): void {
|
||||
const user = this.userService.getLocalUser();
|
||||
if (user) {
|
||||
updateFn(user.bookPreferences);
|
||||
this.userService.updateBookPreferences(user.id, user.bookPreferences);
|
||||
}
|
||||
}
|
||||
|
||||
onThemeChange(): void {
|
||||
this.appSettingsService.saveAppSetting('epub', 'theme', this.selectedTheme);
|
||||
this.updatePreference(prefs => prefs.epubReaderSetting.theme = this.selectedTheme);
|
||||
}
|
||||
|
||||
onFontChange(): void {
|
||||
this.appSettingsService.saveAppSetting('epub', 'font', this.selectedFont);
|
||||
this.updatePreference(prefs => prefs.epubReaderSetting.font = this.selectedFont);
|
||||
}
|
||||
|
||||
onSpreadChange(): void {
|
||||
this.appSettingsService.saveAppSetting('pdf', 'spread', this.selectedSpread);
|
||||
this.updatePreference(prefs => prefs.pdfReaderSetting.pageSpread = this.selectedSpread);
|
||||
}
|
||||
|
||||
onZoomChange(): void {
|
||||
this.appSettingsService.saveAppSetting('pdf', 'zoom', this.selectedZoom);
|
||||
this.updatePreference(prefs => prefs.pdfReaderSetting.pageZoom = this.selectedZoom);
|
||||
}
|
||||
|
||||
onSidebarChange(): void {
|
||||
this.appSettingsService.saveAppSetting('pdf', 'sidebar', this.showSidebar.toString());
|
||||
this.updatePreference(prefs => prefs.pdfReaderSetting.showSidebar = this.showSidebar);
|
||||
}
|
||||
|
||||
onFontSizeChange(): void {
|
||||
this.appSettingsService.saveAppSetting('epub', 'fontSize', this.fontSize);
|
||||
this.updatePreference(prefs => prefs.epubReaderSetting.fontSize = this.fontSize);
|
||||
}
|
||||
|
||||
onPdfScopeChange(): void {
|
||||
this.appSettingsService.saveAppSetting('reader_setting', 'pdf', this.selectedPdfScope);
|
||||
this.updatePreference(prefs => prefs.perBookSetting.pdf = this.selectedPdfScope);
|
||||
}
|
||||
|
||||
onEpubScopeChange(): void {
|
||||
this.appSettingsService.saveAppSetting('reader_setting', 'epub', this.selectedEpubScope);
|
||||
this.updatePreference(prefs => prefs.perBookSetting.epub = this.selectedEpubScope);
|
||||
}
|
||||
|
||||
increaseFontSize(): void {
|
||||
|
||||
@@ -19,6 +19,24 @@ export interface User {
|
||||
canEditMetadata: boolean;
|
||||
canManipulateLibrary: boolean;
|
||||
};
|
||||
bookPreferences: UserBookPreferences;
|
||||
}
|
||||
|
||||
export interface UserBookPreferences {
|
||||
perBookSetting: {
|
||||
pdf: string;
|
||||
epub: string;
|
||||
};
|
||||
pdfReaderSetting: {
|
||||
pageSpread: string;
|
||||
pageZoom: string;
|
||||
showSidebar: boolean;
|
||||
};
|
||||
epubReaderSetting: {
|
||||
theme: string;
|
||||
font: string;
|
||||
fontSize: number;
|
||||
};
|
||||
}
|
||||
|
||||
interface JwtPayload {
|
||||
@@ -60,6 +78,10 @@ export class UserService {
|
||||
});
|
||||
}
|
||||
|
||||
getLocalUser(): User | null {
|
||||
return this.userDataSubject.getValue();
|
||||
}
|
||||
|
||||
createUser(userData: Omit<User, 'id'>): Observable<{ message: string }> {
|
||||
return this.http.post<{ message: string }>(this.apiUrl, userData);
|
||||
}
|
||||
@@ -76,6 +98,17 @@ export class UserService {
|
||||
return this.http.delete<void>(`${this.userUrl}/${userId}`);
|
||||
}
|
||||
|
||||
updateBookPreferences(userId: number, prefs: UserBookPreferences): void {
|
||||
this.http.put<void>(`${this.userUrl}/${userId}/book-preferences`, prefs)
|
||||
.subscribe(() => {
|
||||
const currentUser = this.userDataSubject.getValue();
|
||||
if (currentUser) {
|
||||
const updatedUser = {...currentUser, bookPreferences: {...prefs}};
|
||||
this.userDataSubject.next(updatedUser);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private startWebSocket(): void {
|
||||
const token = this.getToken();
|
||||
if (token) {
|
||||
|
||||
Reference in New Issue
Block a user