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? {
|
override fun findByTitle(title: String): Film? {
|
||||||
val films = jdbc.query(
|
val films =
|
||||||
"SELECT id, title, description FROM films WHERE title = ?",
|
jdbc.query(
|
||||||
filmRowMapper,
|
"SELECT id, title, description FROM films WHERE title = ?",
|
||||||
title
|
filmRowMapper,
|
||||||
)
|
title,
|
||||||
|
)
|
||||||
return films.firstOrNull()
|
return films.firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,10 +69,11 @@ class UserRepository(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun findAll(): List<User> =
|
override fun findAll(): List<User> =
|
||||||
jdbc.query(
|
jdbc
|
||||||
"SELECT id, name, email, provider, provider_id, created_at FROM users",
|
.query(
|
||||||
userEntityRowMapper,
|
"SELECT id, name, email, provider, provider_id, created_at FROM users",
|
||||||
).map { it.toDomain() }
|
userEntityRowMapper,
|
||||||
|
).map { it.toDomain() }
|
||||||
|
|
||||||
override fun deleteById(id: UUID) {
|
override fun deleteById(id: UUID) {
|
||||||
jdbc.update("DELETE FROM users WHERE id = ?", id)
|
jdbc.update("DELETE FROM users WHERE id = ?", id)
|
||||||
@@ -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,10 +56,11 @@ class FilmController(
|
|||||||
FilmResponse.fromDomain(
|
FilmResponse.fromDomain(
|
||||||
editFilmUseCase.edit(
|
editFilmUseCase.edit(
|
||||||
id = id,
|
id = id,
|
||||||
command = EditFilmCommand(
|
command =
|
||||||
title = request.title,
|
EditFilmCommand(
|
||||||
description = request.description,
|
title = request.title,
|
||||||
),
|
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,9 +63,10 @@ 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,20 +93,23 @@ class FilmLibraryController(
|
|||||||
fun removeFilm(
|
fun removeFilm(
|
||||||
@PathVariable userId: UUID,
|
@PathVariable userId: UUID,
|
||||||
@PathVariable filmId: UUID,
|
@PathVariable filmId: UUID,
|
||||||
) = removeFilmFromLibraryUseCase.removeFilm(
|
) {
|
||||||
RemoveFilmFromLibraryCommand(
|
removeFilmFromLibraryUseCase.removeFilm(
|
||||||
userId = userId,
|
RemoveFilmFromLibraryCommand(
|
||||||
filmId = filmId,
|
userId = userId,
|
||||||
),
|
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,9 +61,10 @@ class UserController(
|
|||||||
UserResponse.fromDomain(
|
UserResponse.fromDomain(
|
||||||
editUserUseCase.edit(
|
editUserUseCase.edit(
|
||||||
id = id,
|
id = id,
|
||||||
command = EditUserCommand(
|
command =
|
||||||
name = request.name,
|
EditUserCommand(
|
||||||
),
|
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,15 +36,19 @@ class FilmService(
|
|||||||
throw BlockedValueException(target = "Film", field = "description")
|
throw BlockedValueException(target = "Film", field = "description")
|
||||||
}
|
}
|
||||||
|
|
||||||
val film = Film(
|
val film =
|
||||||
id = idGenerator.generateId(),
|
Film(
|
||||||
title = command.title,
|
id = idGenerator.generateId(),
|
||||||
description = command.description,
|
title = command.title,
|
||||||
)
|
description = command.description,
|
||||||
|
)
|
||||||
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,18 +26,18 @@ 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 =
|
||||||
id = idGenerator.generateId(),
|
User(
|
||||||
name = command.name,
|
id = idGenerator.generateId(),
|
||||||
email = command.email,
|
name = command.name,
|
||||||
library = null,
|
email = command.email,
|
||||||
)
|
library = null,
|
||||||
|
)
|
||||||
return userRepository.save(user)
|
return userRepository.save(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS public.films (
|
CREATE TABLE IF NOT EXISTS public.films (
|
||||||
|
|||||||
+30
-29
@@ -9,17 +9,17 @@ 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 =
|
||||||
id = UUID.randomUUID(),
|
UserEntity(
|
||||||
name = "John Pork",
|
id = UUID.randomUUID(),
|
||||||
email = "john@email.com",
|
name = "John Pork",
|
||||||
provider = "GOOGLE",
|
email = "john@email.com",
|
||||||
providerId = "google1234",
|
provider = "GOOGLE",
|
||||||
createdAt = LocalDateTime.now(),
|
providerId = "google1234",
|
||||||
)
|
createdAt = LocalDateTime.now(),
|
||||||
|
)
|
||||||
val user = entity.toDomain()
|
val user = entity.toDomain()
|
||||||
|
|
||||||
assertEquals(entity.id, user.id)
|
assertEquals(entity.id, user.id)
|
||||||
@@ -30,12 +30,13 @@ class UserEntityMappingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `toEntity maps User with OAuth provider`() {
|
fun `toEntity maps User with OAuth provider`() {
|
||||||
val user = User(
|
val user =
|
||||||
id = UUID.randomUUID(),
|
User(
|
||||||
name = "Jane",
|
id = UUID.randomUUID(),
|
||||||
email = "jane@mail.com",
|
name = "Jane",
|
||||||
library = null
|
email = "jane@mail.com",
|
||||||
)
|
library = null,
|
||||||
|
)
|
||||||
|
|
||||||
val entity = user.toEntity(AuthProvider.YANDEX, "yandex456")
|
val entity = user.toEntity(AuthProvider.YANDEX, "yandex456")
|
||||||
|
|
||||||
@@ -48,12 +49,13 @@ class UserEntityMappingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `toEntity maps User without OAuth provider`() {
|
fun `toEntity maps User without OAuth provider`() {
|
||||||
val user = User(
|
val user =
|
||||||
id = UUID.randomUUID(),
|
User(
|
||||||
name = "Bob",
|
id = UUID.randomUUID(),
|
||||||
email = "bob@mail.com",
|
name = "Bob",
|
||||||
library = null
|
email = "bob@mail.com",
|
||||||
)
|
library = null,
|
||||||
|
)
|
||||||
|
|
||||||
val entity = user.toEntity()
|
val entity = user.toEntity()
|
||||||
|
|
||||||
@@ -63,12 +65,13 @@ class UserEntityMappingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `mapping is reversible for basic fields`() {
|
fun `mapping is reversible for basic fields`() {
|
||||||
val original = User(
|
val original =
|
||||||
id = UUID.randomUUID(),
|
User(
|
||||||
name = "Alice",
|
id = UUID.randomUUID(),
|
||||||
email = "alice@email.com",
|
name = "Alice",
|
||||||
library = null
|
email = "alice@email.com",
|
||||||
)
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user