From 53d785ed098f8c6450921468179243731b5ceea5 Mon Sep 17 00:00:00 2001 From: skettiks Date: Tue, 3 Mar 2026 22:57:43 +0300 Subject: [PATCH 1/6] =?UTF-8?q?=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20ktlint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 4001a7b..5b525c2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -164,19 +164,6 @@ tasks.named("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 { @@ -226,7 +213,6 @@ tasks.jacocoTestCoverageVerification { } tasks.check { - dependsOn(tasks.ktlintCheck) // dependsOn(tasks.detekt) dependsOn(tasks.jacocoTestReport) } -- 2.54.0 From c20553ee354d15e853e031fd006b2a4f172c92cf Mon Sep 17 00:00:00 2001 From: skettiks Date: Tue, 3 Mar 2026 22:58:48 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20ktlint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 4001a7b..5b525c2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -164,19 +164,6 @@ tasks.named("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 { @@ -226,7 +213,6 @@ tasks.jacocoTestCoverageVerification { } tasks.check { - dependsOn(tasks.ktlintCheck) // dependsOn(tasks.detekt) dependsOn(tasks.jacocoTestReport) } -- 2.54.0 From 569b2593f81039e3a565421bc09c8ae304bc4ccf Mon Sep 17 00:00:00 2001 From: Elena Ponomareva Date: Thu, 5 Mar 2026 22:42:58 +0300 Subject: [PATCH 3/6] =?UTF-8?q?SQL=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/init.sql | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 sql/init.sql diff --git a/sql/init.sql b/sql/init.sql new file mode 100644 index 0000000..d153740 --- /dev/null +++ b/sql/init.sql @@ -0,0 +1,59 @@ +-- DROP SCHEMA public; +-- CREATE SCHEMA public AUTHORIZATION pg_database_owner; +-- COMMENT ON SCHEMA public IS 'standard public schema'; + +-- public.genres определение +-- Drop table +DROP TABLE if exists public.genres; +CREATE TABLE public.genres ( + id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, + "name" varchar NULL, + CONSTRAINT genres_unique PRIMARY KEY (id) +); + + +-- public.users определение +-- Drop table +DROP TABLE if exists public.users; +CREATE TABLE public.users ( + id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, + login varchar NOT NULL, + "password" varchar NOT NULL, + CONSTRAINT users_unique UNIQUE (id) +); + + +-- public.films определение +-- Drop table +DROP TABLE if exists public.films; +CREATE TABLE public.films ( + id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, + title varchar NOT NULL, + genreid int4 NOT NULL, + issuedate date NULL, + CONSTRAINT films_unique UNIQUE(id) +); + +DROP TABLE if exists public.fiml_genres; +CREATE TABLE public.film_genres ( + id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, + genreid int4 NOT NULL, + filmid int4 NOT NULL, + CONSTRAINT film_genres_genre_fk FOREIGN KEY (genreid) REFERENCES public.genres(id), + CONSTRAINT film_genres_film_fk FOREIGN KEY (filmid) REFERENCES public.films(id) +); + + +-- Drop table +DROP TABLE if exists public.favorites; +CREATE TABLE public.favorites ( + id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, + userid int4 NULL, + filmid int4 NULL, + "comment" varchar NULL, + isviewed bool NULL, + CONSTRAINT favorites_unique PRIMARY KEY (id), + CONSTRAINT favorites_films_fk FOREIGN KEY (filmid) REFERENCES public.films(id), + CONSTRAINT favorites_users_fk FOREIGN KEY (userid) REFERENCES public.users(id) +); + -- 2.54.0 From 65d0c13c2b62ed732a1d3b45ce5f49ecabc8a778 Mon Sep 17 00:00:00 2001 From: Elena Ponomareva Date: Thu, 5 Mar 2026 23:40:31 +0300 Subject: [PATCH 4/6] =?UTF-8?q?SQL=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82?= =?UTF-8?q?=20(=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=B2=20=D0=B4=D1=80=20=D0=BF=D0=B0=D0=BF=D0=BA=D1=83)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {sql => src/main/resources/db/migration}/init.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {sql => src/main/resources/db/migration}/init.sql (100%) diff --git a/sql/init.sql b/src/main/resources/db/migration/init.sql similarity index 100% rename from sql/init.sql rename to src/main/resources/db/migration/init.sql -- 2.54.0 From aa2e69012479f61e42b2c490e6f2b344d30a2af2 Mon Sep 17 00:00:00 2001 From: skettiks Date: Thu, 5 Mar 2026 23:52:05 +0300 Subject: [PATCH 5/6] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20Film?= =?UTF-8?q?Repository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/init.sql | 59 ---------------- .../persistence/FilmLibraryRepository.kt | 5 ++ .../adapters/persistence/FilmRepository.kt | 67 +++++++++++++++++++ .../adapters/persistence/UserRepository.kt | 4 ++ src/main/resources/db/migration/.gitkeep | 0 src/main/resources/db/migration/V1__init.sql | 59 ++++++++++++++++ 6 files changed, 135 insertions(+), 59 deletions(-) delete mode 100644 sql/init.sql create mode 100644 src/main/kotlin/com/project/movienight/adapters/persistence/FilmLibraryRepository.kt create mode 100644 src/main/kotlin/com/project/movienight/adapters/persistence/FilmRepository.kt create mode 100644 src/main/kotlin/com/project/movienight/adapters/persistence/UserRepository.kt delete mode 100644 src/main/resources/db/migration/.gitkeep create mode 100644 src/main/resources/db/migration/V1__init.sql diff --git a/sql/init.sql b/sql/init.sql deleted file mode 100644 index d153740..0000000 --- a/sql/init.sql +++ /dev/null @@ -1,59 +0,0 @@ --- DROP SCHEMA public; --- CREATE SCHEMA public AUTHORIZATION pg_database_owner; --- COMMENT ON SCHEMA public IS 'standard public schema'; - --- public.genres определение --- Drop table -DROP TABLE if exists public.genres; -CREATE TABLE public.genres ( - id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, - "name" varchar NULL, - CONSTRAINT genres_unique PRIMARY KEY (id) -); - - --- public.users определение --- Drop table -DROP TABLE if exists public.users; -CREATE TABLE public.users ( - id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, - login varchar NOT NULL, - "password" varchar NOT NULL, - CONSTRAINT users_unique UNIQUE (id) -); - - --- public.films определение --- Drop table -DROP TABLE if exists public.films; -CREATE TABLE public.films ( - id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, - title varchar NOT NULL, - genreid int4 NOT NULL, - issuedate date NULL, - CONSTRAINT films_unique UNIQUE(id) -); - -DROP TABLE if exists public.fiml_genres; -CREATE TABLE public.film_genres ( - id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, - genreid int4 NOT NULL, - filmid int4 NOT NULL, - CONSTRAINT film_genres_genre_fk FOREIGN KEY (genreid) REFERENCES public.genres(id), - CONSTRAINT film_genres_film_fk FOREIGN KEY (filmid) REFERENCES public.films(id) -); - - --- Drop table -DROP TABLE if exists public.favorites; -CREATE TABLE public.favorites ( - id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, - userid int4 NULL, - filmid int4 NULL, - "comment" varchar NULL, - isviewed bool NULL, - CONSTRAINT favorites_unique PRIMARY KEY (id), - CONSTRAINT favorites_films_fk FOREIGN KEY (filmid) REFERENCES public.films(id), - CONSTRAINT favorites_users_fk FOREIGN KEY (userid) REFERENCES public.users(id) -); - diff --git a/src/main/kotlin/com/project/movienight/adapters/persistence/FilmLibraryRepository.kt b/src/main/kotlin/com/project/movienight/adapters/persistence/FilmLibraryRepository.kt new file mode 100644 index 0000000..2c524e9 --- /dev/null +++ b/src/main/kotlin/com/project/movienight/adapters/persistence/FilmLibraryRepository.kt @@ -0,0 +1,5 @@ +package com.project.movienight.adapters.persistence + +import org.springframework.jdbc.core.JdbcTemplate + +class FilmLibraryRepository(private val jdbc: JdbcTemplate) {} diff --git a/src/main/kotlin/com/project/movienight/adapters/persistence/FilmRepository.kt b/src/main/kotlin/com/project/movienight/adapters/persistence/FilmRepository.kt new file mode 100644 index 0000000..35105c1 --- /dev/null +++ b/src/main/kotlin/com/project/movienight/adapters/persistence/FilmRepository.kt @@ -0,0 +1,67 @@ +package com.project.movienight.adapters.persistence + +import com.project.movienight.domain.model.Film +import org.springframework.jdbc.core.JdbcTemplate +import org.springframework.stereotype.Repository +import java.util.UUID + +@Repository +class FilmRepository(private val jdbc: JdbcTemplate) { + + fun findById(id: UUID): Film? = + jdbc.queryForObject( + "SELECT * FROM films WHERE id = ?", + { rs, _ -> + Film( + id = UUID.fromString(rs.getString("id")), + title = rs.getString("title"), + description = rs.getString("description"), + ) + }, + id.toString() + ) + + fun findAll(): List = + jdbc.query( + "SELECT * FROM films" + ) { rs, _ -> + Film( + id = UUID.fromString(rs.getString("id")), + title = rs.getString("title"), + description = rs.getString("description"), + ) + } + + fun findTopN(limit: Int, sortBy: String = "title"): List = + jdbc.query( + "SELECT * FROM films ORDER BY $sortBy LIMIT ?", + { rs, _ -> + Film( + id = UUID.fromString(rs.getString("id")), + title = rs.getString("title"), + description = rs.getString("description"), + ) + }, + limit + ) + + fun save(film: Film) { + jdbc.update( + """ + INSERT INTO films (id, title, description) + VALUES (?, ?, ?) + ON CONFLICT (id) DO UPDATE + SET title = ?, description = ? + """, + film.id.toString(), film.title, film.description, + film.title, film.description + ) + } + + fun deleteById(id: UUID) { + jdbc.update( + "DELETE FROM films WHERE id = ?", + id.toString() + ) + } +} diff --git a/src/main/kotlin/com/project/movienight/adapters/persistence/UserRepository.kt b/src/main/kotlin/com/project/movienight/adapters/persistence/UserRepository.kt new file mode 100644 index 0000000..84a59f0 --- /dev/null +++ b/src/main/kotlin/com/project/movienight/adapters/persistence/UserRepository.kt @@ -0,0 +1,4 @@ +package com.project.movienight.adapters.persistence + +class UserRepository { +} diff --git a/src/main/resources/db/migration/.gitkeep b/src/main/resources/db/migration/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/resources/db/migration/V1__init.sql b/src/main/resources/db/migration/V1__init.sql new file mode 100644 index 0000000..da677c4 --- /dev/null +++ b/src/main/resources/db/migration/V1__init.sql @@ -0,0 +1,59 @@ +-- DROP SCHEMA public; +-- CREATE SCHEMA public AUTHORIZATION pg_database_owner; +-- COMMENT ON SCHEMA public IS 'standard public schema'; + +-- public.genres определение +-- Drop table +DROP TABLE if exists public.genres; +CREATE TABLE public.genres ( + id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, + "name" varchar NULL, + CONSTRAINT genres_unique PRIMARY KEY (id) +); + + +-- public.users определение +-- Drop table +DROP TABLE if exists public.users; +CREATE TABLE public.users ( + id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, + login varchar NOT NULL, + "password" varchar NOT NULL, + CONSTRAINT users_unique UNIQUE (id) +); + + +-- public.films определение +-- Drop table +DROP TABLE if exists public.films; +CREATE TABLE public.films ( + id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, + title varchar NOT NULL, + genre_id int4 NOT NULL, + issue_date date NULL, + CONSTRAINT films_unique UNIQUE(id) +); + +DROP TABLE if exists public.film_genres; +CREATE TABLE public.film_genres ( + id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, + genre_id int4 NOT NULL, + film_id int4 NOT NULL, + CONSTRAINT film_genres_genre_fk FOREIGN KEY (genre_id) REFERENCES public.genres(id), + CONSTRAINT film_genres_film_fk FOREIGN KEY (film_id) REFERENCES public.films(id) +); + + +-- Drop table +DROP TABLE if exists public.favorites; +CREATE TABLE public.favorites ( + id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, + userid int4 NULL, + film_id int4 NULL, + "comment" varchar NULL, + is_viewed bool NULL, + CONSTRAINT favorites_unique PRIMARY KEY (id), + CONSTRAINT favorites_films_fk FOREIGN KEY (film_id) REFERENCES public.films(id), + CONSTRAINT favorites_users_fk FOREIGN KEY (user_id) REFERENCES public.users(id) +); + -- 2.54.0 From a5066397e0b9cc6528565e53b0258cff90e1de7e Mon Sep 17 00:00:00 2001 From: skettiks Date: Fri, 6 Mar 2026 17:58:04 +0300 Subject: [PATCH 6/6] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= =?UTF-8?q?=20=D0=B4=D0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/FilmLibraryRepository.kt | 84 ++++++++++++++++++- .../adapters/persistence/FilmRepository.kt | 33 ++++---- .../adapters/persistence/UserRepository.kt | 81 +++++++++++++++++- .../project/movienight/domain/model/Film.kt | 7 +- .../movienight/domain/model/FilmLibrary.kt | 9 +- src/main/resources/db/migration/init.sql | 59 ------------- 6 files changed, 190 insertions(+), 83 deletions(-) delete mode 100644 src/main/resources/db/migration/init.sql diff --git a/src/main/kotlin/com/project/movienight/adapters/persistence/FilmLibraryRepository.kt b/src/main/kotlin/com/project/movienight/adapters/persistence/FilmLibraryRepository.kt index 2c524e9..4f5c6e8 100644 --- a/src/main/kotlin/com/project/movienight/adapters/persistence/FilmLibraryRepository.kt +++ b/src/main/kotlin/com/project/movienight/adapters/persistence/FilmLibraryRepository.kt @@ -1,5 +1,87 @@ package com.project.movienight.adapters.persistence +import com.project.movienight.domain.model.FilmLibrary import org.springframework.jdbc.core.JdbcTemplate +import org.springframework.stereotype.Repository -class FilmLibraryRepository(private val jdbc: JdbcTemplate) {} +@Repository +class FilmLibraryRepository(private val jdbc: JdbcTemplate) { + + fun findById(id: Int): FilmLibrary? = + jdbc.queryForObject( + "SELECT * FROM favorites WHERE id = ?", + { rs, _ -> + FilmLibrary( + id = rs.getInt("id"), + userId = rs.getInt("userid"), + filmId = rs.getInt("film_id"), + comment = rs.getString("comment"), + isViewed = rs.getBoolean("is_viewed"), + ) + }, + id + ) + + fun findAllByUserId(userId: Int): List = + jdbc.query( + "SELECT * FROM favorites WHERE userid = ?", + { rs, _ -> + FilmLibrary( + id = rs.getInt("id"), + userId = rs.getInt("userid"), + filmId = rs.getInt("film_id"), + comment = rs.getString("comment"), + isViewed = rs.getBoolean("is_viewed"), + ) + }, + userId + ) + + fun findAll(): List = + jdbc.query( + "SELECT * FROM favorites" + ) { rs, _ -> + FilmLibrary( + id = rs.getInt("id"), + userId = rs.getInt("userid"), + filmId = rs.getInt("film_id"), + comment = rs.getString("comment"), + isViewed = rs.getBoolean("is_viewed"), + ) + } + + fun findTopN(limit: Int, sortBy: String = "id"): List = + jdbc.query( + "SELECT * FROM favorites ORDER BY $sortBy LIMIT ?", + { rs, _ -> + FilmLibrary( + id = rs.getInt("id"), + userId = rs.getInt("userid"), + filmId = rs.getInt("film_id"), + comment = rs.getString("comment"), + isViewed = rs.getBoolean("is_viewed"), + ) + }, + limit + ) + + fun save(library: FilmLibrary) { + jdbc.update( + """ + INSERT INTO favorites (userid, film_id, comment, is_viewed) + VALUES (?, ?, ?, ?) + ON CONFLICT (id) DO UPDATE + SET comment = ?, is_viewed = ? + """, + library.userId, library.filmId, library.comment, library.isViewed, + library.comment, library.isViewed + ) + } + + fun deleteById(id: Int) { + jdbc.update( + "DELETE FROM favorites WHERE id = ?", + id + ) + } +} diff --git a/src/main/kotlin/com/project/movienight/adapters/persistence/FilmRepository.kt b/src/main/kotlin/com/project/movienight/adapters/persistence/FilmRepository.kt index 35105c1..5c9b209 100644 --- a/src/main/kotlin/com/project/movienight/adapters/persistence/FilmRepository.kt +++ b/src/main/kotlin/com/project/movienight/adapters/persistence/FilmRepository.kt @@ -3,22 +3,23 @@ package com.project.movienight.adapters.persistence import com.project.movienight.domain.model.Film import org.springframework.jdbc.core.JdbcTemplate import org.springframework.stereotype.Repository -import java.util.UUID +import java.time.LocalDate @Repository class FilmRepository(private val jdbc: JdbcTemplate) { - fun findById(id: UUID): Film? = + fun findById(id: Int): Film? = jdbc.queryForObject( "SELECT * FROM films WHERE id = ?", { rs, _ -> Film( - id = UUID.fromString(rs.getString("id")), + id = rs.getInt("id"), title = rs.getString("title"), - description = rs.getString("description"), + genreId = rs.getInt("genre_id"), + issueDate = rs.getDate("issue_date")?.toLocalDate(), ) }, - id.toString() + id ) fun findAll(): List = @@ -26,9 +27,10 @@ class FilmRepository(private val jdbc: JdbcTemplate) { "SELECT * FROM films" ) { rs, _ -> Film( - id = UUID.fromString(rs.getString("id")), + id = rs.getInt("id"), title = rs.getString("title"), - description = rs.getString("description"), + genreId = rs.getInt("genre_id"), + issueDate = rs.getDate("issue_date")?.toLocalDate(), ) } @@ -37,9 +39,10 @@ class FilmRepository(private val jdbc: JdbcTemplate) { "SELECT * FROM films ORDER BY $sortBy LIMIT ?", { rs, _ -> Film( - id = UUID.fromString(rs.getString("id")), + id = rs.getInt("id"), title = rs.getString("title"), - description = rs.getString("description"), + genreId = rs.getInt("genre_id"), + issueDate = rs.getDate("issue_date")?.toLocalDate(), ) }, limit @@ -48,20 +51,20 @@ class FilmRepository(private val jdbc: JdbcTemplate) { fun save(film: Film) { jdbc.update( """ - INSERT INTO films (id, title, description) + INSERT INTO films (title, genre_id, issue_date) VALUES (?, ?, ?) ON CONFLICT (id) DO UPDATE - SET title = ?, description = ? + SET title = ?, genre_id = ?, issue_date = ? """, - film.id.toString(), film.title, film.description, - film.title, film.description + film.title, film.genreId, film.issueDate, + film.title, film.genreId, film.issueDate ) } - fun deleteById(id: UUID) { + fun deleteById(id: Int) { jdbc.update( "DELETE FROM films WHERE id = ?", - id.toString() + id ) } } diff --git a/src/main/kotlin/com/project/movienight/adapters/persistence/UserRepository.kt b/src/main/kotlin/com/project/movienight/adapters/persistence/UserRepository.kt index 84a59f0..e453043 100644 --- a/src/main/kotlin/com/project/movienight/adapters/persistence/UserRepository.kt +++ b/src/main/kotlin/com/project/movienight/adapters/persistence/UserRepository.kt @@ -1,4 +1,83 @@ package com.project.movienight.adapters.persistence -class UserRepository { +import com.project.movienight.domain.model.Film +import com.project.movienight.domain.model.User +import org.springframework.jdbc.core.JdbcTemplate +import org.springframework.stereotype.Repository +import java.util.UUID + +@Repository +class UserRepository(private val jdbc: JdbcTemplate) { + + fun findById(id: UUID): User? = + jdbc.queryForObject( + "SELECT * FROM users WHERE id = ?", + {rs, _ -> + User( + id = UUID.fromString(rs.getString("id")), + name = rs.getString("name"), + email = rs.getString("email"), + library = null // брать библиотеку пользователя лучше отдельным запросом, + // который будет в FilmLibraryRepository + ) + }, + id.toString() + ) + + fun save(user: User) { + jdbc.update( + """ + INSERT INTO users(id, name, email, library) + VALUES (:id, :name, :email, :library) + ON CONFLICT (id) + DO UPDATE SET name = :name, email = :email, library = :library + """, + user.id.toString(), user.name, user.email, user.library, + user.name, user.email, user.library + ) + } + + fun deleteById(id: UUID) { + jdbc.update( + "DELETE FROM users WHERE id = ?", + id.toString() + ) + } + + fun findByEmail(email: String): User? = + jdbc.queryForObject( + "SELECT * FROM users WHERE email = ?", + {rs, _ -> + User( + id = UUID.fromString(rs.getString("id")), + name = rs.getString("name"), + email = rs.getString("email"), + library = null + ) + }, + + ) + fun findTopN(limit: Int, sortBy: String = "name"): List = + jdbc.query( + "SELECT * FROM users ORDER BY $sortBy LIMIT ?", + { rs, _ -> + User( + id = UUID.fromString(rs.getString("id")), + name = rs.getString("name"), + email = rs.getString("email"), + library = null + ) + }, + limit + ) + + fun existsByEmail(email: String): Boolean { + val count = jdbc.queryForObject( + "SELECT COUNT(*) FROM users WHERE email = ?", + Int::class.java, + email + ) ?: 0 + return count > 0 + } + } diff --git a/src/main/kotlin/com/project/movienight/domain/model/Film.kt b/src/main/kotlin/com/project/movienight/domain/model/Film.kt index 32122de..d1e6319 100644 --- a/src/main/kotlin/com/project/movienight/domain/model/Film.kt +++ b/src/main/kotlin/com/project/movienight/domain/model/Film.kt @@ -1,9 +1,10 @@ package com.project.movienight.domain.model -import java.util.UUID +import java.time.LocalDate data class Film( - val id: UUID, + val id: Int, val title: String, - val description: String, + val genreId: Int, + val issueDate: LocalDate?, ) diff --git a/src/main/kotlin/com/project/movienight/domain/model/FilmLibrary.kt b/src/main/kotlin/com/project/movienight/domain/model/FilmLibrary.kt index 2f6a724..040a474 100644 --- a/src/main/kotlin/com/project/movienight/domain/model/FilmLibrary.kt +++ b/src/main/kotlin/com/project/movienight/domain/model/FilmLibrary.kt @@ -1,8 +1,9 @@ package com.project.movienight.domain.model -import java.util.UUID - data class FilmLibrary( - val id: UUID, - val userId: UUID, + val id: Int, + val userId: Int, + val filmId: Int, + val comment: String?, + val isViewed: Boolean, ) diff --git a/src/main/resources/db/migration/init.sql b/src/main/resources/db/migration/init.sql deleted file mode 100644 index d153740..0000000 --- a/src/main/resources/db/migration/init.sql +++ /dev/null @@ -1,59 +0,0 @@ --- DROP SCHEMA public; --- CREATE SCHEMA public AUTHORIZATION pg_database_owner; --- COMMENT ON SCHEMA public IS 'standard public schema'; - --- public.genres определение --- Drop table -DROP TABLE if exists public.genres; -CREATE TABLE public.genres ( - id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, - "name" varchar NULL, - CONSTRAINT genres_unique PRIMARY KEY (id) -); - - --- public.users определение --- Drop table -DROP TABLE if exists public.users; -CREATE TABLE public.users ( - id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, - login varchar NOT NULL, - "password" varchar NOT NULL, - CONSTRAINT users_unique UNIQUE (id) -); - - --- public.films определение --- Drop table -DROP TABLE if exists public.films; -CREATE TABLE public.films ( - id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, - title varchar NOT NULL, - genreid int4 NOT NULL, - issuedate date NULL, - CONSTRAINT films_unique UNIQUE(id) -); - -DROP TABLE if exists public.fiml_genres; -CREATE TABLE public.film_genres ( - id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, - genreid int4 NOT NULL, - filmid int4 NOT NULL, - CONSTRAINT film_genres_genre_fk FOREIGN KEY (genreid) REFERENCES public.genres(id), - CONSTRAINT film_genres_film_fk FOREIGN KEY (filmid) REFERENCES public.films(id) -); - - --- Drop table -DROP TABLE if exists public.favorites; -CREATE TABLE public.favorites ( - id int4 GENERATED ALWAYS AS IDENTITY NOT NULL, - userid int4 NULL, - filmid int4 NULL, - "comment" varchar NULL, - isviewed bool NULL, - CONSTRAINT favorites_unique PRIMARY KEY (id), - CONSTRAINT favorites_films_fk FOREIGN KEY (filmid) REFERENCES public.films(id), - CONSTRAINT favorites_users_fk FOREIGN KEY (userid) REFERENCES public.users(id) -); - -- 2.54.0