init commit
This commit is contained in:
parent
de9ddfd0bb
commit
16ca0e8cf3
@ -10,6 +10,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation("io.github.serpro69:kotlin-faker:2.0.0-rc.7")
|
||||||
testImplementation(kotlin("test"))
|
testImplementation(kotlin("test"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package Interface
|
package Interface
|
||||||
|
|
||||||
import model.User
|
import data.features.authorize.model.User
|
||||||
|
|
||||||
interface AdminService {
|
interface AdminService {
|
||||||
fun removeUserById(userId: Int): Boolean
|
fun removeUserById(userId: Int): Boolean
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package Interface
|
package Interface
|
||||||
|
|
||||||
import model.User
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Interface AuthorizeService {
|
Interface AuthorizeService {
|
||||||
fun registration(user: User):Boolean
|
fun registration(user: User):Boolean
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package RepositoryImpl
|
package RepositoryImpl
|
||||||
|
|
||||||
import Interface.AdminService
|
import Interface.AdminService
|
||||||
import model.User
|
import data.features.authorize.model.User
|
||||||
|
|
||||||
class AdminServiceImpl : AdminService {
|
class AdminServiceImpl : AdminService {
|
||||||
private val users = mutableListOf<User>()
|
private val users = mutableListOf<User>()
|
||||||
|
@ -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
|
||||||
|
}
|
@ -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<LocalUser>{
|
||||||
|
val localUserList = mutableListOf<LocalUser>()
|
||||||
|
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
|
||||||
|
)
|
||||||
|
}
|
18
src/main/kotlin/data/features/authorize/model/User.kt
Normal file
18
src/main/kotlin/data/features/authorize/model/User.kt
Normal file
@ -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
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
5
src/main/kotlin/domain/request/AuthorizeRequest.kt
Normal file
5
src/main/kotlin/domain/request/AuthorizeRequest.kt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package domain.request
|
||||||
|
|
||||||
|
data class AuthorizeRequest(
|
||||||
|
val email: String,
|
||||||
|
val password: String,)
|
6
src/main/kotlin/domain/request/RegistrationRequest.kt
Normal file
6
src/main/kotlin/domain/request/RegistrationRequest.kt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package domain.request
|
||||||
|
|
||||||
|
data class RegistrationRequest (
|
||||||
|
val lastname: String,
|
||||||
|
val email: String,
|
||||||
|
val password: String,)
|
11
src/main/kotlin/domain/response/UserPesponse.kt
Normal file
11
src/main/kotlin/domain/response/UserPesponse.kt
Normal file
@ -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?)
|
@ -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 = "администратор"
|
|
||||||
}
|
|
@ -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 = "пользователь"
|
|
||||||
}
|
|
@ -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 = "менеджер"
|
|
||||||
}
|
|
@ -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 = "пользователь" }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user