Initial commit
This commit is contained in:
+37
@@ -0,0 +1,37 @@
|
|||||||
|
HELP.md
|
||||||
|
.gradle
|
||||||
|
build/
|
||||||
|
!gradle/wrapper/gradle-wrapper.jar
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
bin/
|
||||||
|
!**/src/main/**/bin/
|
||||||
|
!**/src/test/**/bin/
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
out/
|
||||||
|
!**/src/main/**/out/
|
||||||
|
!**/src/test/**/out/
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
/gradlew text eol=lf
|
||||||
|
*.bat text eol=crlf
|
||||||
|
*.jar binary
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
HELP.md
|
||||||
|
.gradle
|
||||||
|
build/
|
||||||
|
!gradle/wrapper/gradle-wrapper.jar
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
bin/
|
||||||
|
!**/src/main/**/bin/
|
||||||
|
!**/src/test/**/bin/
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
out/
|
||||||
|
!**/src/main/**/out/
|
||||||
|
!**/src/test/**/out/
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
id 'org.springframework.boot' version '3.4.0'
|
||||||
|
id 'io.spring.dependency-management' version '1.1.6'
|
||||||
|
id 'org.hibernate.orm' version '6.6.2.Final'
|
||||||
|
id 'org.graalvm.buildtools.native' version '0.10.3'
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'com.adityachandel'
|
||||||
|
version = '0.0.1-SNAPSHOT'
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain {
|
||||||
|
languageVersion = JavaLanguageVersion.of(21)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
compileOnly {
|
||||||
|
extendsFrom annotationProcessor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
|
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||||
|
compileOnly 'org.projectlombok:lombok'
|
||||||
|
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||||
|
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
|
||||||
|
annotationProcessor 'org.projectlombok:lombok'
|
||||||
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
|
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||||||
|
implementation 'org.apache.pdfbox:pdfbox:3.0.3'
|
||||||
|
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'
|
||||||
|
implementation 'org.flywaydb:flyway-mysql:10.12.0'
|
||||||
|
implementation 'com.github.jai-imageio:jai-imageio-core:1.4.0'
|
||||||
|
implementation 'com.github.jai-imageio:jai-imageio-jpeg2000:1.3.0'
|
||||||
|
implementation 'org.apache.pdfbox:jbig2-imageio:3.0.3'
|
||||||
|
}
|
||||||
|
|
||||||
|
hibernate {
|
||||||
|
enhancement {
|
||||||
|
enableAssociationManagement = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('test') {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
BIN
Binary file not shown.
@@ -0,0 +1,7 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
+252
@@ -0,0 +1,252 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright © 2015-2021 the original authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
app_path=$0
|
||||||
|
|
||||||
|
# Need this for daisy-chained symlinks.
|
||||||
|
while
|
||||||
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
|
[ -h "$app_path" ]
|
||||||
|
do
|
||||||
|
ls=$( ls -ld "$app_path" )
|
||||||
|
link=${ls#*' -> '}
|
||||||
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# This is normally unused
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
||||||
|
' "$PWD" ) || exit
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD=maximum
|
||||||
|
|
||||||
|
warn () {
|
||||||
|
echo "$*"
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false').
|
||||||
|
cygwin=false
|
||||||
|
msys=false
|
||||||
|
darwin=false
|
||||||
|
nonstop=false
|
||||||
|
case "$( uname )" in #(
|
||||||
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
|
Darwin* ) darwin=true ;; #(
|
||||||
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
|
NONSTOP* ) nonstop=true ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
|
else
|
||||||
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
|
fi
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD=java
|
||||||
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
|
case $MAX_FD in #(
|
||||||
|
max*)
|
||||||
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
|
warn "Could not query maximum file descriptor limit"
|
||||||
|
esac
|
||||||
|
case $MAX_FD in #(
|
||||||
|
'' | soft) :;; #(
|
||||||
|
*)
|
||||||
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
|
# * args from the command line
|
||||||
|
# * the main class name
|
||||||
|
# * -classpath
|
||||||
|
# * -D...appname settings
|
||||||
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-classpath "$CLASSPATH" \
|
||||||
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
||||||
Vendored
+94
@@ -0,0 +1,94 @@
|
|||||||
|
@rem
|
||||||
|
@rem Copyright 2015 the original author or authors.
|
||||||
|
@rem
|
||||||
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@rem you may not use this file except in compliance with the License.
|
||||||
|
@rem You may obtain a copy of the License at
|
||||||
|
@rem
|
||||||
|
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@rem
|
||||||
|
@rem Unless required by applicable law or agreed to in writing, software
|
||||||
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@rem See the License for the specific language governing permissions and
|
||||||
|
@rem limitations under the License.
|
||||||
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
|
@if "%DEBUG%"=="" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
|
:fail
|
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
|
rem the _cmd.exe /c_ return code!
|
||||||
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = 'booklore-api'
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.adityachandel.booklore;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class BookloreApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(BookloreApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.adityachandel.booklore.config;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "app")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class AppProperties {
|
||||||
|
private String pathBook;
|
||||||
|
private String pathConfig;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.adityachandel.booklore.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class WebConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
|
registry.addMapping("/**")
|
||||||
|
.allowedOrigins("*")
|
||||||
|
.allowedMethods("*")
|
||||||
|
.allowedHeaders("*");
|
||||||
|
}
|
||||||
|
}
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
package com.adityachandel.booklore.controller;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.dto.AuthorDTO;
|
||||||
|
import com.adityachandel.booklore.service.AuthorService;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RequestMapping("/v1/author")
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class AuthorController {
|
||||||
|
|
||||||
|
private AuthorService authorService;
|
||||||
|
|
||||||
|
@GetMapping("/{authorId}")
|
||||||
|
public ResponseEntity<AuthorDTO> getAuthor(@PathVariable long authorId) {
|
||||||
|
return ResponseEntity.ok(authorService.getAuthorById(authorId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/book/{bookId}")
|
||||||
|
public ResponseEntity<List<AuthorDTO>> getAuthorsByBookId(@PathVariable long bookId) {
|
||||||
|
return ResponseEntity.ok(authorService.getAuthorsByBookId(bookId));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.adityachandel.booklore.controller;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.dto.BookDTO;
|
||||||
|
import com.adityachandel.booklore.dto.BookViewerSettingDTO;
|
||||||
|
import com.adityachandel.booklore.exception.APIException;
|
||||||
|
import com.adityachandel.booklore.exception.ErrorCode;
|
||||||
|
import com.adityachandel.booklore.service.BooksService;
|
||||||
|
import jakarta.validation.constraints.Max;
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RequestMapping("/v1/book")
|
||||||
|
@RestController
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class BookController {
|
||||||
|
|
||||||
|
private BooksService booksService;
|
||||||
|
|
||||||
|
@GetMapping("/{bookId}")
|
||||||
|
public ResponseEntity<BookDTO> getBook(@PathVariable long bookId) {
|
||||||
|
return ResponseEntity.ok(booksService.getBook(bookId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping()
|
||||||
|
public ResponseEntity<Page<BookDTO>> getBooks(@RequestParam(defaultValue = "0") @Min(0) int page, @RequestParam(defaultValue = "25") @Min(1) @Max(100) int size) {
|
||||||
|
Page<BookDTO> books = booksService.getBooks(page, size);
|
||||||
|
return ResponseEntity.ok(books);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/search")
|
||||||
|
public ResponseEntity<List<BookDTO>> searchBooks(@RequestParam String title) {
|
||||||
|
List<BookDTO> books = booksService.search(title);
|
||||||
|
return ResponseEntity.ok(books);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{bookId}/cover")
|
||||||
|
public ResponseEntity<Resource> getBookCover(@PathVariable long bookId) {
|
||||||
|
return ResponseEntity.ok(booksService.getBookCover(bookId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{bookId}/data")
|
||||||
|
public ResponseEntity<byte[]> getBookData(@PathVariable long bookId) throws IOException {
|
||||||
|
return booksService.getBookData(bookId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{bookId}/viewer-setting")
|
||||||
|
public ResponseEntity<Void> updateBookViewerSettings(@RequestBody BookViewerSettingDTO bookViewerSettingDTO, @PathVariable long bookId) {
|
||||||
|
booksService.saveBookViewerSetting(bookId, bookViewerSettingDTO);
|
||||||
|
return ResponseEntity.noContent().build();
|
||||||
|
}
|
||||||
|
}
|
||||||
+59
@@ -0,0 +1,59 @@
|
|||||||
|
package com.adityachandel.booklore.controller;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.dto.BookDTO;
|
||||||
|
import com.adityachandel.booklore.dto.LibraryDTO;
|
||||||
|
import com.adityachandel.booklore.dto.request.CreateLibraryRequest;
|
||||||
|
import com.adityachandel.booklore.service.LibraryService;
|
||||||
|
import jakarta.validation.constraints.Max;
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
|
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/v1/library")
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class LibraryController {
|
||||||
|
|
||||||
|
private LibraryService libraryService;
|
||||||
|
|
||||||
|
@PostMapping(consumes = "application/json", produces = "application/json")
|
||||||
|
public SseEmitter createLibrary(@RequestBody CreateLibraryRequest request) {
|
||||||
|
return libraryService.createLibrary(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{libraryId}")
|
||||||
|
public ResponseEntity<LibraryDTO> getLibrary(@PathVariable long libraryId) {
|
||||||
|
return ResponseEntity.ok(libraryService.getLibrary(libraryId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{libraryId}")
|
||||||
|
public ResponseEntity<?> deleteLibrary(@PathVariable long libraryId) {
|
||||||
|
libraryService.deleteLibrary(libraryId);
|
||||||
|
return ResponseEntity.noContent().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public ResponseEntity<Page<LibraryDTO>> getLibraries(
|
||||||
|
@RequestParam(defaultValue = "0") @Min(0) int page,
|
||||||
|
@RequestParam(defaultValue = "25") @Min(1) @Max(100) int size) {
|
||||||
|
return ResponseEntity.ok(libraryService.getLibraries(page, size));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{libraryId}/book/{bookId}")
|
||||||
|
public ResponseEntity<BookDTO> getBook(@PathVariable long libraryId, @PathVariable long bookId) {
|
||||||
|
return ResponseEntity.ok(libraryService.getBook(libraryId, bookId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{libraryId}/book")
|
||||||
|
public ResponseEntity<Page<BookDTO>> getBooks(
|
||||||
|
@PathVariable long libraryId,
|
||||||
|
@RequestParam(defaultValue = "0") @Min(0) int page,
|
||||||
|
@RequestParam(defaultValue = "25") @Min(1) @Max(100) int size) {
|
||||||
|
Page<BookDTO> books = libraryService.getBooks(libraryId, page, size);
|
||||||
|
return ResponseEntity.ok(books);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.adityachandel.booklore.controller;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.service.PathService;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/v1/path")
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class PathController {
|
||||||
|
|
||||||
|
private PathService pathService;
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public List<String> getFolders(@RequestParam String path) {
|
||||||
|
return pathService.getFoldersAtPath(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.adityachandel.booklore.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@Data
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class AuthorDTO {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private List<BookDTO> books;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.adityachandel.booklore.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class BookDTO {
|
||||||
|
private Long id;
|
||||||
|
private Long libraryId;
|
||||||
|
private String fileName;
|
||||||
|
private String title;
|
||||||
|
private List<AuthorDTO> authors = new ArrayList<>();
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.adityachandel.booklore.dto;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class BookViewerSettingDTO {
|
||||||
|
private int pageNumber;
|
||||||
|
private String zoom;
|
||||||
|
private boolean sidebar_visible;
|
||||||
|
private String spread;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.adityachandel.booklore.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@Data
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class LibraryDTO {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
}
|
||||||
|
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package com.adityachandel.booklore.dto.request;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class CreateLibraryRequest {
|
||||||
|
private String name;
|
||||||
|
private List<String> paths;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.adityachandel.booklore.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Table(name = "author")
|
||||||
|
public class Author {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ManyToMany(mappedBy = "authors")
|
||||||
|
private List<Book> books;
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.adityachandel.booklore.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Table(name = "book")
|
||||||
|
public class Book {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "file_name", length = 1000)
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
@Column(name = "title")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Column(name = "path")
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
@ManyToMany(fetch = FetchType.LAZY)
|
||||||
|
@JoinTable(
|
||||||
|
name = "book_author_mapping",
|
||||||
|
joinColumns = @JoinColumn(name = "book_id"),
|
||||||
|
inverseJoinColumns = @JoinColumn(name = "author_id")
|
||||||
|
)
|
||||||
|
private List<Author> authors;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "library_id", nullable = false)
|
||||||
|
private Library library;
|
||||||
|
|
||||||
|
@OneToOne(mappedBy = "book", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
|
private BookViewerSetting viewerSetting;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.adityachandel.booklore.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Table(name = "book_viewer_setting")
|
||||||
|
public class BookViewerSetting {
|
||||||
|
@Id
|
||||||
|
private Long bookId;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
@MapsId
|
||||||
|
@JoinColumn(name = "book_id")
|
||||||
|
@JsonIgnore
|
||||||
|
private Book book;
|
||||||
|
|
||||||
|
@Column(name = "page_number")
|
||||||
|
private int pageNumber;
|
||||||
|
|
||||||
|
@Column(name = "zoom")
|
||||||
|
private String zoom;
|
||||||
|
|
||||||
|
@Column(name = "sidebar_visible")
|
||||||
|
private boolean sidebar_visible;
|
||||||
|
|
||||||
|
@Column(name = "spread")
|
||||||
|
private String spread;
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.adityachandel.booklore.entity;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.convertor.PathsConverter;
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Table(name = "library")
|
||||||
|
public class Library {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Convert(converter = PathsConverter.class)
|
||||||
|
@Column(name = "paths")
|
||||||
|
private List<String> paths;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "library", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
|
private List<Book> books;
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.adityachandel.booklore.entity;
|
||||||
|
|
||||||
|
public class PathInfo {
|
||||||
|
private String name;
|
||||||
|
private String fullPath;
|
||||||
|
|
||||||
|
public PathInfo(String name, String fullPath) {
|
||||||
|
this.name = name;
|
||||||
|
this.fullPath = fullPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFullPath() {
|
||||||
|
return fullPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFullPath(String fullPath) {
|
||||||
|
this.fullPath = fullPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.adityachandel.booklore.exception;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class APIException extends RuntimeException {
|
||||||
|
private final HttpStatus status;
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
public APIException(String formattedMessage, HttpStatus status) {
|
||||||
|
super(formattedMessage);
|
||||||
|
this.status = status;
|
||||||
|
this.message = formattedMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.adityachandel.booklore.exception;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum ErrorCode {
|
||||||
|
AUTHOR_NOT_FOUND(HttpStatus.NOT_FOUND, "Author not found with ID: %d"),
|
||||||
|
BOOK_NOT_FOUND(HttpStatus.NOT_FOUND, "Book not found with ID: %d"),
|
||||||
|
FILE_READ_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "Error reading files from path"),
|
||||||
|
IMAGE_NOT_FOUND(HttpStatus.NOT_FOUND, "Image not found or not readable"),
|
||||||
|
INVALID_FILE_FORMAT(HttpStatus.BAD_REQUEST, "Invalid file format"),
|
||||||
|
LIBRARY_NOT_FOUND(HttpStatus.NOT_FOUND, "Library not found with ID: %d"),
|
||||||
|
BAD_REQUEST(HttpStatus.BAD_REQUEST, "Bad request"),
|
||||||
|
INVALID_QUERY_PARAMETERS(HttpStatus.BAD_REQUEST, "Query parameters are required for the search.");
|
||||||
|
|
||||||
|
private final HttpStatus status;
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
ErrorCode(HttpStatus status, String message) {
|
||||||
|
this.status = status;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public APIException createException(Object... details) {
|
||||||
|
String formattedMessage = (details.length > 0) ? String.format(message, details) : message;
|
||||||
|
return new APIException(formattedMessage, this.status);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.adityachandel.booklore.exception;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@AllArgsConstructor
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class ErrorResponse {
|
||||||
|
|
||||||
|
private int status;
|
||||||
|
private String message;
|
||||||
|
private LocalDateTime timestamp;
|
||||||
|
private List<String> details;
|
||||||
|
|
||||||
|
public ErrorResponse(int status, String message) {
|
||||||
|
this.status = status;
|
||||||
|
this.message = message;
|
||||||
|
this.timestamp = LocalDateTime.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponse(int status, String message, List<String> details) {
|
||||||
|
this.status = status;
|
||||||
|
this.message = message;
|
||||||
|
this.timestamp = LocalDateTime.now();
|
||||||
|
this.details = details;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
package com.adityachandel.booklore.exception;
|
||||||
|
|
||||||
|
import jakarta.validation.ConstraintViolationException;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@RestControllerAdvice
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
|
@ExceptionHandler(APIException.class)
|
||||||
|
public ResponseEntity<ErrorResponse> handleAPIException(APIException ex) {
|
||||||
|
ErrorResponse errorResponse = new ErrorResponse(ex.getStatus().value(), ex.getMessage());
|
||||||
|
return new ResponseEntity<>(errorResponse, ex.getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
|
public ResponseEntity<ErrorResponse> handleValidationExceptions(MethodArgumentNotValidException ex) {
|
||||||
|
List<String> errors = ex.getBindingResult()
|
||||||
|
.getFieldErrors()
|
||||||
|
.stream()
|
||||||
|
.map(error -> error.getField() + ": " + error.getDefaultMessage())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
ErrorResponse errorResponse = new ErrorResponse(HttpStatus.BAD_REQUEST.value(), "Validation error", errors);
|
||||||
|
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(ConstraintViolationException.class)
|
||||||
|
public ResponseEntity<ErrorResponse> handleConstraintViolationExceptions(ConstraintViolationException ex) {
|
||||||
|
List<String> errors = ex.getConstraintViolations()
|
||||||
|
.stream()
|
||||||
|
.map(violation -> violation.getPropertyPath() + ": " + violation.getMessage())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
ErrorResponse errorResponse = new ErrorResponse(HttpStatus.BAD_REQUEST.value(), "Validation error", errors);
|
||||||
|
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(Exception.class)
|
||||||
|
public ResponseEntity<ErrorResponse> handleGenericException(Exception ex) {
|
||||||
|
ErrorResponse errorResponse = new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "An unexpected error occurred.");
|
||||||
|
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
package com.adityachandel.booklore.repository;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.entity.Author;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface AuthorRepository extends JpaRepository<Author, Long> {
|
||||||
|
|
||||||
|
Optional<Author> findByName(String name);
|
||||||
|
|
||||||
|
@Query("SELECT a FROM Author a JOIN a.books b WHERE b.id = :bookId")
|
||||||
|
List<Author> findAuthorsByBookId(@Param("bookId") Long bookId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.adityachandel.booklore.repository;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.entity.Book;
|
||||||
|
import com.adityachandel.booklore.entity.Library;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface BookRepository extends JpaRepository<Book, Long>, JpaSpecificationExecutor<Book> {
|
||||||
|
|
||||||
|
Page<Book> findBooksByLibraryId(Long libraryId, Pageable pageable);
|
||||||
|
|
||||||
|
Optional<Book> findBookByIdAndLibraryId(long id, long libraryId);
|
||||||
|
|
||||||
|
List<Book> findByTitleContainingIgnoreCase(String title);
|
||||||
|
}
|
||||||
|
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
package com.adityachandel.booklore.repository;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.entity.BookViewerSetting;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface BookViewerSettingRepository extends JpaRepository<BookViewerSetting, Long> {
|
||||||
|
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package com.adityachandel.booklore.repository;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.entity.Library;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface LibraryRepository extends JpaRepository<Library, Long>, JpaSpecificationExecutor<Library> {
|
||||||
|
|
||||||
|
List<Library> findByName(String name);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.adityachandel.booklore.service;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.dto.AuthorDTO;
|
||||||
|
import com.adityachandel.booklore.entity.Author;
|
||||||
|
import com.adityachandel.booklore.exception.APIException;
|
||||||
|
import com.adityachandel.booklore.exception.ErrorCode;
|
||||||
|
import com.adityachandel.booklore.repository.AuthorRepository;
|
||||||
|
import com.adityachandel.booklore.repository.BookRepository;
|
||||||
|
import com.adityachandel.booklore.transformer.AuthorTransformer;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class AuthorService {
|
||||||
|
|
||||||
|
private final AuthorRepository authorRepository;
|
||||||
|
private final BookRepository bookRepository;
|
||||||
|
|
||||||
|
public AuthorDTO getAuthorById(Long id) {
|
||||||
|
Author author = authorRepository.findById(id).orElseThrow(() -> ErrorCode.AUTHOR_NOT_FOUND.createException(id));
|
||||||
|
return AuthorTransformer.toAuthorDTO(author);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AuthorDTO> getAuthorsByBookId(Long bookId) {
|
||||||
|
bookRepository.findById(bookId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
|
||||||
|
List<Author> authors = authorRepository.findAuthorsByBookId(bookId);
|
||||||
|
return authors.stream().map(AuthorTransformer::toAuthorDTO).toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
package com.adityachandel.booklore.service;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.config.AppProperties;
|
||||||
|
import com.adityachandel.booklore.dto.BookDTO;
|
||||||
|
import com.adityachandel.booklore.dto.BookViewerSettingDTO;
|
||||||
|
import com.adityachandel.booklore.entity.Book;
|
||||||
|
import com.adityachandel.booklore.entity.BookViewerSetting;
|
||||||
|
import com.adityachandel.booklore.entity.Library;
|
||||||
|
import com.adityachandel.booklore.exception.ErrorCode;
|
||||||
|
import com.adityachandel.booklore.repository.BookRepository;
|
||||||
|
import com.adityachandel.booklore.repository.BookViewerSettingRepository;
|
||||||
|
import com.adityachandel.booklore.service.parser.PdfParser;
|
||||||
|
import com.adityachandel.booklore.transformer.BookTransformer;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.UrlResource;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageImpl;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class BooksService {
|
||||||
|
|
||||||
|
private final AppProperties appProperties;
|
||||||
|
private final PdfParser pdfParser;
|
||||||
|
private final BookRepository bookRepository;
|
||||||
|
private final BookViewerSettingRepository bookViewerSettingRepository;
|
||||||
|
|
||||||
|
|
||||||
|
public BookDTO getBook(long bookId) {
|
||||||
|
Book book = bookRepository.findById(bookId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
|
||||||
|
return BookTransformer.convertToBookDTO(book);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page<BookDTO> getBooks(int page, int size) {
|
||||||
|
PageRequest pageRequest = PageRequest.of(page, size);
|
||||||
|
Page<Book> bookPage = bookRepository.findAll(PageRequest.of(page, size));
|
||||||
|
List<BookDTO> bookDTOs = bookPage.getContent().stream().map(BookTransformer::convertToBookDTO).collect(Collectors.toList());
|
||||||
|
return new PageImpl<>(bookDTOs, pageRequest, bookPage.getTotalElements());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Book> parseBooks(Library library, SseEmitter emitter) {
|
||||||
|
List<Book> books = new ArrayList<>();
|
||||||
|
for (String libraryPath : library.getPaths()) {
|
||||||
|
books.addAll(parseBooks(libraryPath, emitter));
|
||||||
|
}
|
||||||
|
return books;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Book> parseBooks(String libraryPath, SseEmitter emitter) {
|
||||||
|
List<Book> books = new ArrayList<>();
|
||||||
|
try (Stream<Path> filePaths = Files.walk(Path.of(libraryPath))) {
|
||||||
|
filePaths.filter(Files::isRegularFile).forEach(filePath -> handleFile(filePath, books, emitter));
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Error reading files from path: {}", libraryPath, e);
|
||||||
|
throw ErrorCode.FILE_READ_ERROR.createException(libraryPath);
|
||||||
|
}
|
||||||
|
return books;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleFile(Path filePath, List<Book> books, SseEmitter emitter) {
|
||||||
|
String fileName = filePath.getFileName().toString();
|
||||||
|
if (fileName.endsWith(".pdf")) {
|
||||||
|
sendSseEvent("Parsing: " + fileName, emitter);
|
||||||
|
Book book = parsePdfBook(filePath);
|
||||||
|
book.setPath(filePath.toAbsolutePath().toString());
|
||||||
|
books.add(book);
|
||||||
|
} else if (fileName.endsWith(".epub")) {
|
||||||
|
log.info("EPUB File: {}", fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendSseEvent(String message, SseEmitter emitter) {
|
||||||
|
try {
|
||||||
|
SseEmitter.SseEventBuilder event = SseEmitter.event()
|
||||||
|
.data(message)
|
||||||
|
.name("SSE Event");
|
||||||
|
emitter.send(event);
|
||||||
|
} catch (IOException e) {
|
||||||
|
emitter.completeWithError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Book parsePdfBook(Path filePath) {
|
||||||
|
Book book = pdfParser.parseBook(filePath.toAbsolutePath().toString(), appProperties.getPathConfig());
|
||||||
|
book.setViewerSetting(BookViewerSetting.builder()
|
||||||
|
.bookId(book.getId())
|
||||||
|
.pageNumber(0)
|
||||||
|
.zoom("page-fit")
|
||||||
|
.spread("off")
|
||||||
|
.sidebar_visible(false)
|
||||||
|
.build());
|
||||||
|
return book;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveBookViewerSetting(long bookId, BookViewerSettingDTO bookViewerSettingDTO) {
|
||||||
|
BookViewerSetting bookViewerSetting = bookViewerSettingRepository.findById(bookId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
|
||||||
|
bookViewerSetting.setPageNumber(bookViewerSettingDTO.getPageNumber());
|
||||||
|
bookViewerSetting.setZoom(bookViewerSettingDTO.getZoom());
|
||||||
|
bookViewerSetting.setSpread(bookViewerSettingDTO.getSpread());
|
||||||
|
bookViewerSetting.setSidebar_visible(bookViewerSettingDTO.isSidebar_visible());
|
||||||
|
bookViewerSettingRepository.save(bookViewerSetting);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Resource getBookCover(long bookId) {
|
||||||
|
Book book = bookRepository.findById(bookId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
|
||||||
|
String thumbPath = appProperties.getPathConfig() + "/thumbs/" + PdfParser.getFileNameWithoutExtension(book.getFileName()) + ".jpg";
|
||||||
|
Path filePath = Paths.get(thumbPath);
|
||||||
|
try {
|
||||||
|
Resource resource = new UrlResource(filePath.toUri());
|
||||||
|
if (resource.exists() && resource.isReadable()) {
|
||||||
|
return resource;
|
||||||
|
} else {
|
||||||
|
throw ErrorCode.IMAGE_NOT_FOUND.createException(thumbPath);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw ErrorCode.IMAGE_NOT_FOUND.createException(thumbPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponseEntity<byte[]> getBookData(long bookId) throws IOException {
|
||||||
|
Book book = bookRepository.findById(bookId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
|
||||||
|
byte[] pdfBytes = Files.readAllBytes(new File(book.getPath()).toPath());
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.header(HttpHeaders.CONTENT_TYPE, "application/pdf")
|
||||||
|
.body(pdfBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BookDTO> search(String title) {
|
||||||
|
List<Book> books = bookRepository.findByTitleContainingIgnoreCase(title);
|
||||||
|
return books.stream().map(BookTransformer::convertToBookDTO).toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
package com.adityachandel.booklore.service;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.dto.BookDTO;
|
||||||
|
import com.adityachandel.booklore.dto.LibraryDTO;
|
||||||
|
import com.adityachandel.booklore.dto.request.CreateLibraryRequest;
|
||||||
|
import com.adityachandel.booklore.entity.Author;
|
||||||
|
import com.adityachandel.booklore.entity.Book;
|
||||||
|
import com.adityachandel.booklore.entity.Library;
|
||||||
|
import com.adityachandel.booklore.exception.ErrorCode;
|
||||||
|
import com.adityachandel.booklore.repository.AuthorRepository;
|
||||||
|
import com.adityachandel.booklore.repository.BookRepository;
|
||||||
|
import com.adityachandel.booklore.repository.BookViewerSettingRepository;
|
||||||
|
import com.adityachandel.booklore.repository.LibraryRepository;
|
||||||
|
import com.adityachandel.booklore.transformer.BookTransformer;
|
||||||
|
import com.adityachandel.booklore.transformer.LibraryTransformer;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static com.adityachandel.booklore.transformer.LibraryTransformer.createLibraryFromRequest;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class LibraryService {
|
||||||
|
|
||||||
|
private LibraryRepository libraryRepository;
|
||||||
|
private BookRepository bookRepository;
|
||||||
|
private BooksService booksService;
|
||||||
|
private AuthorRepository authorRepository;
|
||||||
|
private BookViewerSettingRepository bookViewerSettingRepository;
|
||||||
|
|
||||||
|
|
||||||
|
public LibraryDTO getLibrary(long libraryId) {
|
||||||
|
Library library = libraryRepository.findById(libraryId).orElseThrow(() -> ErrorCode.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||||
|
return LibraryTransformer.convertToLibraryDTO(library);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page<LibraryDTO> getLibraries(int page, int size) {
|
||||||
|
PageRequest pageRequest = PageRequest.of(page, size);
|
||||||
|
Page<Library> libraryPage = libraryRepository.findAll(pageRequest);
|
||||||
|
return libraryPage.map(LibraryTransformer::convertToLibraryDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteLibrary(long id) {
|
||||||
|
libraryRepository.findById(id).orElseThrow(() -> ErrorCode.LIBRARY_NOT_FOUND.createException(id));
|
||||||
|
libraryRepository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public BookDTO getBook(long libraryId, long bookId) {
|
||||||
|
libraryRepository.findById(libraryId).orElseThrow(() -> ErrorCode.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||||
|
Book book = bookRepository.findBookByIdAndLibraryId(bookId, libraryId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
|
||||||
|
return BookTransformer.convertToBookDTO(book);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page<BookDTO> getBooks(long libraryId, int page, int size) {
|
||||||
|
libraryRepository.findById(libraryId).orElseThrow(() -> ErrorCode.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||||
|
PageRequest pageRequest = PageRequest.of(page, size);
|
||||||
|
Page<Book> bookPage = bookRepository.findBooksByLibraryId(libraryId, pageRequest);
|
||||||
|
return bookPage.map(BookTransformer::convertToBookDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public SseEmitter createLibrary(CreateLibraryRequest request) {
|
||||||
|
SseEmitter emitter = new SseEmitter();
|
||||||
|
ExecutorService sseMvcExecutor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
|
sseMvcExecutor.execute(() -> {
|
||||||
|
try {
|
||||||
|
Library library = createLibraryFromRequest(request);
|
||||||
|
List<Book> books = booksService.parseBooks(library, emitter);
|
||||||
|
books.forEach(book -> book.setLibrary(library));
|
||||||
|
library.setBooks(books);
|
||||||
|
|
||||||
|
List<Author> authors = books.stream()
|
||||||
|
.flatMap(book -> book.getAuthors().stream())
|
||||||
|
.distinct()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
authorRepository.saveAll(authors);
|
||||||
|
|
||||||
|
libraryRepository.save(library);
|
||||||
|
bookRepository.saveAll(books);
|
||||||
|
bookViewerSettingRepository.saveAll(books.stream()
|
||||||
|
.map(Book::getViewerSetting)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
|
||||||
|
emitter.complete();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
emitter.completeWithError(ex);
|
||||||
|
} finally {
|
||||||
|
sseMvcExecutor.shutdown();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return emitter;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.adityachandel.booklore.service;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class PathService {
|
||||||
|
|
||||||
|
public List<String> getFoldersAtPath(String path) {
|
||||||
|
Path directory = Paths.get(path);
|
||||||
|
if (!Files.exists(directory) || !Files.isDirectory(directory)) {
|
||||||
|
log.warn("Invalid path or not a directory: {}", path);
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
try (Stream<Path> paths = Files.list(directory)) {
|
||||||
|
return paths
|
||||||
|
.filter(Files::isDirectory)
|
||||||
|
.map(p -> directory.resolve(p.getFileName()).toString())
|
||||||
|
.sorted()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Error accessing path {}: {}", path, e.getMessage(), e);
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.adityachandel.booklore.service.parser;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.entity.Book;
|
||||||
|
|
||||||
|
public interface BookParser {
|
||||||
|
|
||||||
|
Book parseBook(String bookPath, String coverPath);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.adityachandel.booklore.service.parser;
|
||||||
|
|
||||||
|
/*@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class EBookParser implements BookParser {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Book parseBook(String bookPath, String coverPath) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package com.adityachandel.booklore.service.parser;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.entity.Author;
|
||||||
|
import com.adityachandel.booklore.entity.Book;
|
||||||
|
import com.adityachandel.booklore.repository.AuthorRepository;
|
||||||
|
import com.adityachandel.booklore.repository.BookRepository;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.pdfbox.Loader;
|
||||||
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
|
import org.apache.pdfbox.rendering.ImageType;
|
||||||
|
import org.apache.pdfbox.rendering.PDFRenderer;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class PdfParser implements BookParser {
|
||||||
|
|
||||||
|
private AuthorRepository authorRepository;
|
||||||
|
private BookRepository bookRepository;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public Book parseBook(String bookPath, String coverPath) {
|
||||||
|
File bookFile = new File(bookPath);
|
||||||
|
log.info("Parsing: {}", bookFile.getName());
|
||||||
|
File coverDirectory = new File(coverPath, "thumbs");
|
||||||
|
Book book = Book.builder()
|
||||||
|
.path(bookPath)
|
||||||
|
.fileName(bookFile.getName())
|
||||||
|
.authors(new ArrayList<>())
|
||||||
|
.build();
|
||||||
|
try (PDDocument document = Loader.loadPDF(bookFile)) {
|
||||||
|
if (document.getDocumentInformation() == null) {
|
||||||
|
log.warn("No document information found");
|
||||||
|
} else {
|
||||||
|
if (document.getDocumentInformation().getTitle() != null) {
|
||||||
|
book.setTitle(document.getDocumentInformation().getTitle());
|
||||||
|
}
|
||||||
|
if (document.getDocumentInformation().getAuthor() != null) {
|
||||||
|
String authorNamesUnsplit = document.getDocumentInformation().getAuthor();
|
||||||
|
Set<String> authorNames = new HashSet<>();
|
||||||
|
if (authorNamesUnsplit.contains("&")) {
|
||||||
|
authorNames.addAll(Arrays.asList(authorNamesUnsplit.split("&")));
|
||||||
|
} else if (authorNamesUnsplit.contains(",")) {
|
||||||
|
authorNames.addAll(Arrays.asList(authorNamesUnsplit.split(",")));
|
||||||
|
} else {
|
||||||
|
authorNames.add(authorNamesUnsplit);
|
||||||
|
}
|
||||||
|
for (String authorName : authorNames) {
|
||||||
|
authorName = authorName.trim();
|
||||||
|
Optional<Author> authorOptional = authorRepository.findByName(authorName);
|
||||||
|
Author author;
|
||||||
|
if (authorOptional.isPresent()) {
|
||||||
|
author = authorOptional.get();
|
||||||
|
book.getAuthors().add(author);
|
||||||
|
author.getBooks().add(book);
|
||||||
|
} else {
|
||||||
|
author = Author.builder()
|
||||||
|
.name(authorName)
|
||||||
|
.build();
|
||||||
|
author.setBooks(new ArrayList<>());
|
||||||
|
author.getBooks().add(book);
|
||||||
|
book.setAuthors(new ArrayList<>());
|
||||||
|
book.getAuthors().add(author);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
generateCoverImage(bookFile, coverDirectory, document);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("Failed to parse: {}", bookFile.getName());
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return book;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateCoverImage(File bookFile, File coverDirectory, PDDocument document) throws IOException {
|
||||||
|
PDFRenderer renderer = new PDFRenderer(document);
|
||||||
|
BufferedImage coverImage = renderer.renderImageWithDPI(0, 300, ImageType.RGB);
|
||||||
|
BufferedImage resizedImage = resizeImage(coverImage, 250, 350);
|
||||||
|
String coverImageName = getFileNameWithoutExtension(bookFile.getName()) + ".jpg";
|
||||||
|
File coverImageFile = new File(coverDirectory, coverImageName);
|
||||||
|
ImageIO.write(resizedImage, "JPEG", coverImageFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BufferedImage resizeImage(BufferedImage originalImage, int width, int height) {
|
||||||
|
Image tmp = originalImage.getScaledInstance(width, height, Image.SCALE_SMOOTH);
|
||||||
|
BufferedImage resizedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||||
|
Graphics2D g2d = resizedImage.createGraphics();
|
||||||
|
g2d.drawImage(tmp, 0, 0, null);
|
||||||
|
g2d.dispose();
|
||||||
|
return resizedImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getFileNameWithoutExtension(String fileName) {
|
||||||
|
int dotIndex = fileName.lastIndexOf('.');
|
||||||
|
if (dotIndex == -1) {
|
||||||
|
return fileName;
|
||||||
|
} else {
|
||||||
|
return fileName.substring(0, dotIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package com.adityachandel.booklore.transformer;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.dto.AuthorDTO;
|
||||||
|
import com.adityachandel.booklore.entity.Author;
|
||||||
|
|
||||||
|
public class AuthorTransformer {
|
||||||
|
|
||||||
|
public static AuthorDTO toAuthorDTO(Author author) {
|
||||||
|
return AuthorDTO.builder()
|
||||||
|
.name(author.getName())
|
||||||
|
.id(author.getId())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
package com.adityachandel.booklore.transformer;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.dto.BookDTO;
|
||||||
|
import com.adityachandel.booklore.entity.Book;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class BookTransformer {
|
||||||
|
|
||||||
|
public static BookDTO convertToBookDTO(Book book) {
|
||||||
|
BookDTO bookDTO = new BookDTO();
|
||||||
|
bookDTO.setId(book.getId());
|
||||||
|
bookDTO.setLibraryId(book.getLibrary().getId());
|
||||||
|
bookDTO.setFileName(book.getFileName());
|
||||||
|
bookDTO.setTitle(book.getTitle());
|
||||||
|
bookDTO.setAuthors(book.getAuthors().stream().map(AuthorTransformer::toAuthorDTO).collect(Collectors.toList()));
|
||||||
|
return bookDTO;
|
||||||
|
}
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
package com.adityachandel.booklore.transformer;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.dto.LibraryDTO;
|
||||||
|
import com.adityachandel.booklore.dto.request.CreateLibraryRequest;
|
||||||
|
import com.adityachandel.booklore.entity.Library;
|
||||||
|
|
||||||
|
public class LibraryTransformer {
|
||||||
|
|
||||||
|
public static LibraryDTO convertToLibraryDTO(Library library) {
|
||||||
|
return LibraryDTO.builder()
|
||||||
|
.id(library.getId())
|
||||||
|
.name(library.getName())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Library createLibraryFromRequest(CreateLibraryRequest request) {
|
||||||
|
return Library.builder()
|
||||||
|
.name(request.getName())
|
||||||
|
.paths(request.getPaths())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
app:
|
||||||
|
path-book: '/Users/aditya.chandel/my-library-temp/books'
|
||||||
|
path-config: '/Users/aditya.chandel/my-library-temp/config'
|
||||||
|
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: booklore-api
|
||||||
|
datasource:
|
||||||
|
driver-class-name: org.mariadb.jdbc.Driver
|
||||||
|
url: ${SOLITUDE_API_MARIADB_URL:jdbc:mariadb://localhost:3306/booklore}
|
||||||
|
username: ${SOLITUDE_API_MARIADB_USERNAME:root}
|
||||||
|
password: ${SOLITUDE_API_MARIADB_PASSWORD:cfcNEBdUm6QerR6oo2UM}
|
||||||
|
jpa:
|
||||||
|
hibernate:
|
||||||
|
naming:
|
||||||
|
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
|
||||||
|
show-sql: false
|
||||||
|
properties:
|
||||||
|
hibernate:
|
||||||
|
jdbc:
|
||||||
|
batch_size: 500
|
||||||
|
order_inserts: true
|
||||||
|
order_updates: true
|
||||||
|
flyway:
|
||||||
|
enabled: true
|
||||||
|
locations: classpath:db/migration
|
||||||
|
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
root: INFO
|
||||||
|
org.apache.fontbox: ERROR
|
||||||
|
org.apache.pdfbox: ERROR
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS library
|
||||||
|
(
|
||||||
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name VARCHAR(255) UNIQUE NOT NULL,
|
||||||
|
paths BLOB
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS book
|
||||||
|
(
|
||||||
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
title VARCHAR(255),
|
||||||
|
file_name VARCHAR(255) NOT NULL,
|
||||||
|
library_id BIGINT NOT NULL,
|
||||||
|
path VARCHAR(1000) NOT NULL,
|
||||||
|
CONSTRAINT fk_library FOREIGN KEY (library_id) REFERENCES library (id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT unique_file_library UNIQUE (file_name, library_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS author
|
||||||
|
(
|
||||||
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name VARCHAR(255),
|
||||||
|
CONSTRAINT unique_name UNIQUE (name)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS book_author_mapping
|
||||||
|
(
|
||||||
|
book_id BIGINT NOT NULL,
|
||||||
|
author_id BIGINT NOT NULL,
|
||||||
|
CONSTRAINT fk_book_author_mapping_book FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_book_author_mapping_author FOREIGN KEY (author_id) REFERENCES author (id),
|
||||||
|
CONSTRAINT unique_book_author UNIQUE (book_id, author_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS book_viewer_setting
|
||||||
|
(
|
||||||
|
book_id BIGINT PRIMARY KEY,
|
||||||
|
page_number INT DEFAULT 1,
|
||||||
|
zoom VARCHAR(32) DEFAULT 'page-fit',
|
||||||
|
sidebar_visible BOOLEAN DEFAULT false,
|
||||||
|
spread VARCHAR(32) DEFAULT 'off',
|
||||||
|
CONSTRAINT fk_book_viewer_setting FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.adityachandel.booklore;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
class BookloreApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Editor configuration, see https://editorconfig.org
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.ts]
|
||||||
|
quote_type = single
|
||||||
|
ij_typescript_use_double_quotes = false
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
max_line_length = off
|
||||||
|
trim_trailing_whitespace = false
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
# See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files.
|
||||||
|
|
||||||
|
# Compiled output
|
||||||
|
/dist
|
||||||
|
/tmp
|
||||||
|
/out-tsc
|
||||||
|
/bazel-out
|
||||||
|
|
||||||
|
# Node
|
||||||
|
/node_modules
|
||||||
|
npm-debug.log
|
||||||
|
yarn-error.log
|
||||||
|
|
||||||
|
# IDEs and editors
|
||||||
|
.idea/
|
||||||
|
.project
|
||||||
|
.classpath
|
||||||
|
.c9/
|
||||||
|
*.launch
|
||||||
|
.settings/
|
||||||
|
*.sublime-workspace
|
||||||
|
|
||||||
|
# Visual Studio Code
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.history/*
|
||||||
|
|
||||||
|
# Miscellaneous
|
||||||
|
/.angular/cache
|
||||||
|
.sass-cache/
|
||||||
|
/connect.lock
|
||||||
|
/coverage
|
||||||
|
/libpeerconnection.log
|
||||||
|
testem.log
|
||||||
|
/typings
|
||||||
|
|
||||||
|
# System files
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
# BookLore
|
||||||
|
|
||||||
|
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.0.2.
|
||||||
|
|
||||||
|
## Development server
|
||||||
|
|
||||||
|
To start a local development server, run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ng serve
|
||||||
|
```
|
||||||
|
|
||||||
|
Once the server is running, open your browser and navigate to `http://localhost:4200/`. The application will automatically reload whenever you modify any of the source files.
|
||||||
|
|
||||||
|
## Code scaffolding
|
||||||
|
|
||||||
|
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ng generate component component-name
|
||||||
|
```
|
||||||
|
|
||||||
|
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ng generate --help
|
||||||
|
```
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
To build the project run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ng build
|
||||||
|
```
|
||||||
|
|
||||||
|
This will compile your project and store the build artifacts in the `dist/` directory. By default, the production build optimizes your application for performance and speed.
|
||||||
|
|
||||||
|
## Running unit tests
|
||||||
|
|
||||||
|
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ng test
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running end-to-end tests
|
||||||
|
|
||||||
|
For end-to-end (e2e) testing, run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ng e2e
|
||||||
|
```
|
||||||
|
|
||||||
|
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
|
||||||
|
|
||||||
|
## Additional Resources
|
||||||
|
|
||||||
|
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
{
|
||||||
|
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||||
|
"version": 1,
|
||||||
|
"newProjectRoot": "projects",
|
||||||
|
"projects": {
|
||||||
|
"booklore": {
|
||||||
|
"projectType": "application",
|
||||||
|
"schematics": {
|
||||||
|
"@schematics/angular:component": {
|
||||||
|
"style": "scss",
|
||||||
|
"standalone": false
|
||||||
|
},
|
||||||
|
"@schematics/angular:directive": {
|
||||||
|
"standalone": false
|
||||||
|
},
|
||||||
|
"@schematics/angular:pipe": {
|
||||||
|
"standalone": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "",
|
||||||
|
"sourceRoot": "src",
|
||||||
|
"prefix": "app",
|
||||||
|
"architect": {
|
||||||
|
"build": {
|
||||||
|
"builder": "@angular-devkit/build-angular:application",
|
||||||
|
"options": {
|
||||||
|
"outputPath": "dist/booklore",
|
||||||
|
"index": "src/index.html",
|
||||||
|
"browser": "src/main.ts",
|
||||||
|
"polyfills": [
|
||||||
|
"zone.js"
|
||||||
|
],
|
||||||
|
"tsConfig": "tsconfig.app.json",
|
||||||
|
"inlineStyleLanguage": "scss",
|
||||||
|
"assets": [
|
||||||
|
"src/favicon.ico",
|
||||||
|
"src/assets",
|
||||||
|
{
|
||||||
|
"glob": "**/*",
|
||||||
|
"input": "public"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"glob": "**/*",
|
||||||
|
"input": "node_modules/ngx-extended-pdf-viewer/assets/",
|
||||||
|
"output": "/assets/"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"styles": [
|
||||||
|
"src/styles.scss"
|
||||||
|
],
|
||||||
|
"scripts": []
|
||||||
|
},
|
||||||
|
"configurations": {
|
||||||
|
"production": {
|
||||||
|
"budgets": [
|
||||||
|
{
|
||||||
|
"type": "initial",
|
||||||
|
"maximumWarning": "500kB",
|
||||||
|
"maximumError": "1MB"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "anyComponentStyle",
|
||||||
|
"maximumWarning": "4kB",
|
||||||
|
"maximumError": "8kB"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputHashing": "all"
|
||||||
|
},
|
||||||
|
"development": {
|
||||||
|
"optimization": false,
|
||||||
|
"extractLicenses": false,
|
||||||
|
"sourceMap": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultConfiguration": "production"
|
||||||
|
},
|
||||||
|
"serve": {
|
||||||
|
"builder": "@angular-devkit/build-angular:dev-server",
|
||||||
|
"configurations": {
|
||||||
|
"production": {
|
||||||
|
"buildTarget": "booklore:build:production"
|
||||||
|
},
|
||||||
|
"development": {
|
||||||
|
"buildTarget": "booklore:build:development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultConfiguration": "development"
|
||||||
|
},
|
||||||
|
"extract-i18n": {
|
||||||
|
"builder": "@angular-devkit/build-angular:extract-i18n"
|
||||||
|
},
|
||||||
|
"test": {
|
||||||
|
"builder": "@angular-devkit/build-angular:karma",
|
||||||
|
"options": {
|
||||||
|
"polyfills": [
|
||||||
|
"zone.js",
|
||||||
|
"zone.js/testing"
|
||||||
|
],
|
||||||
|
"tsConfig": "tsconfig.spec.json",
|
||||||
|
"inlineStyleLanguage": "scss",
|
||||||
|
"assets": [
|
||||||
|
{
|
||||||
|
"glob": "**/*",
|
||||||
|
"input": "public"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"styles": [
|
||||||
|
"src/styles.scss"
|
||||||
|
],
|
||||||
|
"scripts": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+15240
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,43 @@
|
|||||||
|
{
|
||||||
|
"name": "booklore",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"scripts": {
|
||||||
|
"ng": "ng",
|
||||||
|
"start": "ng serve",
|
||||||
|
"build": "ng build",
|
||||||
|
"watch": "ng build --watch --configuration development",
|
||||||
|
"test": "ng test"
|
||||||
|
},
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@angular/animations": "^19.0.0",
|
||||||
|
"@angular/common": "^19.0.0",
|
||||||
|
"@angular/compiler": "^19.0.0",
|
||||||
|
"@angular/core": "^19.0.0",
|
||||||
|
"@angular/forms": "^19.0.0",
|
||||||
|
"@angular/platform-browser": "^19.0.0",
|
||||||
|
"@angular/platform-browser-dynamic": "^19.0.0",
|
||||||
|
"@angular/router": "^19.0.0",
|
||||||
|
"ngx-extended-pdf-viewer": "^22.0.0",
|
||||||
|
"ngx-infinite-scroll": "^19.0.0",
|
||||||
|
"primeflex": "^3.3.1",
|
||||||
|
"primeicons": "^7.0.0",
|
||||||
|
"primeng": "^17.18.12",
|
||||||
|
"rxjs": "~7.8.0",
|
||||||
|
"tslib": "^2.3.0",
|
||||||
|
"zone.js": "~0.15.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@angular-devkit/build-angular": "^19.0.2",
|
||||||
|
"@angular/cli": "^19.0.2",
|
||||||
|
"@angular/compiler-cli": "^19.0.0",
|
||||||
|
"@types/jasmine": "~5.1.0",
|
||||||
|
"jasmine-core": "~5.4.0",
|
||||||
|
"karma": "~6.4.0",
|
||||||
|
"karma-chrome-launcher": "~3.2.0",
|
||||||
|
"karma-coverage": "~2.2.0",
|
||||||
|
"karma-jasmine": "~5.1.0",
|
||||||
|
"karma-jasmine-html-reporter": "~2.1.0",
|
||||||
|
"typescript": "~5.6.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -0,0 +1,31 @@
|
|||||||
|
import {NgModule} from '@angular/core';
|
||||||
|
import {RouterModule, Routes} from '@angular/router';
|
||||||
|
import {AppLayoutComponent} from './layout/app.layout.component';
|
||||||
|
import {LibraryBrowserComponent} from './book/component/library-browser/library-browser.component';
|
||||||
|
import {PdfViewerComponent} from './book/component/pdf-viewer/pdf-viewer.component';
|
||||||
|
import {DashboardComponent} from './book/component/dashboard/dashboard.component';
|
||||||
|
|
||||||
|
const routes: Routes = [
|
||||||
|
{
|
||||||
|
path: '', component: AppLayoutComponent,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: '', component: DashboardComponent,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'library/:libraryId/books', component: LibraryBrowserComponent,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'pdf-viewer/book/:bookId',
|
||||||
|
component: PdfViewerComponent
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [RouterModule.forRoot(routes)],
|
||||||
|
exports: [RouterModule]
|
||||||
|
})
|
||||||
|
export class AppRoutingModule {
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<router-outlet></router-outlet>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import {Component} from '@angular/core';
|
||||||
|
import {LibraryService} from './book/service/library.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-root',
|
||||||
|
templateUrl: './app.component.html',
|
||||||
|
standalone: false,
|
||||||
|
styleUrl: './app.component.scss'
|
||||||
|
})
|
||||||
|
export class AppComponent {
|
||||||
|
constructor(private libraryService: LibraryService) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import {NgModule} from '@angular/core';
|
||||||
|
import {BrowserModule} from '@angular/platform-browser';
|
||||||
|
|
||||||
|
import {AppRoutingModule} from './app-routing.module';
|
||||||
|
import {AppComponent} from './app.component';
|
||||||
|
import {AppLayoutModule} from './layout/app.layout.module';
|
||||||
|
import {FormsModule} from '@angular/forms';
|
||||||
|
import {DialogService} from 'primeng/dynamicdialog';
|
||||||
|
import {DirectoryPickerComponent} from './book/component/directory-picker/directory-picker.component';
|
||||||
|
import {InputTextModule} from 'primeng/inputtext';
|
||||||
|
import {TableModule} from 'primeng/table';
|
||||||
|
import {Button} from 'primeng/button';
|
||||||
|
import {LibraryCreatorComponent} from './book/component/library-creator/library-creator.component';
|
||||||
|
import {StepperModule} from 'primeng/stepper';
|
||||||
|
import {IconFieldModule} from 'primeng/iconfield';
|
||||||
|
import {InputIconModule} from 'primeng/inputicon';
|
||||||
|
import {ToggleButtonModule} from 'primeng/togglebutton';
|
||||||
|
import {PasswordModule} from 'primeng/password';
|
||||||
|
import {ToastModule} from 'primeng/toast';
|
||||||
|
import { LibraryBrowserComponent } from './book/component/library-browser/library-browser.component';
|
||||||
|
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
|
||||||
|
import { SearchComponent } from './book/component/search/search.component';
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
declarations: [
|
||||||
|
AppComponent,
|
||||||
|
DirectoryPickerComponent,
|
||||||
|
LibraryCreatorComponent,
|
||||||
|
LibraryBrowserComponent
|
||||||
|
],
|
||||||
|
imports: [
|
||||||
|
BrowserModule,
|
||||||
|
AppRoutingModule,
|
||||||
|
AppLayoutModule,
|
||||||
|
FormsModule,
|
||||||
|
InputTextModule,
|
||||||
|
TableModule,
|
||||||
|
Button,
|
||||||
|
StepperModule,
|
||||||
|
IconFieldModule,
|
||||||
|
InputIconModule,
|
||||||
|
ToggleButtonModule,
|
||||||
|
PasswordModule,
|
||||||
|
ToastModule,
|
||||||
|
InfiniteScrollDirective,
|
||||||
|
SearchComponent,
|
||||||
|
],
|
||||||
|
providers: [DialogService],
|
||||||
|
bootstrap: [AppComponent]
|
||||||
|
})
|
||||||
|
export class AppModule { }
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<div class="dashboard">
|
||||||
|
<h1 *ngIf="isLibrariesEmpty" class="no-library-header">
|
||||||
|
Looks like you haven't added a library yet. Let's add one!
|
||||||
|
</h1>
|
||||||
|
<p-button *ngIf="isLibrariesEmpty"
|
||||||
|
label="Add a Library"
|
||||||
|
icon="pi pi-plus"
|
||||||
|
styleClass="p-button-rounded p-button-outlined"
|
||||||
|
(click)="createNewLibrary($event)">
|
||||||
|
</p-button>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
.dashboard {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
margin-top: 5rem;
|
||||||
|
text-align: center;
|
||||||
|
|
||||||
|
.no-library-header {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
color: var(--text-color)
|
||||||
|
}
|
||||||
|
.p-dialog {
|
||||||
|
max-width: 90%; /* Ensure the dialog doesn't overflow the viewport */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
::ng-deep .p-dialog-mask {
|
||||||
|
background-color: rgba(0, 0, 0, 0.5); /* Darken the background with 50% opacity */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* You can also adjust the blur if you want */
|
||||||
|
::ng-deep .p-dialog-mask {
|
||||||
|
backdrop-filter: blur(3px); /* Optional: Apply blur to the background */
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import { Component, WritableSignal } from '@angular/core';
|
||||||
|
import { LibraryService } from '../../service/library.service';
|
||||||
|
import { Library } from '../../model/library.model';
|
||||||
|
import { Button } from 'primeng/button';
|
||||||
|
import { NgIf } from '@angular/common';
|
||||||
|
import { LibraryCreatorComponent } from '../library-creator/library-creator.component';
|
||||||
|
import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-home-page',
|
||||||
|
templateUrl: './dashboard.component.html',
|
||||||
|
imports: [
|
||||||
|
Button,
|
||||||
|
NgIf
|
||||||
|
],
|
||||||
|
styleUrls: ['./dashboard.component.scss'],
|
||||||
|
providers: [DialogService], // Ensure the DialogService is available
|
||||||
|
})
|
||||||
|
export class DashboardComponent {
|
||||||
|
private libraries: WritableSignal<Library[]>;
|
||||||
|
ref: DynamicDialogRef | undefined;
|
||||||
|
|
||||||
|
constructor(private libraryService: LibraryService, public dialogService: DialogService) {
|
||||||
|
this.libraries = this.libraryService.libraries;
|
||||||
|
}
|
||||||
|
|
||||||
|
get isLibrariesEmpty(): boolean {
|
||||||
|
return this.libraries()?.length === 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
createNewLibrary(event: MouseEvent) {
|
||||||
|
const buttonRect = (event.target as HTMLElement).getBoundingClientRect();
|
||||||
|
|
||||||
|
const dialogWidthPercentage = 50; // Use percentage-based width
|
||||||
|
const viewportWidth = window.innerWidth;
|
||||||
|
const dialogWidth = (dialogWidthPercentage / 100) * viewportWidth;
|
||||||
|
|
||||||
|
const leftPosition = buttonRect.left + (buttonRect.width / 2) - (dialogWidth / 2);
|
||||||
|
|
||||||
|
this.ref = this.dialogService.open(LibraryCreatorComponent, {
|
||||||
|
modal: true,
|
||||||
|
width: `${dialogWidthPercentage}%`, // Dynamic width
|
||||||
|
height: 'auto', // Let height adapt to content
|
||||||
|
style: {
|
||||||
|
position: 'absolute',
|
||||||
|
top: `${buttonRect.bottom + 10}px`, // Position below the button
|
||||||
|
left: `${Math.max(leftPosition, 0)}px`, // Ensure it stays within the viewport
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<div style="margin-bottom: 1.5rem; display: flex; align-items: center; gap: 1rem;">
|
||||||
|
<input
|
||||||
|
id="disabled-input"
|
||||||
|
type="text"
|
||||||
|
pInputText
|
||||||
|
[value]="selectedProductName"
|
||||||
|
[disabled]="true"
|
||||||
|
[ngStyle]="{ 'width': '100%', 'padding': '0.5rem', 'font-size': '1rem' }"
|
||||||
|
/>
|
||||||
|
<p-button label="Select" severity="success" [ngStyle]="{ 'width': '100px' }" (click)="onSelect()"/>
|
||||||
|
</div>
|
||||||
|
<ng-container>
|
||||||
|
<div style="overflow-x: auto;">
|
||||||
|
<p-table [value]="paths" [tableStyle]="{ 'min-width': '50rem' }" class="product-table">
|
||||||
|
<ng-template pTemplate="header">
|
||||||
|
<tr>
|
||||||
|
<th [style.width]="'10%'">Type</th>
|
||||||
|
<th [style.width]="'90%'">Name</th>
|
||||||
|
</tr>
|
||||||
|
</ng-template>
|
||||||
|
|
||||||
|
<ng-template pTemplate="body" let-product>
|
||||||
|
<tr (click)="onRowClick(product)">
|
||||||
|
<td>
|
||||||
|
<i *ngIf="product === '...'" class="pi pi-arrow-up"></i>
|
||||||
|
<i *ngIf="product !== '...'" class="pi pi-folder-open"></i>
|
||||||
|
</td>
|
||||||
|
<td>{{ product }}</td>
|
||||||
|
</tr>
|
||||||
|
</ng-template>
|
||||||
|
</p-table>
|
||||||
|
</div>
|
||||||
|
</ng-container>
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import {Component, OnInit} from '@angular/core';
|
||||||
|
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||||
|
import {UtilityService} from '../../service/utility.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-directory-picker-v2',
|
||||||
|
standalone: false,
|
||||||
|
templateUrl: './directory-picker.component.html',
|
||||||
|
styleUrls: ['./directory-picker.component.scss']
|
||||||
|
})
|
||||||
|
export class DirectoryPickerComponent implements OnInit {
|
||||||
|
value: any;
|
||||||
|
paths: string[] = ['...'];
|
||||||
|
selectedProductName: string = '';
|
||||||
|
|
||||||
|
constructor(private utilityService: UtilityService, private dynamicDialogRef: DynamicDialogRef) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
const initialPath = '/';
|
||||||
|
this.getFolders(initialPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
getFolders(path: string): void {
|
||||||
|
this.utilityService.getFolders(path).subscribe(
|
||||||
|
(folders: string[]) => {
|
||||||
|
this.paths = ['...', ...folders];
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
console.error('Error fetching folders:', error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
onRowClick(path: string): void {
|
||||||
|
if (path === '...') {
|
||||||
|
if (this.selectedProductName === '' || this.selectedProductName === '/') {
|
||||||
|
this.getFolders('/');
|
||||||
|
} else {
|
||||||
|
const result = this.selectedProductName.substring(0, this.selectedProductName.lastIndexOf('/')) || '/';
|
||||||
|
this.selectedProductName = result;
|
||||||
|
this.getFolders(result);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.selectedProductName = path;
|
||||||
|
this.getFolders(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onSelect(): void {
|
||||||
|
this.dynamicDialogRef.close(this.selectedProductName);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<div class="book-list" infiniteScroll [infiniteScrollDistance]="2" [infiniteScrollThrottle]="50" (scrolled)="loadMore()">
|
||||||
|
<div class="book-item" *ngFor="let book of books">
|
||||||
|
<img [src]="coverImageSrc(book.id)" class="book-cover placeholder" alt="Cover of {{ book.title }}" loading="lazy"/>
|
||||||
|
<div class="book-info">
|
||||||
|
<h4>{{ book.title }}</h4>
|
||||||
|
<p>{{ getAuthorNames(book) }}</p>
|
||||||
|
<p-button label="View" icon="pi pi-eye" class="view-btn" (click)="openBook(book.id)"></p-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
.book-list {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-item {
|
||||||
|
color: #fff;
|
||||||
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
|
||||||
|
overflow: hidden;
|
||||||
|
transition: transform 0.3s ease-in-out;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
height: auto;
|
||||||
|
background-color: var(--surface-card);
|
||||||
|
border-radius: 8px;
|
||||||
|
position: relative; /* Positioning container for the button and overlay */
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-cover {
|
||||||
|
width: 100%;
|
||||||
|
height: 225px; /* Adjust this as per the image height */
|
||||||
|
object-fit: cover;
|
||||||
|
background-color: #444;
|
||||||
|
transition: background-color 0.3s ease, filter 0.3s ease; /* Add transition for blur effect */
|
||||||
|
position: relative; /* Make this the reference point for the overlay */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Blur and overlay effect */
|
||||||
|
.book-item:hover .book-cover {
|
||||||
|
filter: blur(2px); /* Apply blur effect to the image */
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-item:hover .book-cover::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background: rgba(0, 0, 0, 0.5); /* Semi-transparent black overlay */
|
||||||
|
z-index: 0; /* Put overlay behind the button */
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-info {
|
||||||
|
padding: 10px;
|
||||||
|
text-align: center;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: flex-start;
|
||||||
|
flex-grow: 1;
|
||||||
|
z-index: 1; /* Ensure the text stays above the overlay */
|
||||||
|
}
|
||||||
|
|
||||||
|
h4 {
|
||||||
|
font-size: 1rem;
|
||||||
|
color: var(--text-color);
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
max-width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
color: var(--text-color-secondary);
|
||||||
|
font-size: 0.8rem;
|
||||||
|
line-height: 1.4;
|
||||||
|
margin-top: 0;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
max-width: 100%;
|
||||||
|
margin-bottom: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.authors {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.no-authors {
|
||||||
|
color: #888;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* PrimeNG button styling */
|
||||||
|
.view-btn {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%); /* Center button on the image */
|
||||||
|
display: none; /* Hide by default */
|
||||||
|
z-index: 1; /* Ensure it appears over the image */
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-item:hover .view-btn {
|
||||||
|
display: block; /* Show the button when the card is hovered */
|
||||||
|
}
|
||||||
|
|
||||||
|
.infinite-scroll {
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { BookService } from '../../service/book.service';
|
||||||
|
import { Book } from '../../model/book.model';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-library-browser-v2',
|
||||||
|
standalone: false,
|
||||||
|
templateUrl: './library-browser.component.html',
|
||||||
|
styleUrls: ['./library-browser.component.scss'],
|
||||||
|
})
|
||||||
|
export class LibraryBrowserComponent implements OnInit {
|
||||||
|
books: Book[] = [];
|
||||||
|
private libraryId: number = 1;
|
||||||
|
private currentPage: number = 0;
|
||||||
|
|
||||||
|
constructor(private bookService: BookService, private route: ActivatedRoute) {}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.route.paramMap.subscribe((params) => {
|
||||||
|
const libraryId = params.get('libraryId');
|
||||||
|
if (libraryId) {
|
||||||
|
this.libraryId = +libraryId;
|
||||||
|
this.resetState();
|
||||||
|
this.loadBooks();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
resetState(): void {
|
||||||
|
this.books = [];
|
||||||
|
this.currentPage = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
loadBooks(): void {
|
||||||
|
this.bookService.loadBooks(this.libraryId, this.currentPage).subscribe({
|
||||||
|
next: (response) => {
|
||||||
|
this.books = [...this.books, ...response.content];
|
||||||
|
this.currentPage++;
|
||||||
|
},
|
||||||
|
error: (err) => {
|
||||||
|
console.error('Error loading books:', err);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
coverImageSrc(bookId: number): string {
|
||||||
|
return this.bookService.getBookCoverUrl(bookId);
|
||||||
|
}
|
||||||
|
|
||||||
|
loadMore(): void {
|
||||||
|
this.loadBooks();
|
||||||
|
}
|
||||||
|
|
||||||
|
getAuthorNames(book: Book): string {
|
||||||
|
return book.authors?.map((author) => author.name).join(', ') || 'No authors available';
|
||||||
|
}
|
||||||
|
|
||||||
|
openBook(bookId: number): void {
|
||||||
|
const url = `/pdf-viewer/book/${bookId}`;
|
||||||
|
window.open(url, '_blank');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
<p-stepper>
|
||||||
|
<p-stepperPanel header="Library Name">
|
||||||
|
<ng-template pTemplate="content" let-nextCallback="nextCallback" let-index="index">
|
||||||
|
<div class="flex flex-column h-21rem">
|
||||||
|
<div
|
||||||
|
class="border-2 border-dashed surface-border border-round surface-ground flex-auto flex justify-content-center align-items-center font-medium">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
pInputText
|
||||||
|
[(ngModel)]="value"
|
||||||
|
placeholder="Enter library name..."/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex pt-4 justify-content-end">
|
||||||
|
<p-button
|
||||||
|
label="Next"
|
||||||
|
icon="pi pi-arrow-right"
|
||||||
|
iconPos="right"
|
||||||
|
(onClick)="nextCallback.emit()"/>
|
||||||
|
</div>
|
||||||
|
</ng-template>
|
||||||
|
</p-stepperPanel>
|
||||||
|
<p-stepperPanel header="Media Location">
|
||||||
|
<ng-template pTemplate="content" let-prevCallback="prevCallback" let-index="index">
|
||||||
|
<div class="flex flex-column">
|
||||||
|
<div
|
||||||
|
class="border-2 border-dashed surface-border border-round surface-ground flex-auto flex align-items-start"
|
||||||
|
style="padding-top: 2.5rem;">
|
||||||
|
<div class="flex flex-column justify-content-center align-items-center w-100">
|
||||||
|
<p-button
|
||||||
|
severity="secondary"
|
||||||
|
label="Browse for media folders"
|
||||||
|
(onClick)="show()">
|
||||||
|
</p-button>
|
||||||
|
<p-table [value]="folders" styleClass="p-datatable-striped" class="p-table-custom mt-3">
|
||||||
|
<ng-template pTemplate="body" let-folder let-i="rowIndex">
|
||||||
|
<tr>
|
||||||
|
<td class="tr-custom">{{ folder }}</td>
|
||||||
|
<td class="tr-custom td-x-custom">
|
||||||
|
<p-button
|
||||||
|
icon="pi pi-times"
|
||||||
|
[rounded]="true"
|
||||||
|
[text]="true"
|
||||||
|
severity="danger"
|
||||||
|
(onClick)="removeFolder(i)"
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</ng-template>
|
||||||
|
</p-table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex pt-4 justify-content-between">
|
||||||
|
<p-button label="Back" icon="pi pi-arrow-left" (onClick)="prevCallback.emit()"/>
|
||||||
|
<p-button severity="success" label="Save" icon="pi pi-save" (onClick)="addLibrary()"></p-button>
|
||||||
|
</div>
|
||||||
|
</ng-template>
|
||||||
|
</p-stepperPanel>
|
||||||
|
</p-stepper>
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
.container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
position: relative;
|
||||||
|
height: 100%; /* Fills the parent container */
|
||||||
|
}
|
||||||
|
|
||||||
|
.textbox {
|
||||||
|
padding: 10px;
|
||||||
|
margin-bottom: 20px; /* Space between textbox and button */
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 10px;
|
||||||
|
left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tr-custom {
|
||||||
|
padding: 0.25rem 0.5rem !important;
|
||||||
|
border: 0px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-table-custom {
|
||||||
|
margin: 1.5rem !important;
|
||||||
|
min-width: 35rem !important;
|
||||||
|
max-height: 11.25rem !important;
|
||||||
|
overflow: scroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
.td-x-custom {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mt-3 {
|
||||||
|
margin-top: 1rem; /* Adds spacing between the button and the table */
|
||||||
|
}
|
||||||
|
|
||||||
|
.w-100 {
|
||||||
|
width: 100%; /* Ensures full-width alignment for consistent layout */
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
import {Component} from '@angular/core';
|
||||||
|
import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||||
|
import {DirectoryPickerComponent} from '../directory-picker/directory-picker.component';
|
||||||
|
import {MessageService} from 'primeng/api';
|
||||||
|
import {LibraryService} from '../../service/library.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-library-creator',
|
||||||
|
standalone: false,
|
||||||
|
templateUrl: './library-creator.component.html',
|
||||||
|
styleUrl: './library-creator.component.scss',
|
||||||
|
providers: [MessageService]
|
||||||
|
})
|
||||||
|
export class LibraryCreatorComponent {
|
||||||
|
value: string = '';
|
||||||
|
folders: string[] = [];
|
||||||
|
ref: DynamicDialogRef | undefined;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
public dialogService: DialogService,
|
||||||
|
private dynamicDialogRef: DynamicDialogRef,
|
||||||
|
private messageService: MessageService,
|
||||||
|
private libraryServiceV2: LibraryService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
show() {
|
||||||
|
this.ref = this.dialogService.open(DirectoryPickerComponent, {
|
||||||
|
header: 'Select Media Directory',
|
||||||
|
modal: false,
|
||||||
|
width: '50%',
|
||||||
|
height: '75%',
|
||||||
|
contentStyle: { overflow: 'auto' },
|
||||||
|
baseZIndex: 10
|
||||||
|
});
|
||||||
|
|
||||||
|
this.ref.onClose.subscribe((selectedFolder: string) => {
|
||||||
|
if (selectedFolder) {
|
||||||
|
this.addFolder(selectedFolder);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
addFolder(folder: string): void {
|
||||||
|
this.folders.push(folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeFolder(index: number): void {
|
||||||
|
this.folders.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
addLibrary() {
|
||||||
|
const newLibrary = {
|
||||||
|
name: this.value,
|
||||||
|
paths: this.folders,
|
||||||
|
};
|
||||||
|
this.libraryServiceV2.createLibrary(newLibrary).subscribe({
|
||||||
|
next: (createdLibrary) => {
|
||||||
|
console.log('Library successfully created:', createdLibrary);
|
||||||
|
},
|
||||||
|
error: (err) => {
|
||||||
|
console.error('Failed to create library:', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.dynamicDialogRef.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
validateLibraryNameAndProceed(nextCallback: any) {
|
||||||
|
if (this.value.trim()) {
|
||||||
|
this.libraryServiceV2.checkLibraryNameExists(this.value).subscribe(
|
||||||
|
(response) => {
|
||||||
|
const libraryExists = response && response.name === this.value;
|
||||||
|
if (libraryExists) {
|
||||||
|
this.messageService.add({
|
||||||
|
severity: 'error',
|
||||||
|
summary: 'Library Name Exists',
|
||||||
|
detail: 'This library name is already taken.',
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
nextCallback.emit();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
this.messageService.add({
|
||||||
|
severity: 'error',
|
||||||
|
summary: 'Error',
|
||||||
|
detail: 'An error occurred while checking the library name.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<ngx-extended-pdf-viewer
|
||||||
|
[src]="getSrc()"
|
||||||
|
[handTool]="handTool"
|
||||||
|
[height]="'auto'"
|
||||||
|
[page]="page"
|
||||||
|
[rotation]="rotation"
|
||||||
|
[scrollMode]="scrollMode"
|
||||||
|
[sidebarVisible]="sidebarVisible"
|
||||||
|
[zoom]="zoom"
|
||||||
|
[spread]="spread"
|
||||||
|
(pageChange)="onPageChange($event)"
|
||||||
|
(zoomChange)="onZoomChange($event)"
|
||||||
|
(sidebarVisibleChange)="onSidebarVisibleChange($event)"
|
||||||
|
(spreadChange)="onSpreadChange($event)">
|
||||||
|
</ngx-extended-pdf-viewer>
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
import { ChangeDetectorRef, Component, NgZone, OnInit } from '@angular/core';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
import { NgxExtendedPdfViewerModule, ScrollModeType } from 'ngx-extended-pdf-viewer';
|
||||||
|
import { BookService } from '../../service/book.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-pdf-viewer',
|
||||||
|
standalone: true,
|
||||||
|
imports: [NgxExtendedPdfViewerModule],
|
||||||
|
templateUrl: './pdf-viewer.component.html',
|
||||||
|
})
|
||||||
|
export class PdfViewerComponent implements OnInit {
|
||||||
|
bookId!: number;
|
||||||
|
handTool = true;
|
||||||
|
page = 1;
|
||||||
|
rotation: 0 | 90 | 180 | 270 = 0;
|
||||||
|
scrollMode: ScrollModeType = ScrollModeType.page;
|
||||||
|
sidebarVisible = false;
|
||||||
|
spread: 'off' | 'even' | 'odd' = 'odd';
|
||||||
|
src = '';
|
||||||
|
zoom: number | string = 'page-fit';
|
||||||
|
private isInitialLoad = true;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private bookService: BookService,
|
||||||
|
private zone: NgZone,
|
||||||
|
private route: ActivatedRoute
|
||||||
|
) {}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.route.paramMap.subscribe((params) => {
|
||||||
|
this.bookId = +params.get('bookId')!;
|
||||||
|
this.loadBook(this.bookId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private loadBook(bookId: number): void {
|
||||||
|
this.bookService.getBook(bookId).subscribe((book) => {
|
||||||
|
this.zone.run(() => {
|
||||||
|
const { pageNumber, zoom, sidebar_visible, spread } = book.viewerSetting;
|
||||||
|
this.page = pageNumber || 1;
|
||||||
|
this.zoom = zoom || 'page-fit';
|
||||||
|
this.sidebarVisible = sidebar_visible || false;
|
||||||
|
this.spread = spread || 'odd';
|
||||||
|
this.isInitialLoad = false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateViewerSetting(): void {
|
||||||
|
if (this.isInitialLoad) return;
|
||||||
|
const updatedViewerSetting = {
|
||||||
|
pageNumber: this.page,
|
||||||
|
zoom: this.zoom,
|
||||||
|
sidebar_visible: this.sidebarVisible,
|
||||||
|
spread: this.spread,
|
||||||
|
};
|
||||||
|
this.bookService.updateViewerSetting(updatedViewerSetting, this.bookId).subscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
onPageChange(page: number): void {
|
||||||
|
if (page !== this.page) {
|
||||||
|
this.page = page;
|
||||||
|
this.updateViewerSetting();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onZoomChange(zoom: string | number): void {
|
||||||
|
if (zoom !== this.zoom) {
|
||||||
|
this.zoom = zoom;
|
||||||
|
this.updateViewerSetting();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onSidebarVisibleChange(visible: boolean): void {
|
||||||
|
if (visible !== this.sidebarVisible) {
|
||||||
|
this.sidebarVisible = visible;
|
||||||
|
this.updateViewerSetting();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onSpreadChange(spread: 'off' | 'even' | 'odd'): void {
|
||||||
|
if (spread !== this.spread) {
|
||||||
|
this.spread = spread;
|
||||||
|
this.updateViewerSetting();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getSrc(): string {
|
||||||
|
return this.bookService.getBookDataUrl(this.bookId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<div class="search-container" #searchContainer>
|
||||||
|
<span class="p-input-icon-left">
|
||||||
|
<i class="pi pi-search"></i>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
pInputText
|
||||||
|
[(ngModel)]="searchQuery"
|
||||||
|
(input)="onSearchInputChange()"
|
||||||
|
placeholder="Search books..."
|
||||||
|
class="search-input"
|
||||||
|
#searchInput/>
|
||||||
|
<button *ngIf="searchQuery" pButton icon="pi pi-times" (click)="clearSearch()" class="clear-btn" type="button" aria-label="Clear Search"></button>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<div class="search-dropdown layout-menu" [class.show]="books.length > 0">
|
||||||
|
<div class="search-dropdown-item" *ngFor="let book of books" (click)="onBookClick(book)">
|
||||||
|
<img [src]="getBookCoverUrl(book.id)" alt="Book Cover" class="search-book-cover" />
|
||||||
|
<span class="search-book-name">{{ book.title }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
.search-container {
|
||||||
|
margin-left: 20px;
|
||||||
|
position: relative; /* Ensure the dropdown is positioned relative to the container */
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-dropdown {
|
||||||
|
position: absolute;
|
||||||
|
left: 0; /* Align the dropdown to the left of the container */
|
||||||
|
background-color: var(--surface-overlay); /* Use theme's background color */
|
||||||
|
border: 1px solid var(--surface-border);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
z-index: 1000;
|
||||||
|
max-height: 300px; /* Limit the height of the dropdown */
|
||||||
|
overflow-y: auto; /* Scroll if the content exceeds max-height */
|
||||||
|
width: 600px; /* Ensures the dropdown has the same width as the search bar */
|
||||||
|
opacity: 0;
|
||||||
|
height: 0;
|
||||||
|
transition: opacity 0.3s ease, height 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Show the dropdown */
|
||||||
|
.search-dropdown.show {
|
||||||
|
opacity: 1;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Dropdown item styles */
|
||||||
|
.search-dropdown-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.3s;
|
||||||
|
|
||||||
|
/* Hover effect */
|
||||||
|
&:hover {
|
||||||
|
background-color: var(--surface-hover);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Book cover styling */
|
||||||
|
.search-book-cover {
|
||||||
|
width: 25px; /* Set a fixed width */
|
||||||
|
height: 37px; /* Set a fixed height */
|
||||||
|
object-fit: cover; /* Ensure the image fits the area without distortion */
|
||||||
|
max-width: 100px; /* Max width to prevent images from becoming too big */
|
||||||
|
max-height: 150px; /* Max height to maintain consistency */
|
||||||
|
border-radius: 4px; /* Rounded corners */
|
||||||
|
margin-right: 10px; /* Space between the image and the title */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Book title styling */
|
||||||
|
.search-book-name {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--text-color);
|
||||||
|
flex-grow: 1; /* Allow the title to take up the remaining space */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Optionally customize the transition duration or timing */
|
||||||
|
.search-dropdown.show {
|
||||||
|
opacity: 1;
|
||||||
|
height: auto;
|
||||||
|
transition: opacity 0.3s ease, height 0.4s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.clear-btn {
|
||||||
|
color: var(--text-color-secondary);
|
||||||
|
position: absolute;
|
||||||
|
right: 10px;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||||
|
import { Subject, Subscription } from 'rxjs';
|
||||||
|
import { debounceTime, distinctUntilChanged, switchMap, catchError } from 'rxjs/operators';
|
||||||
|
import { Book } from '../../model/book.model';
|
||||||
|
import { BookService } from '../../service/book.service';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
import { InputTextModule } from 'primeng/inputtext';
|
||||||
|
import { NgForOf, NgIf } from '@angular/common';
|
||||||
|
import { ButtonDirective } from 'primeng/button';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-search',
|
||||||
|
templateUrl: './search.component.html',
|
||||||
|
imports: [
|
||||||
|
FormsModule,
|
||||||
|
InputTextModule,
|
||||||
|
NgForOf,
|
||||||
|
NgIf,
|
||||||
|
ButtonDirective
|
||||||
|
],
|
||||||
|
styleUrls: ['./search.component.scss']
|
||||||
|
})
|
||||||
|
export class SearchComponent implements OnInit, OnDestroy {
|
||||||
|
searchQuery: string = '';
|
||||||
|
books: Book[] = [];
|
||||||
|
#searchSubject = new Subject<string>();
|
||||||
|
#subscription!: Subscription;
|
||||||
|
|
||||||
|
constructor(private bookService: BookService) {}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.initializeSearch();
|
||||||
|
}
|
||||||
|
|
||||||
|
initializeSearch(): void {
|
||||||
|
this.#subscription = this.#searchSubject.pipe(
|
||||||
|
debounceTime(500),
|
||||||
|
distinctUntilChanged(),
|
||||||
|
switchMap((query) => this.bookService.searchBooks(query).pipe(
|
||||||
|
catchError((error) => {
|
||||||
|
console.error('Error while searching books:', error);
|
||||||
|
return [];
|
||||||
|
})
|
||||||
|
))
|
||||||
|
).subscribe({
|
||||||
|
next: (result: Book[]) => this.books = result,
|
||||||
|
error: (error) => console.error('Subscription error:', error)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onSearchInputChange(): void {
|
||||||
|
this.#searchSubject.next(this.searchQuery.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
onBookClick(book: Book): void {
|
||||||
|
this.clearSearch();
|
||||||
|
this.openBook(book.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
openBook(bookId: number): void {
|
||||||
|
const url = `/pdf-viewer/book/${bookId}`;
|
||||||
|
window.open(url, '_blank');
|
||||||
|
}
|
||||||
|
|
||||||
|
getBookCoverUrl(bookId: number): string {
|
||||||
|
return this.bookService.getBookCoverUrl(bookId);
|
||||||
|
}
|
||||||
|
|
||||||
|
clearSearch(): void {
|
||||||
|
this.searchQuery = '';
|
||||||
|
this.books = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
if (this.#subscription) {
|
||||||
|
this.#subscription.unsubscribe();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export interface Author {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import {Author} from './author.model';
|
||||||
|
|
||||||
|
export interface Book {
|
||||||
|
id: number;
|
||||||
|
libraryId: number;
|
||||||
|
title: string;
|
||||||
|
authors: Author[];
|
||||||
|
viewerSetting: BookViewerSetting;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BookViewerSetting {
|
||||||
|
pageNumber: number;
|
||||||
|
zoom: number | string;
|
||||||
|
sidebar_visible: boolean;
|
||||||
|
spread: 'off' | 'even' | 'odd';
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PaginatedBooksResponse {
|
||||||
|
content: Book[];
|
||||||
|
totalElements: number;
|
||||||
|
totalPages: number;
|
||||||
|
size: number;
|
||||||
|
number: number;
|
||||||
|
first: boolean;
|
||||||
|
last: boolean;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
export interface Library {
|
||||||
|
id?: number;
|
||||||
|
name: string;
|
||||||
|
paths: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LibraryApiResponse {
|
||||||
|
content: Library[];
|
||||||
|
totalElements: number;
|
||||||
|
totalPages: number;
|
||||||
|
numberOfElements: number;
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { Book, PaginatedBooksResponse } from '../model/book.model';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
export class BookService {
|
||||||
|
private readonly pageSize = 25;
|
||||||
|
private readonly libraryUrl = 'http://localhost:8080/v1/library';
|
||||||
|
private readonly bookUrl = 'http://localhost:8080/v1/book';
|
||||||
|
|
||||||
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
|
getBook(bookId: number): Observable<Book> {
|
||||||
|
return this.http.get<Book>(`${this.bookUrl}/${bookId}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
loadBooks(libraryId: number, page: number): Observable<PaginatedBooksResponse> {
|
||||||
|
return this.http.get<PaginatedBooksResponse>(
|
||||||
|
`${this.libraryUrl}/${libraryId}/book?page=${page}&size=${this.pageSize}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
searchBooks(query: string): Observable<Book[]> {
|
||||||
|
if (query.length < 3) {
|
||||||
|
return new Observable<Book[]>();
|
||||||
|
}
|
||||||
|
return this.http.get<Book[]>(`${this.bookUrl}/search?title=${encodeURIComponent(query)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateViewerSetting(viewerSetting: any, bookId: number): Observable<void> {
|
||||||
|
const url = `${this.bookUrl}/${bookId}/viewer-setting`;
|
||||||
|
return this.http.put<void>(url, viewerSetting);
|
||||||
|
}
|
||||||
|
|
||||||
|
getBookDataUrl(bookId: number): string {
|
||||||
|
return `${this.bookUrl}/${bookId}/data`;
|
||||||
|
}
|
||||||
|
|
||||||
|
getBookCoverUrl(bookId: number): string {
|
||||||
|
return `${this.bookUrl}/${bookId}/cover`;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { Injectable, signal } from '@angular/core';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { catchError, map, tap } from 'rxjs/operators';
|
||||||
|
import { Observable, of } from 'rxjs';
|
||||||
|
import { Library, LibraryApiResponse } from '../model/library.model';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class LibraryService {
|
||||||
|
private libraryUrl: string = 'http://localhost:8080/v1/library';
|
||||||
|
|
||||||
|
libraries = signal<Library[]>([]);
|
||||||
|
|
||||||
|
constructor(private http: HttpClient) {
|
||||||
|
this.getLibrariesFromAPI();
|
||||||
|
}
|
||||||
|
|
||||||
|
getLibrariesFromAPI(): void {
|
||||||
|
this.http.get<LibraryApiResponse>(this.libraryUrl).pipe(
|
||||||
|
map(response => response.content),
|
||||||
|
catchError(error => {
|
||||||
|
console.error('Error loading libraries:', error);
|
||||||
|
return of([]);
|
||||||
|
})
|
||||||
|
).subscribe(
|
||||||
|
(libraries) => {
|
||||||
|
this.libraries.set(libraries);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
createLibrary(newLibrary: Library): Observable<Library> {
|
||||||
|
return this.http.post<Library>(this.libraryUrl, newLibrary).pipe(
|
||||||
|
tap((createdLibrary) => {
|
||||||
|
this.libraries.set([...this.libraries(), createdLibrary]);
|
||||||
|
}),
|
||||||
|
catchError(error => {
|
||||||
|
console.error('Error creating library:', error);
|
||||||
|
throw error;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
checkLibraryNameExists(name: string): Observable<any> {
|
||||||
|
return this.http.get<Library>(`${this.libraryUrl}/search?name=${name}`).pipe(
|
||||||
|
catchError(error => {
|
||||||
|
console.error('Error checking library name:', error);
|
||||||
|
return of(null);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import {Observable} from 'rxjs';
|
||||||
|
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class UtilityService {
|
||||||
|
|
||||||
|
private pathUrl = 'http://localhost:8080/v1/path';
|
||||||
|
|
||||||
|
constructor(private http: HttpClient) { }
|
||||||
|
|
||||||
|
getFolders(path: string): Observable<string[]> {
|
||||||
|
const params = new HttpParams().set('path', path);
|
||||||
|
return this.http.get<string[]>(this.pathUrl, { params });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export interface MenuChangeEvent {
|
||||||
|
key: string;
|
||||||
|
routeEvent?: boolean;
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<div class="layout-footer">
|
||||||
|
<img src="assets/layout/images/{{layoutService.config().colorScheme === 'light' ? 'logo-dark' : 'logo-white'}}.svg" alt="Logo" height="20" class="mr-2"/>
|
||||||
|
by
|
||||||
|
<span class="font-medium ml-2">PrimeNG</span>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
import { LayoutService } from "./service/app.layout.service";
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-footer',
|
||||||
|
templateUrl: './app.footer.component.html'
|
||||||
|
})
|
||||||
|
export class AppFooterComponent {
|
||||||
|
constructor(public layoutService: LayoutService) { }
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<div class="layout-wrapper" [ngClass]="containerClass">
|
||||||
|
<app-topbar></app-topbar>
|
||||||
|
<div class="layout-sidebar layout-sidebar-custom">
|
||||||
|
<app-sidebar></app-sidebar>
|
||||||
|
</div>
|
||||||
|
<div class="layout-main-container layout-main-container-custom">
|
||||||
|
<div class="layout-main" >
|
||||||
|
<router-outlet ></router-outlet>
|
||||||
|
</div>
|
||||||
|
<app-footer></app-footer>
|
||||||
|
</div>
|
||||||
|
<app-config></app-config>
|
||||||
|
<div class="layout-mask"></div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
import { Component, OnDestroy, Renderer2, ViewChild } from '@angular/core';
|
||||||
|
import {NavigationEnd, Router, RouterOutlet} from '@angular/router';
|
||||||
|
import { filter, Subscription } from 'rxjs';
|
||||||
|
import { LayoutService } from "./service/app.layout.service";
|
||||||
|
import { AppSidebarComponent } from "./app.sidebar.component";
|
||||||
|
import { AppTopBarComponent } from './app.topbar.component';
|
||||||
|
import {AppFooterComponent} from "./app.footer.component";
|
||||||
|
import {AppConfigComponent} from "./config/app.config.component";
|
||||||
|
import {NgClass} from '@angular/common';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-layout',
|
||||||
|
imports: [
|
||||||
|
RouterOutlet,
|
||||||
|
AppFooterComponent,
|
||||||
|
AppConfigComponent,
|
||||||
|
AppSidebarComponent,
|
||||||
|
AppTopBarComponent,
|
||||||
|
NgClass
|
||||||
|
],
|
||||||
|
templateUrl: './app.layout.component.html'
|
||||||
|
})
|
||||||
|
export class AppLayoutComponent implements OnDestroy {
|
||||||
|
|
||||||
|
overlayMenuOpenSubscription: Subscription;
|
||||||
|
|
||||||
|
menuOutsideClickListener: any;
|
||||||
|
|
||||||
|
profileMenuOutsideClickListener: any;
|
||||||
|
|
||||||
|
@ViewChild(AppSidebarComponent) appSidebar!: AppSidebarComponent;
|
||||||
|
|
||||||
|
@ViewChild(AppTopBarComponent) appTopbar!: AppTopBarComponent;
|
||||||
|
|
||||||
|
constructor(public layoutService: LayoutService, public renderer: Renderer2, public router: Router) {
|
||||||
|
this.overlayMenuOpenSubscription = this.layoutService.overlayOpen$.subscribe(() => {
|
||||||
|
if (!this.menuOutsideClickListener) {
|
||||||
|
this.menuOutsideClickListener = this.renderer.listen('document', 'click', event => {
|
||||||
|
const isOutsideClicked = !(this.appSidebar.el.nativeElement.isSameNode(event.target) || this.appSidebar.el.nativeElement.contains(event.target)
|
||||||
|
|| this.appTopbar.menuButton.nativeElement.isSameNode(event.target) || this.appTopbar.menuButton.nativeElement.contains(event.target));
|
||||||
|
|
||||||
|
if (isOutsideClicked) {
|
||||||
|
this.hideMenu();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.profileMenuOutsideClickListener) {
|
||||||
|
this.profileMenuOutsideClickListener = this.renderer.listen('document', 'click', event => {
|
||||||
|
const isOutsideClicked = !(this.appTopbar.menu.nativeElement.isSameNode(event.target) || this.appTopbar.menu.nativeElement.contains(event.target)
|
||||||
|
|| this.appTopbar.topbarMenuButton.nativeElement.isSameNode(event.target) || this.appTopbar.topbarMenuButton.nativeElement.contains(event.target));
|
||||||
|
|
||||||
|
if (isOutsideClicked) {
|
||||||
|
this.hideProfileMenu();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.layoutService.state.staticMenuMobileActive) {
|
||||||
|
this.blockBodyScroll();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.router.events.pipe(filter(event => event instanceof NavigationEnd))
|
||||||
|
.subscribe(() => {
|
||||||
|
this.hideMenu();
|
||||||
|
this.hideProfileMenu();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
hideMenu() {
|
||||||
|
this.layoutService.state.overlayMenuActive = false;
|
||||||
|
this.layoutService.state.staticMenuMobileActive = false;
|
||||||
|
this.layoutService.state.menuHoverActive = false;
|
||||||
|
if (this.menuOutsideClickListener) {
|
||||||
|
this.menuOutsideClickListener();
|
||||||
|
this.menuOutsideClickListener = null;
|
||||||
|
}
|
||||||
|
this.unblockBodyScroll();
|
||||||
|
}
|
||||||
|
|
||||||
|
hideProfileMenu() {
|
||||||
|
this.layoutService.state.profileSidebarVisible = false;
|
||||||
|
if (this.profileMenuOutsideClickListener) {
|
||||||
|
this.profileMenuOutsideClickListener();
|
||||||
|
this.profileMenuOutsideClickListener = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
blockBodyScroll(): void {
|
||||||
|
if (document.body.classList) {
|
||||||
|
document.body.classList.add('blocked-scroll');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.body.className += ' blocked-scroll';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unblockBodyScroll(): void {
|
||||||
|
if (document.body.classList) {
|
||||||
|
document.body.classList.remove('blocked-scroll');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.body.className = document.body.className.replace(new RegExp('(^|\\b)' +
|
||||||
|
'blocked-scroll'.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get containerClass() {
|
||||||
|
return {
|
||||||
|
'layout-theme-light': this.layoutService.config().colorScheme === 'light',
|
||||||
|
'layout-theme-dark': this.layoutService.config().colorScheme === 'dark',
|
||||||
|
'layout-overlay': this.layoutService.config().menuMode === 'overlay',
|
||||||
|
'layout-static': this.layoutService.config().menuMode === 'static',
|
||||||
|
'layout-static-inactive': this.layoutService.state.staticMenuDesktopInactive && this.layoutService.config().menuMode === 'static',
|
||||||
|
'layout-overlay-active': this.layoutService.state.overlayMenuActive,
|
||||||
|
'layout-mobile-active': this.layoutService.state.staticMenuMobileActive,
|
||||||
|
'p-input-filled': this.layoutService.config().inputStyle === 'filled',
|
||||||
|
'p-ripple-disabled': !this.layoutService.config().ripple
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
if (this.overlayMenuOpenSubscription) {
|
||||||
|
this.overlayMenuOpenSubscription.unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.menuOutsideClickListener) {
|
||||||
|
this.menuOutsideClickListener();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
|
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
import { InputTextModule } from 'primeng/inputtext';
|
||||||
|
import { SidebarModule } from 'primeng/sidebar';
|
||||||
|
import { BadgeModule } from 'primeng/badge';
|
||||||
|
import { RadioButtonModule } from 'primeng/radiobutton';
|
||||||
|
import { InputSwitchModule } from 'primeng/inputswitch';
|
||||||
|
import { RippleModule } from 'primeng/ripple';
|
||||||
|
import { AppMenuComponent } from './app.menu.component';
|
||||||
|
import { AppMenuitemComponent } from './app.menuitem.component';
|
||||||
|
import { RouterModule } from '@angular/router';
|
||||||
|
import { AppTopBarComponent } from './app.topbar.component';
|
||||||
|
import { AppFooterComponent } from './app.footer.component';
|
||||||
|
import { AppConfigModule } from './config/config.module';
|
||||||
|
import { AppSidebarComponent } from "./app.sidebar.component";
|
||||||
|
import { AppLayoutComponent } from "./app.layout.component";
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
declarations: [
|
||||||
|
|
||||||
|
],
|
||||||
|
imports: [
|
||||||
|
BrowserModule,
|
||||||
|
FormsModule,
|
||||||
|
HttpClientModule,
|
||||||
|
BrowserAnimationsModule,
|
||||||
|
InputTextModule,
|
||||||
|
SidebarModule,
|
||||||
|
BadgeModule,
|
||||||
|
RadioButtonModule,
|
||||||
|
InputSwitchModule,
|
||||||
|
RippleModule,
|
||||||
|
RouterModule,
|
||||||
|
AppConfigModule,
|
||||||
|
AppMenuitemComponent,
|
||||||
|
AppTopBarComponent,
|
||||||
|
AppFooterComponent,
|
||||||
|
AppMenuComponent,
|
||||||
|
AppSidebarComponent,
|
||||||
|
AppLayoutComponent
|
||||||
|
],
|
||||||
|
exports: [AppLayoutComponent]
|
||||||
|
})
|
||||||
|
export class AppLayoutModule { }
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<ul class="layout-menu">
|
||||||
|
<ng-container *ngFor="let item of home; let i = index;">
|
||||||
|
<li app-menuitem *ngIf="!item.separator" [item]="item" [index]="i" [root]="true"></li>
|
||||||
|
<li *ngIf="item.separator" class="menu-separator"></li>
|
||||||
|
</ng-container>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<ul class="layout-menu">
|
||||||
|
<ng-container *ngFor="let item of libraryMenu(); let i = index;">
|
||||||
|
<li app-menuitem *ngIf="!item.separator" [item]="item" [index]="i" [root]="true"></li>
|
||||||
|
<li *ngIf="item.separator" class="menu-separator"></li>
|
||||||
|
</ng-container>
|
||||||
|
</ul>
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import {Component, computed, OnInit} from '@angular/core';
|
||||||
|
import {AppMenuitemComponent} from './app.menuitem.component';
|
||||||
|
import {NgForOf, NgIf} from '@angular/common';
|
||||||
|
import {MenuModule} from 'primeng/menu';
|
||||||
|
import {LibraryService} from '../book/service/library.service';
|
||||||
|
import {Library} from '../book/model/library.model';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-menu',
|
||||||
|
imports: [AppMenuitemComponent, NgIf, NgForOf, MenuModule],
|
||||||
|
templateUrl: './app.menu.component.html',
|
||||||
|
})
|
||||||
|
export class AppMenuComponent implements OnInit {
|
||||||
|
home: any[] = [];
|
||||||
|
libraries: any;
|
||||||
|
|
||||||
|
libraryMenu = computed(() => [
|
||||||
|
{
|
||||||
|
label: 'Library',
|
||||||
|
separator: false,
|
||||||
|
items: this.libraries().map((lib: Library) => ({
|
||||||
|
label: lib.name,
|
||||||
|
icon: 'pi pi-fw pi-home',
|
||||||
|
routerLink: [`/library/${lib.id}/books`]
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
constructor(private libraryService: LibraryService) {
|
||||||
|
this.libraries = this.libraryService.libraries;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.populateHome();
|
||||||
|
}
|
||||||
|
|
||||||
|
private populateHome() {
|
||||||
|
this.home = [
|
||||||
|
{
|
||||||
|
label: 'Home',
|
||||||
|
items: [
|
||||||
|
{label: 'Dashboard', icon: 'pi pi-fw pi-home', routerLink: ['/']},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Subject } from 'rxjs';
|
||||||
|
import { MenuChangeEvent } from './api/menuchangeevent';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class MenuService {
|
||||||
|
|
||||||
|
private menuSource = new Subject<MenuChangeEvent>();
|
||||||
|
private resetSource = new Subject();
|
||||||
|
|
||||||
|
menuSource$ = this.menuSource.asObservable();
|
||||||
|
resetSource$ = this.resetSource.asObservable();
|
||||||
|
|
||||||
|
onMenuStateChange(event: MenuChangeEvent) {
|
||||||
|
this.menuSource.next(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
reset() {
|
||||||
|
this.resetSource.next(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
import { ChangeDetectorRef, Component, Host, HostBinding, Input, OnDestroy, OnInit } from '@angular/core';
|
||||||
|
import {NavigationEnd, Router, RouterLink, RouterLinkActive} from '@angular/router';
|
||||||
|
import { animate, state, style, transition, trigger } from '@angular/animations';
|
||||||
|
import { Subscription } from 'rxjs';
|
||||||
|
import { filter } from 'rxjs/operators';
|
||||||
|
import { MenuService } from './app.menu.service';
|
||||||
|
import { LayoutService } from './service/app.layout.service';
|
||||||
|
import {NgClass, NgForOf, NgIf} from '@angular/common';
|
||||||
|
import {Ripple} from 'primeng/ripple';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
// eslint-disable-next-line @angular-eslint/component-selector
|
||||||
|
selector: '[app-menuitem]',
|
||||||
|
template: `
|
||||||
|
<ng-container>
|
||||||
|
<div *ngIf="root && item.visible !== false" class="layout-menuitem-root-text">{{ item.label }}</div>
|
||||||
|
<a *ngIf="(!item.routerLink || item.items) && item.visible !== false" [attr.href]="item.url"
|
||||||
|
(click)="itemClick($event)"
|
||||||
|
[ngClass]="item.class" [attr.target]="item.target" tabindex="0" pRipple>
|
||||||
|
<i [ngClass]="item.icon" class="layout-menuitem-icon"></i>
|
||||||
|
<span class="layout-menuitem-text">{{ item.label }}</span>
|
||||||
|
<i class="pi pi-fw pi-angle-down layout-submenu-toggler" *ngIf="item.items"></i>
|
||||||
|
</a>
|
||||||
|
<a *ngIf="(item.routerLink && !item.items) && item.visible !== false" (click)="itemClick($event)"
|
||||||
|
[ngClass]="item.class"
|
||||||
|
[routerLink]="item.routerLink" routerLinkActive="active-route"
|
||||||
|
[routerLinkActiveOptions]="item.routerLinkActiveOptions||{ paths: 'exact', queryParams: 'ignored', matrixParams: 'ignored', fragment: 'ignored' }"
|
||||||
|
[fragment]="item.fragment" [queryParamsHandling]="item.queryParamsHandling"
|
||||||
|
[preserveFragment]="item.preserveFragment"
|
||||||
|
[skipLocationChange]="item.skipLocationChange" [replaceUrl]="item.replaceUrl" [state]="item.state"
|
||||||
|
[queryParams]="item.queryParams"
|
||||||
|
[attr.target]="item.target" tabindex="0" pRipple>
|
||||||
|
<i [ngClass]="item.icon" class="layout-menuitem-icon"></i>
|
||||||
|
<span class="layout-menuitem-text">{{ item.label }}</span>
|
||||||
|
<i class="pi pi-fw pi-angle-down layout-submenu-toggler" *ngIf="item.items"></i>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<ul *ngIf="item.items && item.visible !== false" [@children]="submenuAnimation">
|
||||||
|
<ng-template ngFor let-child let-i="index" [ngForOf]="item.items">
|
||||||
|
<li app-menuitem [item]="child" [index]="i" [parentKey]="key" [class]="child.badgeClass"></li>
|
||||||
|
</ng-template>
|
||||||
|
</ul>
|
||||||
|
</ng-container>
|
||||||
|
`,
|
||||||
|
imports: [
|
||||||
|
RouterLink,
|
||||||
|
RouterLinkActive,
|
||||||
|
NgClass,
|
||||||
|
NgForOf,
|
||||||
|
Ripple,
|
||||||
|
NgIf
|
||||||
|
],
|
||||||
|
animations: [
|
||||||
|
trigger('children', [
|
||||||
|
state('collapsed', style({
|
||||||
|
height: '0'
|
||||||
|
})),
|
||||||
|
state('expanded', style({
|
||||||
|
height: '*'
|
||||||
|
})),
|
||||||
|
transition('collapsed <=> expanded', animate('400ms cubic-bezier(0.86, 0, 0.07, 1)'))
|
||||||
|
])
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class AppMenuitemComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
|
@Input() item: any;
|
||||||
|
|
||||||
|
@Input() index!: number;
|
||||||
|
|
||||||
|
@Input() @HostBinding('class.layout-root-menuitem') root!: boolean;
|
||||||
|
|
||||||
|
@Input() parentKey!: string;
|
||||||
|
|
||||||
|
active = false;
|
||||||
|
|
||||||
|
menuSourceSubscription: Subscription;
|
||||||
|
|
||||||
|
menuResetSubscription: Subscription;
|
||||||
|
|
||||||
|
key: string = "";
|
||||||
|
|
||||||
|
constructor(public layoutService: LayoutService, private cd: ChangeDetectorRef, public router: Router, private menuService: MenuService) {
|
||||||
|
this.menuSourceSubscription = this.menuService.menuSource$.subscribe(value => {
|
||||||
|
Promise.resolve(null).then(() => {
|
||||||
|
if (value.routeEvent) {
|
||||||
|
this.active = (value.key === this.key || value.key.startsWith(this.key + '-')) ? true : false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (value.key !== this.key && !value.key.startsWith(this.key + '-')) {
|
||||||
|
this.active = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
this.menuResetSubscription = this.menuService.resetSource$.subscribe(() => {
|
||||||
|
this.active = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.router.events.pipe(filter(event => event instanceof NavigationEnd))
|
||||||
|
.subscribe(params => {
|
||||||
|
if (this.item.routerLink) {
|
||||||
|
this.updateActiveStateFromRoute();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.key = this.parentKey ? this.parentKey + '-' + this.index : String(this.index);
|
||||||
|
|
||||||
|
if (this.item.routerLink) {
|
||||||
|
this.updateActiveStateFromRoute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateActiveStateFromRoute() {
|
||||||
|
let activeRoute = this.router.isActive(this.item.routerLink[0], { paths: 'exact', queryParams: 'ignored', matrixParams: 'ignored', fragment: 'ignored' });
|
||||||
|
|
||||||
|
if (activeRoute) {
|
||||||
|
this.menuService.onMenuStateChange({ key: this.key, routeEvent: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
itemClick(event: Event) {
|
||||||
|
// avoid processing disabled items
|
||||||
|
if (this.item.disabled) {
|
||||||
|
event.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// execute command
|
||||||
|
if (this.item.command) {
|
||||||
|
this.item.command({ originalEvent: event, item: this.item });
|
||||||
|
}
|
||||||
|
|
||||||
|
// toggle active state
|
||||||
|
if (this.item.items) {
|
||||||
|
this.active = !this.active;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.menuService.onMenuStateChange({ key: this.key });
|
||||||
|
}
|
||||||
|
|
||||||
|
get submenuAnimation() {
|
||||||
|
return this.root ? 'expanded' : (this.active ? 'expanded' : 'collapsed');
|
||||||
|
}
|
||||||
|
|
||||||
|
@HostBinding('class.active-menuitem')
|
||||||
|
get activeClass() {
|
||||||
|
return this.active && !this.root;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
if (this.menuSourceSubscription) {
|
||||||
|
this.menuSourceSubscription.unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.menuResetSubscription) {
|
||||||
|
this.menuResetSubscription.unsubscribe();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<app-menu></app-menu>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
.layout-sidebar-custom {
|
||||||
|
width: 250px !important;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { Component, ElementRef } from '@angular/core';
|
||||||
|
import { LayoutService } from "./service/app.layout.service";
|
||||||
|
import {AppMenuComponent} from './app.menu.component';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-sidebar',
|
||||||
|
imports: [
|
||||||
|
AppMenuComponent
|
||||||
|
],
|
||||||
|
templateUrl: './app.sidebar.component.html'
|
||||||
|
})
|
||||||
|
export class AppSidebarComponent {
|
||||||
|
constructor(public layoutService: LayoutService, public el: ElementRef) { }
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<div class="layout-topbar">
|
||||||
|
<a class="layout-topbar-logo" routerLink="">
|
||||||
|
<img src="assets/layout/images/{{layoutService.config().colorScheme === 'light' ? 'logo-dark' : 'logo-white'}}.svg"
|
||||||
|
alt="logo">
|
||||||
|
<span>BookLore</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<button #menubutton class="p-link layout-menu-button layout-topbar-button" (click)="layoutService.onMenuToggle()">
|
||||||
|
<i class="pi pi-bars"></i>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<app-search></app-search>
|
||||||
|
|
||||||
|
<button #topbarmenubutton class="p-link layout-topbar-menu-button layout-topbar-button"
|
||||||
|
(click)="layoutService.showProfileSidebar()">
|
||||||
|
<i class="pi pi-ellipsis-v"></i>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div #topbarmenu class="layout-topbar-menu">
|
||||||
|
<button
|
||||||
|
class="p-link layout-menu-button layout-topbar-button"
|
||||||
|
(click)="openLibraryCreatorDialog()"
|
||||||
|
pTooltip="Create New Library"
|
||||||
|
tooltipPosition="top">
|
||||||
|
<i class="pi pi-plus-circle"></i>
|
||||||
|
</button>
|
||||||
|
<button class="p-link layout-topbar-button">
|
||||||
|
<i class="pi pi-user"></i>
|
||||||
|
<span>Profile</span>
|
||||||
|
</button>
|
||||||
|
<button class="p-link layout-topbar-button" [routerLink]="'/documentation'">
|
||||||
|
<i class="pi pi-cog"></i>
|
||||||
|
<span>Settings</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import {Component, ElementRef, OnDestroy, ViewChild,} from '@angular/core';
|
||||||
|
import {MenuItem} from 'primeng/api';
|
||||||
|
import {LayoutService} from './service/app.layout.service';
|
||||||
|
import {RouterLink} from '@angular/router';
|
||||||
|
import {DialogService as PrimeDialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||||
|
import {LibraryCreatorComponent} from '../book/component/library-creator/library-creator.component';
|
||||||
|
import {TooltipModule} from 'primeng/tooltip';
|
||||||
|
import {FormsModule} from '@angular/forms';
|
||||||
|
import {InputTextModule} from 'primeng/inputtext';
|
||||||
|
import {SearchComponent} from '../book/component/search/search.component';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-topbar',
|
||||||
|
imports: [
|
||||||
|
RouterLink,
|
||||||
|
TooltipModule,
|
||||||
|
FormsModule,
|
||||||
|
InputTextModule,
|
||||||
|
SearchComponent,
|
||||||
|
],
|
||||||
|
templateUrl: './app.topbar.component.html',
|
||||||
|
})
|
||||||
|
export class AppTopBarComponent implements OnDestroy {
|
||||||
|
items!: MenuItem[];
|
||||||
|
ref: DynamicDialogRef | undefined;
|
||||||
|
|
||||||
|
@ViewChild('menubutton') menuButton!: ElementRef;
|
||||||
|
@ViewChild('topbarmenubutton') topbarMenuButton!: ElementRef;
|
||||||
|
@ViewChild('topbarmenu') menu!: ElementRef;
|
||||||
|
|
||||||
|
constructor(public layoutService: LayoutService, public dialogService: PrimeDialogService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
openLibraryCreatorDialog(): void {
|
||||||
|
this.ref = this.dialogService.open(LibraryCreatorComponent, {
|
||||||
|
header: "Create New Library",
|
||||||
|
modal: false,
|
||||||
|
width: '50%',
|
||||||
|
height: '50%',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
if (this.ref) {
|
||||||
|
this.ref.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user