Merge pull request #37 from devitq/hotfix/fix-ci
hotfix(ci): fixed tests and style
This commit was merged in pull request #37.
This commit is contained in:
@@ -62,11 +62,12 @@ class FilmRepository(
|
||||
)
|
||||
|
||||
override fun findByTitle(title: String): Film? {
|
||||
val films = jdbc.query(
|
||||
"SELECT id, title, description FROM films WHERE title = ?",
|
||||
filmRowMapper,
|
||||
title
|
||||
)
|
||||
val films =
|
||||
jdbc.query(
|
||||
"SELECT id, title, description FROM films WHERE title = ?",
|
||||
filmRowMapper,
|
||||
title,
|
||||
)
|
||||
return films.firstOrNull()
|
||||
}
|
||||
|
||||
|
||||
@@ -69,10 +69,11 @@ class UserRepository(
|
||||
}
|
||||
|
||||
override fun findAll(): List<User> =
|
||||
jdbc.query(
|
||||
"SELECT id, name, email, provider, provider_id, created_at FROM users",
|
||||
userEntityRowMapper,
|
||||
).map { it.toDomain() }
|
||||
jdbc
|
||||
.query(
|
||||
"SELECT id, name, email, provider, provider_id, created_at FROM users",
|
||||
userEntityRowMapper,
|
||||
).map { it.toDomain() }
|
||||
|
||||
override fun deleteById(id: UUID) {
|
||||
jdbc.update("DELETE FROM users WHERE id = ?", id)
|
||||
@@ -84,7 +85,10 @@ class UserRepository(
|
||||
): User? {
|
||||
val entities =
|
||||
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,
|
||||
provider.name,
|
||||
providerId,
|
||||
|
||||
@@ -56,10 +56,11 @@ class FilmController(
|
||||
FilmResponse.fromDomain(
|
||||
editFilmUseCase.edit(
|
||||
id = id,
|
||||
command = EditFilmCommand(
|
||||
title = request.title,
|
||||
description = request.description,
|
||||
),
|
||||
command =
|
||||
EditFilmCommand(
|
||||
title = request.title,
|
||||
description = request.description,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -72,16 +73,13 @@ class FilmController(
|
||||
@GetMapping("/{id}")
|
||||
fun getById(
|
||||
@PathVariable id: UUID,
|
||||
): FilmResponse =
|
||||
FilmResponse.fromDomain(getFilmByIdUseCase.getById(id))
|
||||
): FilmResponse = FilmResponse.fromDomain(getFilmByIdUseCase.getById(id))
|
||||
|
||||
@GetMapping("/search")
|
||||
fun searchByTitle(
|
||||
@RequestParam title: String,
|
||||
): FilmResponse? =
|
||||
searchFilmByTitleUseCase.searchByTitle(title)?.let { FilmResponse.fromDomain(it) }
|
||||
): FilmResponse? = searchFilmByTitleUseCase.searchByTitle(title)?.let { FilmResponse.fromDomain(it) }
|
||||
|
||||
@GetMapping
|
||||
fun getAll(): List<FilmResponse> =
|
||||
getAllFilmsUseCase.getAll().map { FilmResponse.fromDomain(it) }
|
||||
fun getAll(): List<FilmResponse> = getAllFilmsUseCase.getAll().map { FilmResponse.fromDomain(it) }
|
||||
}
|
||||
|
||||
@@ -63,9 +63,10 @@ class FilmLibraryController(
|
||||
fun getAllFilmsInLibrary(
|
||||
@PathVariable userId: UUID,
|
||||
): List<FilmResponse> {
|
||||
val library = getFilmLibraryUseCase.getLibrary(
|
||||
GetFilmLibraryQuery(userId = userId)
|
||||
)
|
||||
val library =
|
||||
getFilmLibraryUseCase.getLibrary(
|
||||
GetFilmLibraryQuery(userId = userId),
|
||||
)
|
||||
|
||||
val film = getFilmByIdUseCase.getById(library.filmId)
|
||||
|
||||
@@ -92,20 +93,23 @@ class FilmLibraryController(
|
||||
fun removeFilm(
|
||||
@PathVariable userId: UUID,
|
||||
@PathVariable filmId: UUID,
|
||||
) = removeFilmFromLibraryUseCase.removeFilm(
|
||||
RemoveFilmFromLibraryCommand(
|
||||
userId = userId,
|
||||
filmId = filmId,
|
||||
),
|
||||
)
|
||||
) {
|
||||
removeFilmFromLibraryUseCase.removeFilm(
|
||||
RemoveFilmFromLibraryCommand(
|
||||
userId = userId,
|
||||
filmId = filmId,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@GetMapping("/available-films")
|
||||
fun getAvailableFilms(
|
||||
@PathVariable userId: UUID,
|
||||
): List<FilmResponse> {
|
||||
val userLibrary = getFilmLibraryUseCase.getLibrary(
|
||||
GetFilmLibraryQuery(userId = userId)
|
||||
)
|
||||
val userLibrary =
|
||||
getFilmLibraryUseCase.getLibrary(
|
||||
GetFilmLibraryQuery(userId = userId),
|
||||
)
|
||||
|
||||
val allFilms = getAllFilmsUseCase.getAll()
|
||||
|
||||
|
||||
@@ -46,14 +46,12 @@ class UserController(
|
||||
)
|
||||
|
||||
@GetMapping
|
||||
fun getAll(): List<UserResponse> =
|
||||
getAllUsersUseCase.getAll().map { UserResponse.fromDomain(it) }
|
||||
fun getAll(): List<UserResponse> = getAllUsersUseCase.getAll().map { UserResponse.fromDomain(it) }
|
||||
|
||||
@GetMapping("/{id}")
|
||||
fun getById(
|
||||
@PathVariable id: UUID,
|
||||
): UserResponse =
|
||||
UserResponse.fromDomain(getUserByIdUseCase.getById(id))
|
||||
): UserResponse = UserResponse.fromDomain(getUserByIdUseCase.getById(id))
|
||||
|
||||
@PatchMapping("/{id}")
|
||||
fun edit(
|
||||
@@ -63,9 +61,10 @@ class UserController(
|
||||
UserResponse.fromDomain(
|
||||
editUserUseCase.edit(
|
||||
id = id,
|
||||
command = EditUserCommand(
|
||||
name = request.name,
|
||||
),
|
||||
command =
|
||||
EditUserCommand(
|
||||
name = request.name,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ class FilmService(
|
||||
GetFilmByIdUseCase,
|
||||
GetAllFilmsUseCase,
|
||||
SearchFilmByTitleUseCase {
|
||||
|
||||
override fun create(command: CreateFilmCommand): Film {
|
||||
if (filmConfig.isBlocked(command.title)) {
|
||||
throw BlockedValueException(target = "Film", field = "title")
|
||||
@@ -37,15 +36,19 @@ class FilmService(
|
||||
throw BlockedValueException(target = "Film", field = "description")
|
||||
}
|
||||
|
||||
val film = Film(
|
||||
id = idGenerator.generateId(),
|
||||
title = command.title,
|
||||
description = command.description,
|
||||
)
|
||||
val film =
|
||||
Film(
|
||||
id = idGenerator.generateId(),
|
||||
title = command.title,
|
||||
description = command.description,
|
||||
)
|
||||
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)) {
|
||||
throw BlockedValueException(target = "Film", field = "title")
|
||||
}
|
||||
@@ -63,9 +66,8 @@ class FilmService(
|
||||
filmRepository.deleteById(id)
|
||||
}
|
||||
|
||||
override fun getById(id: UUID): Film {
|
||||
return filmRepository.findById(id) ?: throw EntityNotFoundException(entity = "Film", id = id.toString())
|
||||
}
|
||||
override fun getById(id: UUID): Film =
|
||||
filmRepository.findById(id) ?: throw EntityNotFoundException(entity = "Film", id = id.toString())
|
||||
|
||||
override fun getAll(): List<Film> = filmRepository.findAll()
|
||||
|
||||
|
||||
@@ -26,18 +26,18 @@ class UserService(
|
||||
DeleteUserUseCase,
|
||||
GetUserByIdUseCase,
|
||||
GetAllUsersUseCase {
|
||||
|
||||
override fun create(command: CreateUserCommand): User {
|
||||
if (userConfig.isBlocked(command.name)) {
|
||||
throw BlockedValueException(target = "User", field = "name")
|
||||
}
|
||||
|
||||
val user = User(
|
||||
id = idGenerator.generateId(),
|
||||
name = command.name,
|
||||
email = command.email,
|
||||
library = null,
|
||||
)
|
||||
val user =
|
||||
User(
|
||||
id = idGenerator.generateId(),
|
||||
name = command.name,
|
||||
email = command.email,
|
||||
library = null,
|
||||
)
|
||||
return userRepository.save(user)
|
||||
}
|
||||
|
||||
@@ -59,9 +59,8 @@ class UserService(
|
||||
userRepository.deleteById(id)
|
||||
}
|
||||
|
||||
override fun getById(id: UUID): User {
|
||||
return userRepository.findById(id) ?: throw EntityNotFoundException(entity = "User", id = id.toString())
|
||||
}
|
||||
override fun getById(id: UUID): User =
|
||||
userRepository.findById(id) ?: throw EntityNotFoundException(entity = "User", id = id.toString())
|
||||
|
||||
override fun getAll(): List<User> = userRepository.findAll()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
CREATE TABLE IF NOT EXISTS public.users (
|
||||
id UUID PRIMARY KEY,
|
||||
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
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.films (
|
||||
|
||||
+30
-29
@@ -9,17 +9,17 @@ import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNull
|
||||
|
||||
class UserEntityMappingTest {
|
||||
|
||||
@Test
|
||||
fun `toDomain maps UserEntity correctly`() {
|
||||
val entity = UserEntity(
|
||||
id = UUID.randomUUID(),
|
||||
name = "John Pork",
|
||||
email = "john@email.com",
|
||||
provider = "GOOGLE",
|
||||
providerId = "google1234",
|
||||
createdAt = LocalDateTime.now(),
|
||||
)
|
||||
val entity =
|
||||
UserEntity(
|
||||
id = UUID.randomUUID(),
|
||||
name = "John Pork",
|
||||
email = "john@email.com",
|
||||
provider = "GOOGLE",
|
||||
providerId = "google1234",
|
||||
createdAt = LocalDateTime.now(),
|
||||
)
|
||||
val user = entity.toDomain()
|
||||
|
||||
assertEquals(entity.id, user.id)
|
||||
@@ -30,12 +30,13 @@ class UserEntityMappingTest {
|
||||
|
||||
@Test
|
||||
fun `toEntity maps User with OAuth provider`() {
|
||||
val user = User(
|
||||
id = UUID.randomUUID(),
|
||||
name = "Jane",
|
||||
email = "jane@mail.com",
|
||||
library = null
|
||||
)
|
||||
val user =
|
||||
User(
|
||||
id = UUID.randomUUID(),
|
||||
name = "Jane",
|
||||
email = "jane@mail.com",
|
||||
library = null,
|
||||
)
|
||||
|
||||
val entity = user.toEntity(AuthProvider.YANDEX, "yandex456")
|
||||
|
||||
@@ -48,12 +49,13 @@ class UserEntityMappingTest {
|
||||
|
||||
@Test
|
||||
fun `toEntity maps User without OAuth provider`() {
|
||||
val user = User(
|
||||
id = UUID.randomUUID(),
|
||||
name = "Bob",
|
||||
email = "bob@mail.com",
|
||||
library = null
|
||||
)
|
||||
val user =
|
||||
User(
|
||||
id = UUID.randomUUID(),
|
||||
name = "Bob",
|
||||
email = "bob@mail.com",
|
||||
library = null,
|
||||
)
|
||||
|
||||
val entity = user.toEntity()
|
||||
|
||||
@@ -63,12 +65,13 @@ class UserEntityMappingTest {
|
||||
|
||||
@Test
|
||||
fun `mapping is reversible for basic fields`() {
|
||||
val original = User(
|
||||
id = UUID.randomUUID(),
|
||||
name = "Alice",
|
||||
email = "alice@email.com",
|
||||
library = null
|
||||
)
|
||||
val original =
|
||||
User(
|
||||
id = UUID.randomUUID(),
|
||||
name = "Alice",
|
||||
email = "alice@email.com",
|
||||
library = null,
|
||||
)
|
||||
|
||||
val mapped = original.toEntity().toDomain()
|
||||
|
||||
@@ -76,6 +79,4 @@ class UserEntityMappingTest {
|
||||
assertEquals(original.name, mapped.name)
|
||||
assertEquals(original.email, mapped.email)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user