BE code clean up
This commit is contained in:
@@ -11,5 +11,4 @@ public class BookloreApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(BookloreApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.adityachandel.booklore.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class ObjectMapperConfig {
|
||||
|
||||
/*@Bean
|
||||
public ObjectMapper objectMapper() {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.registerModule(new JavaTimeModule());
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
return objectMapper;
|
||||
}*/
|
||||
}
|
||||
-6
@@ -1,15 +1,9 @@
|
||||
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.user.UserCreatorService;
|
||||
import com.adityachandel.booklore.service.user.UserService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
@RequestMapping("/api/v1/settings")
|
||||
public class AppSettingController {
|
||||
|
||||
private AppSettingService appSettingService;
|
||||
private final AppSettingService appSettingService;
|
||||
|
||||
@GetMapping
|
||||
public AppSettings getAppSettings() {
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
public class AuthorController {
|
||||
|
||||
private AuthorService authorService;
|
||||
private final AuthorService authorService;
|
||||
|
||||
@GetMapping("/book/{bookId}")
|
||||
public ResponseEntity<List<String>> getAuthorsByBookId(@PathVariable long bookId) {
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
public class BookController {
|
||||
|
||||
private BooksService booksService;
|
||||
private final BooksService booksService;
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<List<Book>> getBooks(@RequestParam(required = false, defaultValue = "false") boolean withDescription) {
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
public class LibraryController {
|
||||
|
||||
private LibraryService libraryService;
|
||||
private final LibraryService libraryService;
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<List<Library>> getLibraries() {
|
||||
|
||||
+4
-4
@@ -22,10 +22,10 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
public class MetadataController {
|
||||
|
||||
private BookMetadataService bookMetadataService;
|
||||
private BookMetadataUpdater bookMetadataUpdater;
|
||||
private JobSchedulerService jobSchedulerService;
|
||||
private BookMetadataMapper bookMetadataMapper;
|
||||
private final BookMetadataService bookMetadataService;
|
||||
private final BookMetadataUpdater bookMetadataUpdater;
|
||||
private final JobSchedulerService jobSchedulerService;
|
||||
private final BookMetadataMapper bookMetadataMapper;
|
||||
|
||||
@PostMapping("/{bookId}/metadata/prospective")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
public class PathController {
|
||||
|
||||
private PathService pathService;
|
||||
private final PathService pathService;
|
||||
|
||||
@GetMapping
|
||||
@PreAuthorize("@securityUtil.canManipulateLibrary() or @securityUtil.isAdmin()")
|
||||
|
||||
+1
-2
@@ -1,6 +1,6 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.BookPreferences;
|
||||
import com.adityachandel.booklore.model.dto.settings.BookPreferences;
|
||||
import com.adityachandel.booklore.model.dto.BookLoreUser;
|
||||
import com.adityachandel.booklore.model.dto.request.UserUpdateRequest;
|
||||
import com.adityachandel.booklore.service.user.UserService;
|
||||
@@ -19,7 +19,6 @@ public class UserController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
|
||||
@GetMapping("/me")
|
||||
public ResponseEntity<BookLoreUser> getMyself() {
|
||||
return ResponseEntity.ok(userService.getMyself());
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.adityachandel.booklore.convertor;
|
||||
|
||||
import com.adityachandel.booklore.model.BookPreferences;
|
||||
import com.adityachandel.booklore.model.dto.settings.BookPreferences;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.adityachandel.booklore.convertor;
|
||||
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
import jakarta.persistence.Converter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Converter
|
||||
public class PathsConverter implements AttributeConverter<List<String>, String> {
|
||||
|
||||
private static final String DELIMITER = ";";
|
||||
|
||||
@Override
|
||||
public String convertToDatabaseColumn(List<String> attribute) {
|
||||
if (attribute == null || attribute.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return attribute.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(String::trim)
|
||||
.collect(Collectors.joining(DELIMITER));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> convertToEntityAttribute(String dbData) {
|
||||
if (dbData == null || dbData.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return Arrays.stream(dbData.split(DELIMITER))
|
||||
.filter(Objects::nonNull)
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.adityachandel.booklore.model.dto;
|
||||
|
||||
import com.adityachandel.booklore.model.BookPreferences;
|
||||
import com.adityachandel.booklore.model.dto.settings.BookPreferences;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.model;
|
||||
package com.adityachandel.booklore.model.dto.settings;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.adityachandel.booklore.model;
|
||||
package com.adityachandel.booklore.model.dto.settings;
|
||||
|
||||
import com.adityachandel.booklore.model.entity.LibraryEntity;
|
||||
import com.adityachandel.booklore.model.entity.LibraryPathEntity;
|
||||
+1
-2
@@ -1,8 +1,7 @@
|
||||
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 com.adityachandel.booklore.model.dto.settings.BookPreferences;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
|
||||
+2
-2
@@ -19,8 +19,8 @@ import java.util.stream.Collectors;
|
||||
@AllArgsConstructor
|
||||
public class AppSettingService {
|
||||
|
||||
private AppSettingsRepository appSettingsRepository;
|
||||
private ObjectMapper objectMapper;
|
||||
private final AppSettingsRepository appSettingsRepository;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public AppSettings getAppSettings() {
|
||||
List<AppSettingEntity> settings = appSettingsRepository.findAll();
|
||||
|
||||
+5
-7
@@ -1,6 +1,6 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
|
||||
import com.adityachandel.booklore.model.LibraryFile;
|
||||
import com.adityachandel.booklore.model.dto.settings.LibraryFile;
|
||||
import com.adityachandel.booklore.model.entity.*;
|
||||
import com.adityachandel.booklore.model.enums.BookFileType;
|
||||
import com.adityachandel.booklore.repository.*;
|
||||
@@ -17,12 +17,10 @@ import java.util.Set;
|
||||
@AllArgsConstructor
|
||||
public class BookCreatorService {
|
||||
|
||||
private AuthorRepository authorRepository;
|
||||
private CategoryRepository categoryRepository;
|
||||
private BookRepository bookRepository;
|
||||
private BookMetadataRepository bookMetadataRepository;
|
||||
private PdfViewerPreferencesRepository pdfViewerPreferencesRepository;
|
||||
private EpubViewerPreferencesRepository epubViewerPreferencesRepository;
|
||||
private final AuthorRepository authorRepository;
|
||||
private final CategoryRepository categoryRepository;
|
||||
private final BookRepository bookRepository;
|
||||
private final BookMetadataRepository bookMetadataRepository;
|
||||
|
||||
public BookEntity createShellBook(LibraryFile libraryFile, BookFileType bookFileType) {
|
||||
BookEntity bookEntity = BookEntity.builder()
|
||||
|
||||
@@ -50,7 +50,6 @@ public class BookMetadataService {
|
||||
private final FileService fileService;
|
||||
private final Map<MetadataProvider, BookParser> parserMap;
|
||||
|
||||
|
||||
public List<BookMetadata> getProspectiveMetadataListForBookId(long bookId, FetchMetadataRequest request) {
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
Book book = bookMapper.toBook(bookEntity);
|
||||
|
||||
+7
-8
@@ -24,14 +24,13 @@ import java.util.stream.Collectors;
|
||||
@AllArgsConstructor
|
||||
public class BookMetadataUpdater {
|
||||
|
||||
private BookRepository bookRepository;
|
||||
private AuthorRepository authorRepository;
|
||||
private BookMetadataRepository bookMetadataRepository;
|
||||
private CategoryRepository categoryRepository;
|
||||
private BookAwardRepository awardRepository;
|
||||
private FileService fileService;
|
||||
private BookAwardRepository bookAwardRepository;
|
||||
|
||||
private final BookRepository bookRepository;
|
||||
private final AuthorRepository authorRepository;
|
||||
private final BookMetadataRepository bookMetadataRepository;
|
||||
private final CategoryRepository categoryRepository;
|
||||
private final BookAwardRepository awardRepository;
|
||||
private final FileService fileService;
|
||||
private final BookAwardRepository bookAwardRepository;
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public BookMetadataEntity setBookMetadata(long bookId, BookMetadata newMetadata, boolean setThumbnail, boolean mergeCategories) {
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
|
||||
import com.adityachandel.booklore.config.security.AuthenticationService;
|
||||
import com.adityachandel.booklore.config.security.SecurityUtil;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.mapper.BookMapper;
|
||||
import com.adityachandel.booklore.mapper.EpubViewerPreferencesMapper;
|
||||
import com.adityachandel.booklore.mapper.PdfViewerPreferencesMapper;
|
||||
import com.adityachandel.booklore.model.BookPreferences;
|
||||
import com.adityachandel.booklore.model.dto.*;
|
||||
import com.adityachandel.booklore.model.dto.request.ReadProgressRequest;
|
||||
import com.adityachandel.booklore.model.entity.*;
|
||||
@@ -32,7 +28,6 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
+1
-5
@@ -1,7 +1,7 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.model.LibraryFile;
|
||||
import com.adityachandel.booklore.model.dto.settings.LibraryFile;
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.entity.LibraryEntity;
|
||||
import com.adityachandel.booklore.model.entity.LibraryPathEntity;
|
||||
@@ -14,7 +14,6 @@ import com.adityachandel.booklore.util.FileUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
@@ -22,14 +21,12 @@ import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
@Slf4j
|
||||
public class FileUploadService {
|
||||
|
||||
|
||||
private static final long MAX_FILE_SIZE = 100 * 1024 * 1024; // 100 MB
|
||||
private static final String PDF_MIME_TYPE = "application/pdf";
|
||||
private static final String EPUB_MIME_TYPE = "application/epub+zip";
|
||||
@@ -39,7 +36,6 @@ public class FileUploadService {
|
||||
private final EpubProcessor epubProcessor;
|
||||
private final NotificationService notificationService;
|
||||
|
||||
|
||||
public Book uploadFile(MultipartFile file, long libraryId, long pathId) {
|
||||
validateFile(file);
|
||||
|
||||
|
||||
+1
-2
@@ -1,7 +1,7 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.model.LibraryFile;
|
||||
import com.adityachandel.booklore.model.dto.settings.LibraryFile;
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.LibraryEntity;
|
||||
@@ -40,7 +40,6 @@ public class LibraryProcessingService {
|
||||
private final BookRepository bookRepository;
|
||||
private final EntityManager entityManager;
|
||||
|
||||
|
||||
@Transactional
|
||||
public void processLibrary(long libraryId) throws IOException {
|
||||
LibraryEntity libraryEntity = libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package com.adityachandel.booklore.service.fileprocessor;
|
||||
|
||||
import com.adityachandel.booklore.mapper.BookMapper;
|
||||
import com.adityachandel.booklore.model.LibraryFile;
|
||||
import com.adityachandel.booklore.model.dto.settings.LibraryFile;
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.adityachandel.booklore.service.fileprocessor;
|
||||
|
||||
import com.adityachandel.booklore.model.LibraryFile;
|
||||
import com.adityachandel.booklore.model.dto.settings.LibraryFile;
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
|
||||
public interface FileProcessor {
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package com.adityachandel.booklore.service.fileprocessor;
|
||||
|
||||
import com.adityachandel.booklore.mapper.BookMapper;
|
||||
import com.adityachandel.booklore.model.LibraryFile;
|
||||
import com.adityachandel.booklore.model.dto.settings.LibraryFile;
|
||||
import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||
import com.adityachandel.booklore.model.enums.BookFileType;
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package com.adityachandel.booklore.service.user;
|
||||
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.model.BookPreferences;
|
||||
import com.adityachandel.booklore.model.dto.settings.BookPreferences;
|
||||
import com.adityachandel.booklore.model.dto.UserCreateRequest;
|
||||
import com.adityachandel.booklore.model.entity.BookLoreUserEntity;
|
||||
import com.adityachandel.booklore.model.entity.LibraryEntity;
|
||||
|
||||
@@ -1,26 +1,21 @@
|
||||
package com.adityachandel.booklore.service.user;
|
||||
|
||||
import com.adityachandel.booklore.config.security.AuthenticationService;
|
||||
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.settings.BookPreferences;
|
||||
import com.adityachandel.booklore.model.dto.BookLoreUser;
|
||||
import com.adityachandel.booklore.model.dto.request.UserLoginRequest;
|
||||
import com.adityachandel.booklore.model.dto.request.UserUpdateRequest;
|
||||
import com.adityachandel.booklore.model.entity.BookLoreUserEntity;
|
||||
import com.adityachandel.booklore.model.entity.LibraryEntity;
|
||||
import com.adityachandel.booklore.repository.LibraryRepository;
|
||||
import com.adityachandel.booklore.repository.UserRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.adityachandel.booklore.util;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class DateUtils {
|
||||
|
||||
private static final String DATE_FORMAT_REGEX = "^[A-Za-z]+\\s[0-9]{1,2},\\s[0-9]{4}$";
|
||||
|
||||
public static String parseDateToInstant(String dateString) {
|
||||
if (dateString == null || dateString.trim().isEmpty() || !Pattern.matches(DATE_FORMAT_REGEX, dateString)) {
|
||||
return dateString;
|
||||
}
|
||||
try {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM d, yyyy", Locale.ENGLISH);
|
||||
LocalDate localDate = LocalDate.parse(dateString, formatter);
|
||||
Instant instant = localDate.atStartOfDay(ZoneId.systemDefault()).toInstant();
|
||||
LocalDate finalDate = instant.atZone(ZoneId.systemDefault()).toLocalDate();
|
||||
return finalDate.toString();
|
||||
} catch (DateTimeParseException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
-10
@@ -1,10 +1,3 @@
|
||||
CREATE TABLE IF NOT EXISTS jwt_secret
|
||||
(
|
||||
id SERIAL PRIMARY KEY,
|
||||
secret TEXT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS library
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
@@ -14,6 +7,7 @@ CREATE TABLE IF NOT EXISTS library
|
||||
watch BOOLEAN NOT NULL DEFAULT FALSE
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS library_path
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
@@ -22,6 +16,7 @@ CREATE TABLE IF NOT EXISTS library_path
|
||||
CONSTRAINT fk_library_path FOREIGN KEY (library_id) REFERENCES library (id)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS book
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
@@ -36,9 +31,9 @@ CREATE TABLE IF NOT EXISTS book
|
||||
CONSTRAINT fk_library_path_id FOREIGN KEY (library_path_id) REFERENCES library_path (id) ON DELETE CASCADE,
|
||||
CONSTRAINT unique_file_library UNIQUE (file_name, library_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_library_id ON book (library_id);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS book_metadata
|
||||
(
|
||||
book_id BIGINT NOT NULL PRIMARY KEY,
|
||||
@@ -81,6 +76,15 @@ CREATE TABLE IF NOT EXISTS book_metadata
|
||||
CONSTRAINT fk_book_metadata FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS jwt_secret
|
||||
(
|
||||
id SERIAL PRIMARY KEY,
|
||||
secret TEXT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE book_award
|
||||
(
|
||||
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
@@ -93,6 +97,7 @@ CREATE TABLE book_award
|
||||
CONSTRAINT unique_book_award UNIQUE (book_id, name, category, awarded_at)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS author
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
@@ -100,12 +105,14 @@ CREATE TABLE IF NOT EXISTS author
|
||||
CONSTRAINT unique_name UNIQUE (name)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS category
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS pdf_viewer_preference
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
@@ -117,6 +124,7 @@ CREATE TABLE IF NOT EXISTS pdf_viewer_preference
|
||||
UNIQUE (user_id, book_id)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS epub_viewer_preference
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
@@ -128,6 +136,7 @@ CREATE TABLE IF NOT EXISTS epub_viewer_preference
|
||||
UNIQUE (user_id, book_id)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS book_metadata_category_mapping
|
||||
(
|
||||
book_id BIGINT NOT NULL,
|
||||
@@ -137,6 +146,7 @@ CREATE TABLE IF NOT EXISTS book_metadata_category_mapping
|
||||
CONSTRAINT fk_book_metadata_category_mapping_category FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS book_metadata_author_mapping
|
||||
(
|
||||
book_id BIGINT NOT NULL,
|
||||
@@ -145,10 +155,10 @@ CREATE TABLE IF NOT EXISTS book_metadata_author_mapping
|
||||
CONSTRAINT fk_book_metadata_author_mapping_book FOREIGN KEY (book_id) REFERENCES book_metadata (book_id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_book_metadata_author_mapping_author FOREIGN KEY (author_id) REFERENCES author (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_book_metadata_id ON book_metadata_author_mapping (book_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_author_id ON book_metadata_author_mapping (author_id);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS users
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
@@ -161,6 +171,7 @@ CREATE TABLE IF NOT EXISTS users
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS user_permissions
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
@@ -172,9 +183,9 @@ CREATE TABLE IF NOT EXISTS user_permissions
|
||||
permission_admin BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
CONSTRAINT fk_user_permissions_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX idx_user_permissions_user ON user_permissions (user_id);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS shelf
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
@@ -186,6 +197,7 @@ CREATE TABLE IF NOT EXISTS shelf
|
||||
CONSTRAINT fk_shelf_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS book_shelf_mapping
|
||||
(
|
||||
book_id BIGINT NOT NULL,
|
||||
@@ -195,6 +207,7 @@ CREATE TABLE IF NOT EXISTS book_shelf_mapping
|
||||
CONSTRAINT fk_book_shelf_mapping_shelf FOREIGN KEY (shelf_id) REFERENCES shelf (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE app_settings
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
@@ -204,6 +217,7 @@ CREATE TABLE app_settings
|
||||
UNIQUE (category, name)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS user_book_progress
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
@@ -219,6 +233,7 @@ CREATE TABLE IF NOT EXISTS user_book_progress
|
||||
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,
|
||||
Reference in New Issue
Block a user