diff --git a/build.gradle.kts b/build.gradle.kts index aa3d088..cd92585 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,6 +10,7 @@ repositories { } dependencies { + implementation("io.github.serpro69:kotlin-faker:2.0.0-rc.7") testImplementation(kotlin("test")) } diff --git a/src/main/kotlin/Interface/AdminService.kt b/src/main/kotlin/Interface/AdminService.kt index 5b27ee7..3037baa 100644 --- a/src/main/kotlin/Interface/AdminService.kt +++ b/src/main/kotlin/Interface/AdminService.kt @@ -1,6 +1,6 @@ package Interface -import model.User +import data.features.authorize.model.User interface AdminService { fun removeUserById(userId: Int): Boolean diff --git a/src/main/kotlin/Interface/AuthorizeService.kt b/src/main/kotlin/Interface/AuthorizeService.kt index 3a2ce89..804846b 100644 --- a/src/main/kotlin/Interface/AuthorizeService.kt +++ b/src/main/kotlin/Interface/AuthorizeService.kt @@ -1,7 +1,5 @@ package Interface -import model.User - /* Interface AuthorizeService { fun registration(user: User):Boolean diff --git a/src/main/kotlin/RepositoryImpl/AdminServiceImpl.kt b/src/main/kotlin/RepositoryImpl/AdminServiceImpl.kt index 35367dc..3c136f4 100644 --- a/src/main/kotlin/RepositoryImpl/AdminServiceImpl.kt +++ b/src/main/kotlin/RepositoryImpl/AdminServiceImpl.kt @@ -1,7 +1,7 @@ package RepositoryImpl import Interface.AdminService -import model.User +import data.features.authorize.model.User class AdminServiceImpl : AdminService { private val users = mutableListOf() diff --git a/src/main/kotlin/data/features/authorize/AuthorizeRepository.kt b/src/main/kotlin/data/features/authorize/AuthorizeRepository.kt new file mode 100644 index 0000000..62114c8 --- /dev/null +++ b/src/main/kotlin/data/features/authorize/AuthorizeRepository.kt @@ -0,0 +1,10 @@ +package data.features.authorize + +import domain.request.AuthorizeRequest +import domain.request.RegistrationRequest +import domain.response.UserPesponse + +interface AuthorizeRepository { + fun auth(authorizeRequest: AuthorizeRequest): UserPesponse + fun registration(registrationRequest: RegistrationRequest): UserPesponse +} \ No newline at end of file diff --git a/src/main/kotlin/data/features/authorize/AuthorizeRepositoryImpl.kt b/src/main/kotlin/data/features/authorize/AuthorizeRepositoryImpl.kt new file mode 100644 index 0000000..61d8304 --- /dev/null +++ b/src/main/kotlin/data/features/authorize/AuthorizeRepositoryImpl.kt @@ -0,0 +1,77 @@ +package org.example.data.admin + +import data.features.authorize.model.User +import domain.request.AuthorizeRequest +import domain.request.RegistrationRequest +import domain.response.UserPesponse +import io.github.serpro69.kfaker.Faker +import java.util.* + +data class LocalUser( + val uuid: UUID, + var lastname: String, + var firstname: String? = null, + var email: String, + var photo: String? = null, + var password: String, + var number: String? = null, + var address: String? = null +) +val users = generateUsers(100).toMutableList() +fun generateUsers(userCount: Int): List{ + val localUserList = mutableListOf() + val faker = Faker() + repeat(userCount){ + localUserList.add( + LocalUser( + uuid = UUID.randomUUID(), + lastname = faker.name.lastName(), + firstname = faker.name.firstName(), + email = faker.random.randomString(3)+"@mail.ru", + photo= faker.random.randomString(10), + password = faker.random.randomString(8), + number = faker.phoneNumber.phoneNumber(), + address = faker.address.fullAddress() + ) + ) + + } + return localUserList +} + +fun auth(authorizeRequest: AuthorizeRequest): User { + val findUser = users.firstOrNull { it.email == authorizeRequest.email } + checkNotNull(findUser) { + "Пользователь не найден" + } + return if (findUser.password == authorizeRequest.password) User( + uuid = findUser.uuid, + firstname = findUser.firstname ?: "", + lastname = findUser.lastname, + email = findUser.email, + photo = findUser.photo ?: "", + number = findUser.number, + address = findUser.address + ) + else throw IllegalArgumentException("Пароли не совпадают") +} + +fun registration(registrationRequest: RegistrationRequest): User { + val user = LocalUser( + uuid = UUID.randomUUID(), + lastname = registrationRequest.lastname, + email = registrationRequest.email, + password = registrationRequest.password + ) + + users.add(user) + return User( + uuid = user.uuid, + firstname = user.firstname ?: "", + lastname = user.lastname, + email = user.email, + photo = user.photo ?: "", + number = user.number, + address = user.address + ) +} \ No newline at end of file diff --git a/src/main/kotlin/data/features/authorize/model/User.kt b/src/main/kotlin/data/features/authorize/model/User.kt new file mode 100644 index 0000000..8df0c52 --- /dev/null +++ b/src/main/kotlin/data/features/authorize/model/User.kt @@ -0,0 +1,18 @@ +package data.features.authorize.model + +import java.time.LocalDate +import java.util.UUID + +open class User( + val uuid: UUID, + val firstname: String, + val lastname: String?, + var email: String, + var number: String?, + var address: String?, + var photo: String +) + + + + diff --git a/src/main/kotlin/domain/request/AuthorizeRequest.kt b/src/main/kotlin/domain/request/AuthorizeRequest.kt new file mode 100644 index 0000000..84b547b --- /dev/null +++ b/src/main/kotlin/domain/request/AuthorizeRequest.kt @@ -0,0 +1,5 @@ +package domain.request + +data class AuthorizeRequest( + val email: String, + val password: String,) diff --git a/src/main/kotlin/domain/request/RegistrationRequest.kt b/src/main/kotlin/domain/request/RegistrationRequest.kt new file mode 100644 index 0000000..8b38b3b --- /dev/null +++ b/src/main/kotlin/domain/request/RegistrationRequest.kt @@ -0,0 +1,6 @@ +package domain.request + +data class RegistrationRequest ( + val lastname: String, + val email: String, + val password: String,) \ No newline at end of file diff --git a/src/main/kotlin/domain/response/UserPesponse.kt b/src/main/kotlin/domain/response/UserPesponse.kt new file mode 100644 index 0000000..361873d --- /dev/null +++ b/src/main/kotlin/domain/response/UserPesponse.kt @@ -0,0 +1,11 @@ +package domain.response + + + +data class UserPesponse( + val firstname:String?, + val lastname: String?, + val email: String, + val number: String?, + val adress: String?, + val photo: String?) diff --git a/src/main/kotlin/model/AdminUser.kt b/src/main/kotlin/model/AdminUser.kt deleted file mode 100644 index 12fe212..0000000 --- a/src/main/kotlin/model/AdminUser.kt +++ /dev/null @@ -1,14 +0,0 @@ -package model - -import java.time.LocalDate - -class AdminUser( - userId: Int, - login: String, - password: String, - lastAuthorizeDate: LocalDate, - email: String, - phone: String -) : User(userId, login, password, lastAuthorizeDate, email, phone) { - override val role: String = "администратор" -} diff --git a/src/main/kotlin/model/DefaultUser.kt b/src/main/kotlin/model/DefaultUser.kt deleted file mode 100644 index 411174f..0000000 --- a/src/main/kotlin/model/DefaultUser.kt +++ /dev/null @@ -1,14 +0,0 @@ -package model - -import java.time.LocalDate - -class DefaultUser( - userId: Int, - login: String, - password: String, - lastAuthorizeDate: LocalDate, - email: String, - phone: String -) : User(userId, login, password, lastAuthorizeDate, email, phone) { - override val role: String = "пользователь" -} \ No newline at end of file diff --git a/src/main/kotlin/model/ManagerUser.kt b/src/main/kotlin/model/ManagerUser.kt deleted file mode 100644 index 1e1f6fc..0000000 --- a/src/main/kotlin/model/ManagerUser.kt +++ /dev/null @@ -1,14 +0,0 @@ -package model - -import java.time.LocalDate - -class ManagerUser( - userId: Int, - login: String, - password: String, - lastAuthorizeDate: LocalDate, - email: String, - phone: String -) : User(userId, login, password, lastAuthorizeDate, email, phone) { - override val role: String = "менеджер" -} \ No newline at end of file diff --git a/src/main/kotlin/model/User.kt b/src/main/kotlin/model/User.kt deleted file mode 100644 index 9761be8..0000000 --- a/src/main/kotlin/model/User.kt +++ /dev/null @@ -1,16 +0,0 @@ -package model - -import java.time.LocalDate - -open class User( - val userId: Int, - val login: String, - var password: String, - var lastAuthorizeDate: LocalDate, - var email: String, - var phone: String -) { open val role: String = "пользователь" } - - - -