initial commit
This commit is contained in:
+160
@@ -0,0 +1,160 @@
|
||||
# Gradle
|
||||
.gradle
|
||||
**/build/
|
||||
!**/src/**/build/
|
||||
|
||||
# Ignore Gradle GUI config
|
||||
gradle-app.setting
|
||||
|
||||
# Avoid ignore Gradle wrapper properties
|
||||
!gradle-wrapper.properties
|
||||
|
||||
# Cache of project
|
||||
.gradletasknamecache
|
||||
|
||||
# Eclipse Gradle plugin generated files
|
||||
# Eclipse Core
|
||||
.project
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
|
||||
|
||||
# Kotlin
|
||||
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
# Kotlin Gradle plugin data, see https://kotlinlang.org/docs/whatsnew20.html#new-directory-for-kotlin-data-in-gradle-projects
|
||||
.kotlin/
|
||||
|
||||
|
||||
# Jetbrains
|
||||
# Covers JetBrains IDEs: IntelliJ, GoLand, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# AWS User-specific
|
||||
.idea/**/aws.xml
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# SonarLint plugin
|
||||
.idea/sonarlint/
|
||||
.idea/sonarlint.xml # see https://community.sonarsource.com/t/is-the-file-idea-idea-idea-sonarlint-xml-intended-to-be-under-source-control/121119
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based HTTP Client
|
||||
.idea/httpRequests
|
||||
http-client.private.env.json
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
# Apifox Helper cache
|
||||
.idea/.cache/.Apifox_Helper
|
||||
.idea/ApifoxUploaderProjectSetting.xml
|
||||
|
||||
# Github Copilot persisted session migrations, see: https://github.com/microsoft/copilot-intellij-feedback/issues/712#issuecomment-3322062215
|
||||
.idea/**/copilot.data.migration.*.xml
|
||||
|
||||
# General
|
||||
.git
|
||||
node_modules
|
||||
dist
|
||||
tmp
|
||||
buildSrc
|
||||
|
||||
# Env files
|
||||
.env
|
||||
.env.local
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
||||
|
||||
# logs
|
||||
logs/
|
||||
*.log
|
||||
|
||||
# Ignore local IDE/run configs
|
||||
.vscode/
|
||||
@@ -0,0 +1,24 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.{kt,kts,java}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
max_line_length = 120
|
||||
|
||||
[*.{yml,yaml,json,json5,xml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
max_line_length = off
|
||||
|
||||
[*.properties]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
@@ -0,0 +1,3 @@
|
||||
/gradlew text eol=lf
|
||||
*.bat text eol=crlf
|
||||
*.jar binary
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
# Gradle
|
||||
.gradle
|
||||
**/build/
|
||||
!**/src/**/build/
|
||||
|
||||
# Ignore Gradle GUI config
|
||||
gradle-app.setting
|
||||
|
||||
# Avoid ignore Gradle wrapper properties
|
||||
!gradle-wrapper.properties
|
||||
|
||||
# Cache of project
|
||||
.gradletasknamecache
|
||||
|
||||
# Eclipse Gradle plugin generated files
|
||||
# Eclipse Core
|
||||
.project
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
|
||||
|
||||
# Kotlin
|
||||
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
# Kotlin Gradle plugin data, see https://kotlinlang.org/docs/whatsnew20.html#new-directory-for-kotlin-data-in-gradle-projects
|
||||
.kotlin/
|
||||
|
||||
|
||||
# Jetbrains
|
||||
# Covers JetBrains IDEs: IntelliJ, GoLand, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# AWS User-specific
|
||||
.idea/**/aws.xml
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# SonarLint plugin
|
||||
.idea/sonarlint/
|
||||
.idea/sonarlint.xml # see https://community.sonarsource.com/t/is-the-file-idea-idea-idea-sonarlint-xml-intended-to-be-under-source-control/121119
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based HTTP Client
|
||||
.idea/httpRequests
|
||||
http-client.private.env.json
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
# Apifox Helper cache
|
||||
.idea/.cache/.Apifox_Helper
|
||||
.idea/ApifoxUploaderProjectSetting.xml
|
||||
|
||||
# Github Copilot persisted session migrations, see: https://github.com/microsoft/copilot-intellij-feedback/issues/712#issuecomment-3322062215
|
||||
.idea/**/copilot.data.migration.*.xml
|
||||
|
||||
# General
|
||||
.DS_Store
|
||||
__MACOSX/
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
Icon[
|
||||
]
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
@@ -0,0 +1,71 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
# Stage 1: Build
|
||||
FROM docker.io/gradle:9-jdk21-alpine AS builder
|
||||
|
||||
ARG GRADLE_USER_HOME=/home/gradle/.gradle
|
||||
ARG APP_HOME=/workspace
|
||||
ARG JAR_NAME=app.jar
|
||||
|
||||
WORKDIR ${APP_HOME}
|
||||
|
||||
ENV GRADLE_USER_HOME=${GRADLE_USER_HOME} \
|
||||
ORG_GRADLE_PROJECT_buildCacheEnabled=true
|
||||
|
||||
COPY gradle gradle
|
||||
COPY gradlew gradlew
|
||||
COPY settings.gradle.kts build.gradle.kts gradle.properties ./
|
||||
|
||||
RUN gradle wrapper
|
||||
|
||||
RUN --mount=type=cache,target=${GRADLE_USER_HOME} \
|
||||
./gradlew --no-daemon --no-parallel dependencies || true
|
||||
|
||||
COPY src src
|
||||
|
||||
RUN --mount=type=cache,target=${GRADLE_USER_HOME} \
|
||||
./gradlew --no-daemon build \
|
||||
-x test \
|
||||
-x detekt \
|
||||
-x ktlintCheck \
|
||||
-x ktlintKotlinScriptCheck \
|
||||
-x ktlintMainSourceSetCheck \
|
||||
-x ktlintTestSourceSetCheck
|
||||
|
||||
RUN mkdir -p ${APP_HOME}/dist \
|
||||
&& cp ${APP_HOME}/build/libs/*.jar ${APP_HOME}/dist/${JAR_NAME} \
|
||||
&& ls -la ${APP_HOME}/dist
|
||||
|
||||
|
||||
# Stage 2: Runtime
|
||||
FROM docker.io/eclipse-temurin:21-jre-jammy AS runtime
|
||||
|
||||
LABEL org.opencontainers.image.title="MovieNight" \
|
||||
org.opencontainers.image.description="MovieNight application" \
|
||||
org.opencontainers.image.authors="MovieNight team"
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN groupadd -g 1000 app \
|
||||
&& useradd -u 1000 -g app -s /usr/sbin/nologin -M app
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends ca-certificates curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY --from=builder --chown=app:app /workspace/dist/app.jar /app/app.jar
|
||||
|
||||
USER app
|
||||
|
||||
ENV JAVA_OPTS="-Xms256m -Xmx512m -XX:+UseG1GC" \
|
||||
SERVER_PORT=8080 \
|
||||
PATH="/app:$PATH"
|
||||
|
||||
EXPOSE ${SERVER_PORT}
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=30s --retries=3 \
|
||||
CMD curl -fsS http://127.0.0.1:${SERVER_PORT}/actuator/health || exit 1
|
||||
|
||||
STOPSIGNAL SIGTERM
|
||||
|
||||
ENTRYPOINT ["sh", "-c", "exec java ${JAVA_OPTS} -Dserver.port=${SERVER_PORT} -jar /app/app.jar"]
|
||||
@@ -0,0 +1,232 @@
|
||||
import com.google.protobuf.gradle.id
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.springframework.boot.gradle.tasks.bundling.BootJar
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "2.1.20"
|
||||
kotlin("plugin.spring") version "2.1.20"
|
||||
id("org.springframework.boot") version "3.4.3"
|
||||
id("io.spring.dependency-management") version "1.1.7"
|
||||
id("com.google.protobuf") version "0.9.6"
|
||||
// alias(libs.plugins.ktlint)
|
||||
// alias(libs.plugins.detekt)
|
||||
jacoco
|
||||
}
|
||||
|
||||
apply(from = "$rootDir/gradle/docker.gradle.kts")
|
||||
|
||||
group = "com.project"
|
||||
version = "0.0.1"
|
||||
description = "MovieNight project"
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_21
|
||||
targetCompatibility = JavaVersion.VERSION_21
|
||||
}
|
||||
|
||||
configurations {
|
||||
compileOnly {
|
||||
extendsFrom(configurations.annotationProcessor.get())
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
extra["sentryVersion"] = "8.27.0"
|
||||
extra["springGrpcVersion"] = "1.0.1"
|
||||
|
||||
dependencies {
|
||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||
implementation("org.springframework.boot:spring-boot-h2console")
|
||||
implementation("org.springframework.boot:spring-boot-micrometer-tracing-brave")
|
||||
implementation("org.springframework.boot:spring-boot-starter-actuator")
|
||||
implementation("org.springframework.boot:spring-boot-starter-cache")
|
||||
implementation("org.springframework.boot:spring-boot-starter-data-jdbc")
|
||||
implementation("org.springframework.boot:spring-boot-starter-flyway")
|
||||
implementation("org.springframework.boot:spring-boot-starter-security")
|
||||
implementation("org.springframework.boot:spring-boot-starter-validation")
|
||||
implementation("io.grpc:grpc-services")
|
||||
implementation("io.micrometer:micrometer-tracing-bridge-brave")
|
||||
implementation("io.sentry:sentry-spring-boot-4-starter")
|
||||
implementation("net.ttddyy.observation:datasource-micrometer-spring-boot:2.0.1")
|
||||
implementation("org.flywaydb:flyway-database-postgresql")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||
implementation("org.springframework.grpc:spring-grpc-spring-boot-starter")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
|
||||
implementation(libs.emailverifier.kt)
|
||||
|
||||
compileOnly("org.projectlombok:lombok")
|
||||
developmentOnly("org.springframework.boot:spring-boot-devtools")
|
||||
runtimeOnly("com.h2database:h2")
|
||||
runtimeOnly("io.micrometer:micrometer-registry-prometheus")
|
||||
runtimeOnly("org.postgresql:postgresql")
|
||||
annotationProcessor("org.projectlombok:lombok")
|
||||
|
||||
testImplementation("org.springframework.boot:spring-boot-micrometer-tracing-test")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-actuator-test")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-cache-test")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-data-jdbc-test")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-flyway-test")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-security-test")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-validation-test")
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
|
||||
testImplementation("org.springframework.grpc:spring-grpc-test")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
compilerOptions {
|
||||
freeCompilerArgs.set(
|
||||
listOf(
|
||||
"-Xjsr305=strict",
|
||||
"-Xjvm-default=all",
|
||||
"-opt-in=kotlin.RequiresOptIn",
|
||||
"-opt-in=kotlin.ExperimentalStdlibApi",
|
||||
),
|
||||
)
|
||||
jvmTarget.set(JvmTarget.JVM_21)
|
||||
allWarningsAsErrors.set(false)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
sourceCompatibility = "21"
|
||||
targetCompatibility = "21"
|
||||
options.encoding = "UTF-8"
|
||||
options.isIncremental = true
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom("io.sentry:sentry-bom:${property("sentryVersion")}")
|
||||
mavenBom("org.springframework.grpc:spring-grpc-dependencies:${property("springGrpcVersion")}")
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
freeCompilerArgs.addAll("-Xjsr305=strict", "-Xannotation-default-target=param-property")
|
||||
}
|
||||
}
|
||||
|
||||
protobuf {
|
||||
protoc {
|
||||
artifact = "com.google.protobuf:protoc:3.25.1"
|
||||
}
|
||||
plugins {
|
||||
id("grpc") {
|
||||
artifact = "io.grpc:protoc-gen-grpc-java:1.60.0"
|
||||
}
|
||||
}
|
||||
generateProtoTasks {
|
||||
all().forEach {
|
||||
it.plugins {
|
||||
id("grpc") {
|
||||
option("@generated=omit")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
events("passed", "skipped", "failed")
|
||||
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
|
||||
showStandardStreams = false
|
||||
}
|
||||
maxParallelForks = maxOf(1, Runtime.getRuntime().availableProcessors() / 2)
|
||||
minHeapSize = "512m"
|
||||
maxHeapSize = "2048m"
|
||||
systemProperty("spring.profiles.active", "test")
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
filesMatching("**/application.y{a,}ml") {
|
||||
filter { line ->
|
||||
line.replace("\${project.version}", project.version.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named<BootJar>("bootJar") {
|
||||
archiveFileName.set("${project.name}-${project.version}.jar")
|
||||
layered {
|
||||
enabled.set(true)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named<Jar>("jar") {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
ktlint {
|
||||
version.set(libs.versions.ktlint.get())
|
||||
debug.set(false)
|
||||
verbose.set(true)
|
||||
android.set(false)
|
||||
outputToConsole.set(true)
|
||||
ignoreFailures.set(false)
|
||||
enableExperimentalRules.set(true)
|
||||
filter {
|
||||
exclude("**/build/**")
|
||||
exclude("**/generated/**")
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
detekt {
|
||||
buildUponDefaultConfig = true
|
||||
allRules = false
|
||||
config.setFrom("$projectDir/config/detekt/detekt.yaml")
|
||||
baseline = file("$projectDir/config/detekt/baseline.xml")
|
||||
}
|
||||
*/
|
||||
|
||||
jacoco {
|
||||
toolVersion = "0.8.11"
|
||||
}
|
||||
|
||||
tasks.jacocoTestReport {
|
||||
dependsOn(tasks.test)
|
||||
reports {
|
||||
xml.required.set(true)
|
||||
html.required.set(true)
|
||||
csv.required.set(false)
|
||||
}
|
||||
finalizedBy(tasks.jacocoTestCoverageVerification)
|
||||
}
|
||||
|
||||
tasks.jacocoTestCoverageVerification {
|
||||
violationRules {
|
||||
rule {
|
||||
limit {
|
||||
minimum = "0.60".toBigDecimal()
|
||||
}
|
||||
}
|
||||
rule {
|
||||
element = "CLASS"
|
||||
excludes =
|
||||
listOf(
|
||||
"*.config.*",
|
||||
"*.dto.*",
|
||||
"*.entity.*",
|
||||
)
|
||||
limit {
|
||||
counter = "LINE"
|
||||
value = "COVEREDRATIO"
|
||||
minimum = "0.60".toBigDecimal()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.check {
|
||||
dependsOn(tasks.ktlintCheck)
|
||||
// dependsOn(tasks.detekt)
|
||||
dependsOn(tasks.jacocoTestReport)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<baseline>
|
||||
<!-- This file is generated by detekt and should be committed to version control -->
|
||||
<!-- It contains the current code smell baseline for your project -->
|
||||
</baseline>
|
||||
@@ -0,0 +1,9 @@
|
||||
# yaml-language-server: $schema=https://json.schemastore.org/detekt-1.22.0.json
|
||||
|
||||
comments:
|
||||
UndocumentedPublicClass:
|
||||
active: false
|
||||
UndocumentedPublicFunction:
|
||||
active: false
|
||||
UndocumentedPublicProperty:
|
||||
active: false
|
||||
@@ -0,0 +1,12 @@
|
||||
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
||||
org.gradle.parallel=true
|
||||
org.gradle.caching=true
|
||||
org.gradle.daemon=true
|
||||
|
||||
kotlin.code.style=official
|
||||
kotlin.incremental=true
|
||||
kotlin.incremental.js=true
|
||||
kotlin.incremental.multiplatform=true
|
||||
|
||||
org.gradle.configuration-cache=true
|
||||
org.gradle.unsafe.configuration-cache-problems=warn
|
||||
@@ -0,0 +1,31 @@
|
||||
import org.gradle.api.tasks.Exec
|
||||
|
||||
/**
|
||||
* Usage:
|
||||
* - ./gradlew dockerBuild
|
||||
* - ./gradlew dockerPush
|
||||
*/
|
||||
|
||||
val dockerImageName: String = (project.findProperty("dockerImageName") as String?) ?: run {
|
||||
val group = project.group?.toString()?.takeIf { it.isNotBlank() }
|
||||
val name = project.name.lowercase()
|
||||
val version = project.version?.toString()?.takeIf { it.isNotBlank() && it != "unspecified" } ?: "latest"
|
||||
if (group != null) {
|
||||
"${group}/${name}:${version}"
|
||||
} else {
|
||||
"${name}:${version}"
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register<Exec>("dockerBuild") {
|
||||
group = "docker"
|
||||
description = "Build Docker image using Containerfile"
|
||||
commandLine("docker", "build", "-f", "Containerfile", "-t", dockerImageName, ".")
|
||||
}
|
||||
|
||||
tasks.register<Exec>("dockerPush") {
|
||||
group = "docker"
|
||||
description = "Push Docker image to registry (requires login)"
|
||||
onlyIf { System.getenv("CI") != null || project.hasProperty("pushDocker") }
|
||||
commandLine("docker", "push", dockerImageName)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
[versions]
|
||||
ktlint = "1.8.0"
|
||||
detekt = "1.23.8"
|
||||
emailverifier = "1.0.0"
|
||||
|
||||
[libraries]
|
||||
emailverifier-kt = { module = "io.github.mbalatsko:emailverifier-kt", version.ref = "emailverifier" }
|
||||
|
||||
[plugins]
|
||||
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "12.0.3" }
|
||||
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -0,0 +1,248 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015 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\n' "$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
|
||||
|
||||
|
||||
|
||||
# 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" )
|
||||
|
||||
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, 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" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# 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
+93
@@ -0,0 +1,93 @@
|
||||
@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
|
||||
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
: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,18 @@
|
||||
rootProject.name = "movienight"
|
||||
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"
|
||||
}
|
||||
|
||||
buildCache {
|
||||
local {
|
||||
isEnabled = true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.project.movienight
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
|
||||
import org.springframework.boot.runApplication
|
||||
|
||||
@SpringBootApplication
|
||||
@ConfigurationPropertiesScan("com.project.movienight.config")
|
||||
class MovieNightApplication
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
runApplication<MovieNightApplication>(*args)
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.project.movienight
|
||||
|
||||
import com.project.movienight.application.ports.input.CreateFilmCommand
|
||||
import com.project.movienight.application.ports.input.CreateUserCommand
|
||||
import com.project.movienight.application.ports.input.EditFilmCommand
|
||||
import com.project.movienight.application.ports.input.EditUserCommand
|
||||
import com.project.movienight.application.services.FilmService
|
||||
import com.project.movienight.application.services.UserService
|
||||
import com.project.movienight.config.FilmServiceProperties
|
||||
import com.project.movienight.config.UserServiceProperties
|
||||
import org.springframework.boot.CommandLineRunner
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Component
|
||||
class MovieNightService(
|
||||
private val userService: UserService,
|
||||
private val userConfig: UserServiceProperties,
|
||||
private val filmService: FilmService,
|
||||
private val filmConfig: FilmServiceProperties,
|
||||
) : CommandLineRunner {
|
||||
fun performActions() {
|
||||
println("Заблокированные имена пользователей: ${userConfig.blockedNames}")
|
||||
println("Заблокированные паттерны в описании фильмов: ${filmConfig.blockedPatterns}")
|
||||
|
||||
println("Создание пользователей...")
|
||||
|
||||
var userAboba = userService.create(CreateUserCommand(name = "абоба", email = "aboba228@mail.com"))
|
||||
println(userAboba)
|
||||
|
||||
val userAlice = userService.create(CreateUserCommand(name = "алиса", email = "alice@mail.com"))
|
||||
println(userAlice)
|
||||
|
||||
val userBob = userService.create(CreateUserCommand(name = "боб", email = "bob@mail.com"))
|
||||
println(userBob)
|
||||
|
||||
println("Создание фильмов...")
|
||||
|
||||
var filmSpiderMan =
|
||||
filmService.create(
|
||||
CreateFilmCommand(
|
||||
"Spider-Man: Beyond the Spider-Verse",
|
||||
"Spider-Man: Beyond the Spider-Verse is an upcoming American animated superhero film based on Marvel Comics featuring the character Miles Morales / Spider-Man.",
|
||||
),
|
||||
)
|
||||
println(filmSpiderMan)
|
||||
|
||||
val filmStarWars =
|
||||
filmService.create(
|
||||
CreateFilmCommand(
|
||||
"Star Wars: Episode III – Revenge of the Sith",
|
||||
"is a 2005 American epic space opera film written and directed by George Lucas. The sequel to Attack of the Clones (2002), it is the sixth film in the Star Wars film series.",
|
||||
),
|
||||
)
|
||||
println(filmStarWars)
|
||||
|
||||
println("Редактирование фильма ${filmSpiderMan.title}")
|
||||
filmSpiderMan = filmService.edit(filmSpiderMan.id, EditFilmCommand("Delayed", "-"))
|
||||
println(filmSpiderMan)
|
||||
|
||||
println("Редактирование пользователя ${userAboba.name}")
|
||||
userAboba = userService.edit(userAboba.id, EditUserCommand("абеме"))
|
||||
println(userAboba)
|
||||
|
||||
println("Создание пользователя с запрещённым именем")
|
||||
try {
|
||||
userService.create(CreateUserCommand(name = "admin", email = "admin@mail.com"))
|
||||
} catch (e: IllegalArgumentException) {
|
||||
println("error: ${e.message}")
|
||||
}
|
||||
|
||||
println("Создание фильмов с запрещённым паттернами")
|
||||
try {
|
||||
filmService.create(CreateFilmCommand("Python", "Python is the best language"))
|
||||
} catch (e: IllegalArgumentException) {
|
||||
println("error: ${e.message}")
|
||||
}
|
||||
|
||||
println("Удаление пользователей")
|
||||
userService.delete(userAboba.id)
|
||||
userService.delete(userAlice.id)
|
||||
userService.delete(userBob.id)
|
||||
|
||||
println("Удаление фильмов")
|
||||
filmService.delete(filmSpiderMan.id)
|
||||
filmService.delete(filmStarWars.id)
|
||||
}
|
||||
|
||||
override fun run(vararg args: String) {
|
||||
println("Запустился сервис")
|
||||
performActions()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.project.movienight.adapters.id
|
||||
|
||||
import com.project.movienight.application.ports.output.IdGenerator
|
||||
import org.springframework.stereotype.Component
|
||||
import java.util.UUID
|
||||
|
||||
@Component
|
||||
class UuidGenerator : IdGenerator {
|
||||
override fun generateId(): UUID = UUID.randomUUID()
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.project.movienight.adapters.persistence.inmemory
|
||||
|
||||
import com.project.movienight.application.ports.output.FilmLibraryRepositoryPort
|
||||
import com.project.movienight.domain.model.FilmLibrary
|
||||
import org.springframework.stereotype.Repository
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
@Repository
|
||||
class FilmLibraryRepositoryAdapter : FilmLibraryRepositoryPort {
|
||||
private val storage: MutableMap<UUID, FilmLibrary> = ConcurrentHashMap()
|
||||
private val userIdIndex: MutableMap<UUID, UUID> = ConcurrentHashMap()
|
||||
|
||||
override fun save(filmLibrary: FilmLibrary): FilmLibrary {
|
||||
storage[filmLibrary.id] = filmLibrary
|
||||
userIdIndex[filmLibrary.userId] = filmLibrary.id
|
||||
return filmLibrary
|
||||
}
|
||||
|
||||
override fun findById(id: UUID): FilmLibrary? {
|
||||
return storage[id]
|
||||
}
|
||||
|
||||
override fun findAll(): List<FilmLibrary> {
|
||||
return storage.values.toList()
|
||||
}
|
||||
|
||||
override fun deleteById(id: UUID) {
|
||||
val filmLibrary = storage[id]
|
||||
if (filmLibrary != null) {
|
||||
userIdIndex.remove(filmLibrary.userId)
|
||||
}
|
||||
storage.remove(id)
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.project.movienight.adapters.persistence.inmemory
|
||||
|
||||
import com.project.movienight.application.ports.output.FilmRepositoryPort
|
||||
import com.project.movienight.domain.model.Film
|
||||
import org.springframework.stereotype.Repository
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
@Repository
|
||||
class FilmRepositoryAdapter : FilmRepositoryPort {
|
||||
private val films: MutableMap<UUID, Film> = ConcurrentHashMap()
|
||||
|
||||
override fun save(film: Film): Film {
|
||||
films[film.id] = film
|
||||
|
||||
return film
|
||||
}
|
||||
|
||||
override fun findById(id: UUID): Film? = films[id]
|
||||
|
||||
override fun findAll(): List<Film> = films.values.toList()
|
||||
|
||||
override fun deleteById(id: UUID) {
|
||||
films.remove(id)
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.project.movienight.adapters.persistence.inmemory
|
||||
|
||||
import com.project.movienight.application.ports.output.UserRepositoryPort
|
||||
import com.project.movienight.domain.model.User
|
||||
import org.springframework.stereotype.Repository
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
@Repository
|
||||
class UserRepositoryAdapter : UserRepositoryPort {
|
||||
private val users: MutableMap<UUID, User> = ConcurrentHashMap()
|
||||
|
||||
override fun save(user: User): User {
|
||||
users[user.id] = user
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
override fun findById(id: UUID): User? = users[id]
|
||||
|
||||
override fun findAll(): List<User> = users.values.toList()
|
||||
|
||||
override fun deleteById(id: UUID) {
|
||||
users.remove(id)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.project.movienight.application.ports.input
|
||||
|
||||
import com.project.movienight.domain.model.FilmLibrary
|
||||
import java.util.UUID
|
||||
|
||||
// 1. Создание бибилиотеки пользователя
|
||||
|
||||
interface CreateFilmLibraryUseCase {
|
||||
fun create(command: CreateFilmLibraryCommand): FilmLibrary
|
||||
}
|
||||
|
||||
data class CreateFilmLibraryCommand(
|
||||
val userId: UUID,
|
||||
val name: String = "Мои фильмы"
|
||||
)
|
||||
|
||||
|
||||
// 2. Добавление фильма в библиотеку
|
||||
|
||||
interface AddFilmToLibraryUseCase {
|
||||
fun addFilm(command: AddFilmToLibraryCommand): FilmLibrary
|
||||
}
|
||||
|
||||
data class AddFilmToLibraryCommand(
|
||||
val userId: UUID,
|
||||
val filmId: UUID
|
||||
)
|
||||
|
||||
// 3. Удаление фильма из библиотеки
|
||||
|
||||
interface RemoveFilmFromLibraryUseCase {
|
||||
fun removeFilm(command: RemoveFilmFromLibraryCommand): FilmLibrary
|
||||
}
|
||||
|
||||
data class RemoveFilmFromLibraryCommand(
|
||||
val userId: UUID,
|
||||
val filmId: UUID,
|
||||
val libraryId: UUID? = null
|
||||
)
|
||||
|
||||
// 4. Получение библиотеки пользователя
|
||||
|
||||
interface GetFilmLibraryUseCase {
|
||||
fun getLibrary(query: GetFilmLibraryQuery): FilmLibrary
|
||||
}
|
||||
|
||||
data class GetFilmLibraryQuery(
|
||||
val userId: UUID,
|
||||
)
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.project.movienight.application.ports.input
|
||||
|
||||
import com.project.movienight.domain.model.Film
|
||||
import java.util.UUID
|
||||
|
||||
interface CreateFilmUseCase {
|
||||
fun create(command: CreateFilmCommand): Film
|
||||
}
|
||||
|
||||
data class CreateFilmCommand(
|
||||
val title: String,
|
||||
val description: String,
|
||||
)
|
||||
|
||||
interface EditFilmUseCase {
|
||||
fun edit(
|
||||
id: UUID,
|
||||
command: EditFilmCommand,
|
||||
): Film
|
||||
}
|
||||
|
||||
data class EditFilmCommand(
|
||||
val title: String,
|
||||
val description: String,
|
||||
)
|
||||
|
||||
interface DeleteFilmUseCase {
|
||||
fun delete(id: UUID)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.project.movienight.application.ports.input
|
||||
|
||||
import com.project.movienight.domain.model.User
|
||||
import java.util.UUID
|
||||
|
||||
interface CreateUserUseCase {
|
||||
fun create(command: CreateUserCommand): User
|
||||
}
|
||||
|
||||
data class CreateUserCommand(
|
||||
val name: String,
|
||||
val email: String,
|
||||
)
|
||||
|
||||
interface EditUserUseCase {
|
||||
fun edit(
|
||||
id: UUID,
|
||||
command: EditUserCommand,
|
||||
): User
|
||||
}
|
||||
|
||||
data class EditUserCommand(
|
||||
val name: String,
|
||||
)
|
||||
|
||||
interface DeleteUserUseCase {
|
||||
fun delete(id: UUID)
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.project.movienight.application.ports.output
|
||||
|
||||
import com.project.movienight.domain.model.FilmLibrary
|
||||
import java.util.UUID
|
||||
|
||||
interface FilmLibraryRepositoryPort {
|
||||
fun save(filmLibrary: FilmLibrary): FilmLibrary
|
||||
|
||||
fun findById(id: UUID): FilmLibrary?
|
||||
|
||||
fun findAll(): List<FilmLibrary>
|
||||
|
||||
fun deleteById(id: UUID)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.project.movienight.application.ports.output
|
||||
|
||||
import com.project.movienight.domain.model.Film
|
||||
import java.util.UUID
|
||||
|
||||
interface FilmRepositoryPort {
|
||||
fun save(film: Film): Film
|
||||
|
||||
fun findById(id: UUID): Film?
|
||||
|
||||
fun findAll(): List<Film>
|
||||
|
||||
fun deleteById(id: UUID)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.project.movienight.application.ports.output
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
interface IdGenerator {
|
||||
fun generateId(): UUID
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.project.movienight.application.ports.output
|
||||
|
||||
import com.project.movienight.domain.model.User
|
||||
import java.util.UUID
|
||||
|
||||
interface UserRepositoryPort {
|
||||
fun save(user: User): User
|
||||
|
||||
fun findById(id: UUID): User?
|
||||
|
||||
fun findAll(): List<User>
|
||||
|
||||
fun deleteById(id: UUID)
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.project.movienight.application.services
|
||||
|
||||
import com.project.movienight.application.ports.input.CreateFilmCommand
|
||||
import com.project.movienight.application.ports.input.CreateFilmUseCase
|
||||
import com.project.movienight.application.ports.input.DeleteFilmUseCase
|
||||
import com.project.movienight.application.ports.input.EditFilmCommand
|
||||
import com.project.movienight.application.ports.input.EditFilmUseCase
|
||||
import com.project.movienight.application.ports.output.FilmRepositoryPort
|
||||
import com.project.movienight.application.ports.output.IdGenerator
|
||||
import com.project.movienight.config.FilmServiceProperties
|
||||
import com.project.movienight.domain.model.Film
|
||||
import org.springframework.stereotype.Service
|
||||
import java.util.UUID
|
||||
|
||||
@Service
|
||||
class FilmService(
|
||||
private val filmRepository: FilmRepositoryPort,
|
||||
private val idGenerator: IdGenerator,
|
||||
private val filmConfig: FilmServiceProperties,
|
||||
) : CreateFilmUseCase,
|
||||
EditFilmUseCase,
|
||||
DeleteFilmUseCase {
|
||||
override fun create(command: CreateFilmCommand): Film {
|
||||
if (filmConfig.isBlocked(command.title)) {
|
||||
throw IllegalArgumentException("Film with this title is not acceptable")
|
||||
}
|
||||
if (filmConfig.isBlocked(command.description)) {
|
||||
throw IllegalArgumentException("Film with this description is not acceptable")
|
||||
}
|
||||
|
||||
val film =
|
||||
Film(
|
||||
id = idGenerator.generateId(),
|
||||
title = command.title,
|
||||
description = command.description,
|
||||
)
|
||||
return filmRepository.save(film)
|
||||
}
|
||||
|
||||
override fun edit(
|
||||
id: UUID,
|
||||
command: EditFilmCommand,
|
||||
): Film {
|
||||
if (filmConfig.isBlocked(command.title)) {
|
||||
throw IllegalArgumentException("Film with this title is not acceptable")
|
||||
}
|
||||
if (filmConfig.isBlocked(command.description)) {
|
||||
throw IllegalArgumentException("Film with this description is not acceptable")
|
||||
}
|
||||
|
||||
var film = filmRepository.findById(id) ?: throw IllegalArgumentException("Film with id $id not found")
|
||||
|
||||
film = film.copy(title = command.title, description = command.description)
|
||||
|
||||
return filmRepository.save(film)
|
||||
}
|
||||
|
||||
override fun delete(id: UUID) {
|
||||
filmRepository.findById(id) ?: throw IllegalArgumentException("Film with id $id not found")
|
||||
|
||||
filmRepository.deleteById(id)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.project.movienight.application.services
|
||||
|
||||
import com.project.movienight.application.ports.input.CreateUserCommand
|
||||
import com.project.movienight.application.ports.input.CreateUserUseCase
|
||||
import com.project.movienight.application.ports.input.DeleteUserUseCase
|
||||
import com.project.movienight.application.ports.input.EditUserCommand
|
||||
import com.project.movienight.application.ports.input.EditUserUseCase
|
||||
import com.project.movienight.application.ports.output.IdGenerator
|
||||
import com.project.movienight.application.ports.output.UserRepositoryPort
|
||||
import com.project.movienight.config.UserServiceProperties
|
||||
import com.project.movienight.domain.model.User
|
||||
import org.springframework.stereotype.Service
|
||||
import java.util.UUID
|
||||
|
||||
@Service
|
||||
class UserService(
|
||||
private val userRepository: UserRepositoryPort,
|
||||
private val idGenerator: IdGenerator,
|
||||
private val userConfig: UserServiceProperties,
|
||||
) : CreateUserUseCase,
|
||||
EditUserUseCase,
|
||||
DeleteUserUseCase {
|
||||
override fun create(command: CreateUserCommand): User {
|
||||
if (userConfig.isBlocked(command.name)) {
|
||||
throw IllegalArgumentException("User with this name is not acceptable")
|
||||
}
|
||||
|
||||
val user =
|
||||
User(
|
||||
id = idGenerator.generateId(),
|
||||
name = command.name,
|
||||
email = command.email,
|
||||
library = null,
|
||||
)
|
||||
return userRepository.save(user)
|
||||
}
|
||||
|
||||
override fun edit(
|
||||
id: UUID,
|
||||
command: EditUserCommand,
|
||||
): User {
|
||||
if (userConfig.isBlocked(command.name)) {
|
||||
throw IllegalArgumentException("User with this name is not acceptable")
|
||||
}
|
||||
|
||||
var user = userRepository.findById(id) ?: throw IllegalArgumentException("User with id $id not found")
|
||||
|
||||
user = user.copy(name = command.name)
|
||||
|
||||
return userRepository.save(user)
|
||||
}
|
||||
|
||||
override fun delete(id: UUID) {
|
||||
userRepository.findById(id) ?: throw IllegalArgumentException("User with id $id not found")
|
||||
|
||||
userRepository.deleteById(id)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.project.movienight.config
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||
|
||||
@ConfigurationProperties(prefix = "services.film")
|
||||
data class FilmServiceProperties(
|
||||
val blockedPatterns: List<String> = listOf(),
|
||||
) {
|
||||
val normalized: Set<String> =
|
||||
blockedPatterns
|
||||
.map { it.trim().lowercase() }
|
||||
.filter { it.isNotBlank() }
|
||||
.toSet()
|
||||
|
||||
fun isBlocked(fieldValue: String): Boolean {
|
||||
val normalizedFieldValue = fieldValue.lowercase()
|
||||
|
||||
return normalized.any { pattern -> normalizedFieldValue.contains(pattern) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.project.movienight.config
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||
|
||||
@ConfigurationProperties(prefix = "services.user")
|
||||
data class UserServiceProperties(
|
||||
val blockedNames: List<String> = listOf(),
|
||||
) {
|
||||
private val normalized: Set<String> = blockedNames.map { it.trim().lowercase() }.toSet()
|
||||
|
||||
fun isBlocked(name: String): Boolean = name.trim().lowercase() in normalized
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.project.movienight.domain.model
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
data class Film(
|
||||
val id: UUID,
|
||||
val title: String,
|
||||
val description: String,
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.project.movienight.domain.model
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
data class FilmLibrary(
|
||||
val id: UUID,
|
||||
val userId: UUID,
|
||||
)
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.project.movienight.domain.model
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
data class User(
|
||||
val id: UUID,
|
||||
val name: String,
|
||||
val email: String,
|
||||
val library: FilmLibrary?,
|
||||
)
|
||||
@@ -0,0 +1,15 @@
|
||||
spring:
|
||||
application:
|
||||
name: MovieNight
|
||||
|
||||
services:
|
||||
user:
|
||||
blocked-names:
|
||||
- admin
|
||||
- root
|
||||
- system
|
||||
film:
|
||||
blocked-patterns:
|
||||
- censored
|
||||
- epstein
|
||||
- python
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.project.movienight
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
|
||||
@SpringBootTest
|
||||
class MovieNightApplicationTests {
|
||||
@Test
|
||||
fun contextLoads() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user