hotfix(ci): fixed tests and style #37

Merged
devitq merged 4 commits from hotfix/fix-ci into develop 2026-05-03 18:12:10 +00:00
9 changed files with 100 additions and 89 deletions
@@ -62,10 +62,11 @@ class FilmRepository(
) )
override fun findByTitle(title: String): Film? { override fun findByTitle(title: String): Film? {
val films = jdbc.query( val films =
jdbc.query(
"SELECT id, title, description FROM films WHERE title = ?", "SELECT id, title, description FROM films WHERE title = ?",
filmRowMapper, filmRowMapper,
title title,
) )
return films.firstOrNull() return films.firstOrNull()
} }
@@ -69,7 +69,8 @@ class UserRepository(
} }
override fun findAll(): List<User> = override fun findAll(): List<User> =
jdbc.query( jdbc
.query(
"SELECT id, name, email, provider, provider_id, created_at FROM users", "SELECT id, name, email, provider, provider_id, created_at FROM users",
userEntityRowMapper, userEntityRowMapper,
).map { it.toDomain() } ).map { it.toDomain() }
@@ -84,7 +85,10 @@ class UserRepository(
): User? { ): User? {
val entities = val entities =
jdbc.query( jdbc.query(
"SELECT id, name, email, provider, provider_id, created_at FROM users WHERE provider = ? AND provider_id = ?", """
SELECT id, name, email, provider, provider_id, created_at FROM users
WHERE provider = ? AND provider_id = ?
""".trimIndent(),
userEntityRowMapper, userEntityRowMapper,
provider.name, provider.name,
providerId, providerId,
@@ -56,7 +56,8 @@ class FilmController(
FilmResponse.fromDomain( FilmResponse.fromDomain(
editFilmUseCase.edit( editFilmUseCase.edit(
id = id, id = id,
command = EditFilmCommand( command =
EditFilmCommand(
title = request.title, title = request.title,
description = request.description, description = request.description,
), ),
@@ -72,16 +73,13 @@ class FilmController(
@GetMapping("/{id}") @GetMapping("/{id}")
fun getById( fun getById(
@PathVariable id: UUID, @PathVariable id: UUID,
): FilmResponse = ): FilmResponse = FilmResponse.fromDomain(getFilmByIdUseCase.getById(id))
FilmResponse.fromDomain(getFilmByIdUseCase.getById(id))
@GetMapping("/search") @GetMapping("/search")
fun searchByTitle( fun searchByTitle(
@RequestParam title: String, @RequestParam title: String,
): FilmResponse? = ): FilmResponse? = searchFilmByTitleUseCase.searchByTitle(title)?.let { FilmResponse.fromDomain(it) }
searchFilmByTitleUseCase.searchByTitle(title)?.let { FilmResponse.fromDomain(it) }
@GetMapping @GetMapping
fun getAll(): List<FilmResponse> = fun getAll(): List<FilmResponse> = getAllFilmsUseCase.getAll().map { FilmResponse.fromDomain(it) }
getAllFilmsUseCase.getAll().map { FilmResponse.fromDomain(it) }
} }
@@ -63,8 +63,9 @@ class FilmLibraryController(
fun getAllFilmsInLibrary( fun getAllFilmsInLibrary(
@PathVariable userId: UUID, @PathVariable userId: UUID,
): List<FilmResponse> { ): List<FilmResponse> {
val library = getFilmLibraryUseCase.getLibrary( val library =
GetFilmLibraryQuery(userId = userId) getFilmLibraryUseCase.getLibrary(
GetFilmLibraryQuery(userId = userId),
) )
val film = getFilmByIdUseCase.getById(library.filmId) val film = getFilmByIdUseCase.getById(library.filmId)
@@ -92,19 +93,22 @@ class FilmLibraryController(
fun removeFilm( fun removeFilm(
@PathVariable userId: UUID, @PathVariable userId: UUID,
@PathVariable filmId: UUID, @PathVariable filmId: UUID,
) = removeFilmFromLibraryUseCase.removeFilm( ) {
removeFilmFromLibraryUseCase.removeFilm(
RemoveFilmFromLibraryCommand( RemoveFilmFromLibraryCommand(
userId = userId, userId = userId,
filmId = filmId, filmId = filmId,
), ),
) )
}
@GetMapping("/available-films") @GetMapping("/available-films")
fun getAvailableFilms( fun getAvailableFilms(
@PathVariable userId: UUID, @PathVariable userId: UUID,
): List<FilmResponse> { ): List<FilmResponse> {
val userLibrary = getFilmLibraryUseCase.getLibrary( val userLibrary =
GetFilmLibraryQuery(userId = userId) getFilmLibraryUseCase.getLibrary(
GetFilmLibraryQuery(userId = userId),
) )
val allFilms = getAllFilmsUseCase.getAll() val allFilms = getAllFilmsUseCase.getAll()
@@ -46,14 +46,12 @@ class UserController(
) )
@GetMapping @GetMapping
fun getAll(): List<UserResponse> = fun getAll(): List<UserResponse> = getAllUsersUseCase.getAll().map { UserResponse.fromDomain(it) }
getAllUsersUseCase.getAll().map { UserResponse.fromDomain(it) }
@GetMapping("/{id}") @GetMapping("/{id}")
fun getById( fun getById(
@PathVariable id: UUID, @PathVariable id: UUID,
): UserResponse = ): UserResponse = UserResponse.fromDomain(getUserByIdUseCase.getById(id))
UserResponse.fromDomain(getUserByIdUseCase.getById(id))
@PatchMapping("/{id}") @PatchMapping("/{id}")
fun edit( fun edit(
@@ -63,7 +61,8 @@ class UserController(
UserResponse.fromDomain( UserResponse.fromDomain(
editUserUseCase.edit( editUserUseCase.edit(
id = id, id = id,
command = EditUserCommand( command =
EditUserCommand(
name = request.name, name = request.name,
), ),
), ),
@@ -28,7 +28,6 @@ class FilmService(
GetFilmByIdUseCase, GetFilmByIdUseCase,
GetAllFilmsUseCase, GetAllFilmsUseCase,
SearchFilmByTitleUseCase { SearchFilmByTitleUseCase {
override fun create(command: CreateFilmCommand): Film { override fun create(command: CreateFilmCommand): Film {
if (filmConfig.isBlocked(command.title)) { if (filmConfig.isBlocked(command.title)) {
throw BlockedValueException(target = "Film", field = "title") throw BlockedValueException(target = "Film", field = "title")
@@ -37,7 +36,8 @@ class FilmService(
throw BlockedValueException(target = "Film", field = "description") throw BlockedValueException(target = "Film", field = "description")
} }
val film = Film( val film =
Film(
id = idGenerator.generateId(), id = idGenerator.generateId(),
title = command.title, title = command.title,
description = command.description, description = command.description,
@@ -45,7 +45,10 @@ class FilmService(
return filmRepository.save(film) return filmRepository.save(film)
} }
override fun edit(id: UUID, command: EditFilmCommand): Film { override fun edit(
id: UUID,
command: EditFilmCommand,
): Film {
if (filmConfig.isBlocked(command.title)) { if (filmConfig.isBlocked(command.title)) {
throw BlockedValueException(target = "Film", field = "title") throw BlockedValueException(target = "Film", field = "title")
} }
@@ -63,9 +66,8 @@ class FilmService(
filmRepository.deleteById(id) filmRepository.deleteById(id)
} }
override fun getById(id: UUID): Film { override fun getById(id: UUID): Film =
return filmRepository.findById(id) ?: throw EntityNotFoundException(entity = "Film", id = id.toString()) filmRepository.findById(id) ?: throw EntityNotFoundException(entity = "Film", id = id.toString())
}
override fun getAll(): List<Film> = filmRepository.findAll() override fun getAll(): List<Film> = filmRepository.findAll()
@@ -26,13 +26,13 @@ class UserService(
DeleteUserUseCase, DeleteUserUseCase,
GetUserByIdUseCase, GetUserByIdUseCase,
GetAllUsersUseCase { GetAllUsersUseCase {
override fun create(command: CreateUserCommand): User { override fun create(command: CreateUserCommand): User {
if (userConfig.isBlocked(command.name)) { if (userConfig.isBlocked(command.name)) {
throw BlockedValueException(target = "User", field = "name") throw BlockedValueException(target = "User", field = "name")
} }
val user = User( val user =
User(
id = idGenerator.generateId(), id = idGenerator.generateId(),
name = command.name, name = command.name,
email = command.email, email = command.email,
@@ -59,9 +59,8 @@ class UserService(
userRepository.deleteById(id) userRepository.deleteById(id)
} }
override fun getById(id: UUID): User { override fun getById(id: UUID): User =
return userRepository.findById(id) ?: throw EntityNotFoundException(entity = "User", id = id.toString()) userRepository.findById(id) ?: throw EntityNotFoundException(entity = "User", id = id.toString())
}
override fun getAll(): List<User> = userRepository.findAll() override fun getAll(): List<User> = userRepository.findAll()
} }
+4 -1
View File
@@ -1,7 +1,10 @@
CREATE TABLE IF NOT EXISTS public.users ( CREATE TABLE IF NOT EXISTS public.users (
id UUID PRIMARY KEY, id UUID PRIMARY KEY,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
email VARCHAR(320) NOT NULL UNIQUE email VARCHAR(320) NOT NULL UNIQUE,
provider VARCHAR(64),
provider_id VARCHAR(255),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
); );
copilot-pull-request-reviewer[bot] commented 2026-05-03 16:54:14 +00:00 (Migrated from github.com)
Review

Editing an existing V1__init.sql migration will break deployments on any environment that has already applied version 1, because Flyway validates migration checksums and will fail startup when a previously executed migration changes. This needs to be introduced as a new forward-only migration instead of rewriting V1.

Editing an existing `V1__init.sql` migration will break deployments on any environment that has already applied version 1, because Flyway validates migration checksums and will fail startup when a previously executed migration changes. This needs to be introduced as a new forward-only migration instead of rewriting `V1`.
copilot-pull-request-reviewer[bot] commented 2026-05-03 17:20:26 +00:00 (Migrated from github.com)
Review

This changes the contents of the already-versioned V1__init.sql migration instead of adding a new migration. Flyway will not re-run V1 in environments that have already applied it, so those databases will still be missing provider, provider_id, and created_at, and the updated repository queries will start failing at runtime when they select these columns.

This changes the contents of the already-versioned `V1__init.sql` migration instead of adding a new migration. Flyway will not re-run `V1` in environments that have already applied it, so those databases will still be missing `provider`, `provider_id`, and `created_at`, and the updated repository queries will start failing at runtime when they select these columns.
CREATE TABLE IF NOT EXISTS public.films ( CREATE TABLE IF NOT EXISTS public.films (
@@ -9,10 +9,10 @@ import kotlin.test.assertEquals
import kotlin.test.assertNull import kotlin.test.assertNull
class UserEntityMappingTest { class UserEntityMappingTest {
@Test @Test
fun `toDomain maps UserEntity correctly`() { fun `toDomain maps UserEntity correctly`() {
val entity = UserEntity( val entity =
UserEntity(
id = UUID.randomUUID(), id = UUID.randomUUID(),
name = "John Pork", name = "John Pork",
email = "john@email.com", email = "john@email.com",
@@ -30,11 +30,12 @@ class UserEntityMappingTest {
@Test @Test
fun `toEntity maps User with OAuth provider`() { fun `toEntity maps User with OAuth provider`() {
val user = User( val user =
User(
id = UUID.randomUUID(), id = UUID.randomUUID(),
name = "Jane", name = "Jane",
email = "jane@mail.com", email = "jane@mail.com",
library = null library = null,
) )
val entity = user.toEntity(AuthProvider.YANDEX, "yandex456") val entity = user.toEntity(AuthProvider.YANDEX, "yandex456")
@@ -48,11 +49,12 @@ class UserEntityMappingTest {
@Test @Test
fun `toEntity maps User without OAuth provider`() { fun `toEntity maps User without OAuth provider`() {
val user = User( val user =
User(
id = UUID.randomUUID(), id = UUID.randomUUID(),
name = "Bob", name = "Bob",
email = "bob@mail.com", email = "bob@mail.com",
library = null library = null,
) )
val entity = user.toEntity() val entity = user.toEntity()
@@ -63,11 +65,12 @@ class UserEntityMappingTest {
@Test @Test
fun `mapping is reversible for basic fields`() { fun `mapping is reversible for basic fields`() {
val original = User( val original =
User(
id = UUID.randomUUID(), id = UUID.randomUUID(),
name = "Alice", name = "Alice",
email = "alice@email.com", email = "alice@email.com",
library = null library = null,
) )
val mapped = original.toEntity().toDomain() val mapped = original.toEntity().toDomain()
@@ -76,6 +79,4 @@ class UserEntityMappingTest {
assertEquals(original.name, mapped.name) assertEquals(original.name, mapped.name)
assertEquals(original.email, mapped.email) assertEquals(original.email, mapped.email)
} }
} }