Compare commits
No commits in common. "ea2321d8af84792e5ee2a612348eba06422ce900" and "7e66b88679a0f203697452944dc5e105c0854bd9" have entirely different histories.
ea2321d8af
...
7e66b88679
@ -1,15 +1,18 @@
|
|||||||
package org.example
|
package org.example
|
||||||
|
|
||||||
import org.example.data.UserRepository
|
|
||||||
import org.example.data.UserRepositoryImpl
|
import org.example.data.UserRepositoryImpl
|
||||||
import org.example.domain.UserUseCaseImpl
|
import org.example.domain.UserUseCaseImpl
|
||||||
|
import org.example.ui.MainMenuUI
|
||||||
import org.example.ui.UserUI
|
import org.example.ui.UserUI
|
||||||
|
|
||||||
|
|
||||||
|
//class_student
|
||||||
|
//localuser - где нет rtk
|
||||||
|
//844SystemUser
|
||||||
fun main() {
|
fun main() {
|
||||||
val userRepository = UserRepositoryImpl()
|
val userRepository = UserRepositoryImpl()
|
||||||
val userUseCase = UserUseCaseImpl(userRepository)
|
val userUseCase = UserUseCaseImpl(userRepository)
|
||||||
val userUI = UserUI(userUseCase)
|
val userUI = UserUI(userUseCase)
|
||||||
userUI.authorize()
|
val mainMenuUI = MainMenuUI(userUI)
|
||||||
userUI.changePassword()
|
mainMenuUI.displayStartMenu()
|
||||||
userUI.authorize()
|
|
||||||
}
|
}
|
@ -1,10 +0,0 @@
|
|||||||
package org.example.data
|
|
||||||
|
|
||||||
import org.example.domain.request.AddFavouriteRequest
|
|
||||||
|
|
||||||
interface FavouriteRepository{
|
|
||||||
fun getAllFavourites()
|
|
||||||
fun addFavourites(vararg addFavouriteRequest: AddFavouriteRequest)
|
|
||||||
fun removeFavourites()
|
|
||||||
fun getFavouritesByUserId(userID: Int): IntArray
|
|
||||||
}
|
|
@ -1,10 +1,7 @@
|
|||||||
package org.example.data
|
package org.example.data
|
||||||
|
|
||||||
import org.example.data.model.ShoesDTO
|
|
||||||
|
|
||||||
interface ShoesRepository {
|
interface ShoesRepository {
|
||||||
fun addShoes()
|
fun addShoes()
|
||||||
fun removeShoes()
|
|
||||||
fun getAllShoes()
|
fun getAllShoes()
|
||||||
fun getShoesById()
|
fun removeShoes()
|
||||||
}
|
}
|
@ -1,7 +1,18 @@
|
|||||||
package org.example.data
|
package org.example.data
|
||||||
|
|
||||||
|
import org.example.data.model.ShoesDTO
|
||||||
import org.example.data.model.UserDTO
|
import org.example.data.model.UserDTO
|
||||||
|
|
||||||
|
val shoesList = listOf(
|
||||||
|
ShoesDTO(
|
||||||
|
shoesId = 1,
|
||||||
|
shoesName = "1",
|
||||||
|
shoesDescription = "123",
|
||||||
|
shoesUrl = "3",
|
||||||
|
category = "123"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
val userList = listOf(
|
val userList = listOf(
|
||||||
UserDTO(
|
UserDTO(
|
||||||
userId = 1,
|
userId = 1,
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
package org.example.data.model
|
|
||||||
|
|
||||||
//data class BucketDTO(
|
|
||||||
//
|
|
||||||
//)
|
|
@ -1,6 +0,0 @@
|
|||||||
package org.example.data.model
|
|
||||||
|
|
||||||
data class FavouriteDTO(
|
|
||||||
val userId: Int,
|
|
||||||
val shoesID: Int
|
|
||||||
)
|
|
@ -1,27 +0,0 @@
|
|||||||
package org.example.data.model
|
|
||||||
|
|
||||||
import org.example.data.FavouriteRepository
|
|
||||||
import org.example.data.favouriteListSource
|
|
||||||
import org.example.domain.request.AddFavouriteRequest
|
|
||||||
|
|
||||||
class FavouriteRepositoryImpl: FavouriteRepository {
|
|
||||||
val favouriteList = favouriteListSource.toMutableList()
|
|
||||||
override fun getAllFavourites() {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun addFavourites(vararg addFavouriteRequest: AddFavouriteRequest) {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun removeFavourites() {
|
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getFavouritesByUserId(userID: Int): IntArray {
|
|
||||||
return favouriteList
|
|
||||||
.filter { it.userId == userID }
|
|
||||||
.map { it.shoesID }
|
|
||||||
.toIntArray()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +1,12 @@
|
|||||||
package org.example.domain
|
package org.example.domain
|
||||||
|
|
||||||
import org.example.data.FavouriteRepository
|
|
||||||
import org.example.data.ShoesRepository
|
|
||||||
import org.example.data.UserRepository
|
import org.example.data.UserRepository
|
||||||
import org.example.domain.request.AuthorizeRequest
|
import org.example.domain.request.AuthorizeRequest
|
||||||
import org.example.domain.request.ChangePasswordRequest
|
import org.example.domain.request.ChangePasswordRequest
|
||||||
import org.example.domain.request.RegistrationRequest
|
import org.example.domain.request.RegistrationRequest
|
||||||
import org.example.domain.response.UserResponse
|
import org.example.domain.response.UserResponse
|
||||||
|
|
||||||
class UserUseCaseImpl(
|
class UserUseCaseImpl(private val userRepository: UserRepository): UserUseCase {
|
||||||
private val userRepository: UserRepository,
|
|
||||||
private val favouriteRepository: FavouriteRepository,
|
|
||||||
private val shoesRepository: ShoesRepository
|
|
||||||
): UserUseCase {
|
|
||||||
override fun authorize(authorizeRequest: AuthorizeRequest): UserResponse {
|
override fun authorize(authorizeRequest: AuthorizeRequest): UserResponse {
|
||||||
val findUser = userRepository.getAllUsers()
|
val findUser = userRepository.getAllUsers()
|
||||||
.firstOrNull {
|
.firstOrNull {
|
||||||
@ -24,9 +18,7 @@ class UserUseCaseImpl(
|
|||||||
require(findUser.password == authorizeRequest.password){
|
require(findUser.password == authorizeRequest.password){
|
||||||
"Пароли не совпадают"
|
"Пароли не совпадают"
|
||||||
}
|
}
|
||||||
val favourite = favouriteRepository.getFavouritesByUserId(userID = findUser.userId)
|
return UserDtoToUserResponse(findUser)
|
||||||
val shoesFavourite = shoesRepository.getAllShoes().filter { it.shoesId in favourite}
|
|
||||||
return userDtoToUserResponse(findUser, shoesFavourite)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun registration(registrationRequest: RegistrationRequest): UserResponse {
|
override fun registration(registrationRequest: RegistrationRequest): UserResponse {
|
||||||
@ -38,7 +30,7 @@ class UserUseCaseImpl(
|
|||||||
"Такая почта уже существует"
|
"Такая почта уже существует"
|
||||||
}
|
}
|
||||||
val newUser = userRepository.addUser(registrationRequest)
|
val newUser = userRepository.addUser(registrationRequest)
|
||||||
return userDtoToUserResponse(newUser)
|
return UserDtoToUserResponse(newUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun changePassword(changePasswordRequest: ChangePasswordRequest) {
|
override fun changePassword(changePasswordRequest: ChangePasswordRequest) {
|
||||||
|
@ -1,26 +1,13 @@
|
|||||||
package org.example.domain
|
package org.example.domain
|
||||||
|
|
||||||
import org.example.data.model.ShoesDTO
|
|
||||||
import org.example.data.model.UserDTO
|
import org.example.data.model.UserDTO
|
||||||
import org.example.domain.response.ShoesResponse
|
|
||||||
import org.example.domain.response.UserResponse
|
import org.example.domain.response.UserResponse
|
||||||
|
|
||||||
fun userDtoToUserResponse(userDTO: UserDTO, shoesList: List<ShoesDTO> = emptyList()) = UserResponse(
|
fun UserDtoToUserResponse(userDTO: UserDTO) = UserResponse(
|
||||||
lastName = userDTO.lastName,
|
lastName = userDTO.lastName,
|
||||||
firstName = userDTO.firstName,
|
firstName = userDTO.firstName,
|
||||||
email = userDTO.email,
|
email = userDTO.email,
|
||||||
phone = userDTO.phone,
|
phone = userDTO.phone,
|
||||||
userId = userDTO.userId,
|
userId = userDTO.userId,
|
||||||
address = userDTO.address,
|
address = userDTO.address,
|
||||||
favouriteList = shoesList.map(::shoesDtoToUserResponse)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
fun shoesDtoToUserResponse(shoesDTO: ShoesDTO): ShoesResponse{
|
|
||||||
return ShoesResponse(
|
|
||||||
shoesId = shoesDTO.shoesId,
|
|
||||||
shoesName = shoesDTO.shoesName,
|
|
||||||
shoesUrl = shoesDTO.shoesUrl,
|
|
||||||
shoesDescription = shoesDTO.shoesDescription,
|
|
||||||
category = shoesDTO.category
|
|
||||||
)
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
package org.example.domain.request
|
|
||||||
|
|
||||||
data class AddFavouriteRequest(val userID:Int, val shoesID: Int)
|
|
@ -1,16 +0,0 @@
|
|||||||
package org.example.domain.response
|
|
||||||
|
|
||||||
data class ShoesResponse(
|
|
||||||
val shoesId: Int,
|
|
||||||
val shoesName: String,
|
|
||||||
val shoesDescription: String,
|
|
||||||
val shoesUrl: String,
|
|
||||||
val category: String,
|
|
||||||
)
|
|
||||||
{
|
|
||||||
override fun toString(): String {
|
|
||||||
return "name: $shoesName\nshoes: $shoesDescription"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
|||||||
package org.example.domain.response
|
package org.example.domain.response
|
||||||
|
|
||||||
import org.example.data.model.ShoesDTO
|
|
||||||
|
|
||||||
data class UserResponse(
|
data class UserResponse(
|
||||||
val userId: Int,
|
val userId: Int,
|
||||||
var firstName: String,
|
var firstName: String,
|
||||||
@ -9,5 +7,4 @@ data class UserResponse(
|
|||||||
var email: String,
|
var email: String,
|
||||||
var phone: String? = null,
|
var phone: String? = null,
|
||||||
var address: String? = null,
|
var address: String? = null,
|
||||||
var favouriteList: List<ShoesResponse> = emptyList()
|
|
||||||
)
|
)
|
||||||
|
@ -89,16 +89,6 @@ class UserUI(private val userUseCase: UserUseCase) {
|
|||||||
printOutput.appendLine()
|
printOutput.appendLine()
|
||||||
printOutput.append("Ваш адрес ${userResponse.phone}")
|
printOutput.append("Ваш адрес ${userResponse.phone}")
|
||||||
}
|
}
|
||||||
if(!userResponse.favouriteList.isEmpty()){
|
|
||||||
printOutput.appendLine()
|
|
||||||
printOutput.append(
|
|
||||||
userResponse.favouriteList
|
|
||||||
.map { it.toString() }
|
|
||||||
.joinToString("\n")
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
|
||||||
return printOutput.toString()
|
return printOutput.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user