Compare commits

..

No commits in common. "ea2321d8af84792e5ee2a612348eba06422ce900" and "7e66b88679a0f203697452944dc5e105c0854bd9" have entirely different histories.

13 changed files with 24 additions and 114 deletions

View File

@ -1,15 +1,18 @@
package org.example
import org.example.data.UserRepository
import org.example.data.UserRepositoryImpl
import org.example.domain.UserUseCaseImpl
import org.example.ui.MainMenuUI
import org.example.ui.UserUI
//class_student
//localuser - где нет rtk
//844SystemUser
fun main() {
val userRepository = UserRepositoryImpl()
val userUseCase = UserUseCaseImpl(userRepository)
val userUI = UserUI(userUseCase)
userUI.authorize()
userUI.changePassword()
userUI.authorize()
val mainMenuUI = MainMenuUI(userUI)
mainMenuUI.displayStartMenu()
}

View File

@ -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
}

View File

@ -1,10 +1,7 @@
package org.example.data
import org.example.data.model.ShoesDTO
interface ShoesRepository {
fun addShoes()
fun removeShoes()
fun getAllShoes()
fun getShoesById()
fun removeShoes()
}

View File

@ -1,7 +1,18 @@
package org.example.data
import org.example.data.model.ShoesDTO
import org.example.data.model.UserDTO
val shoesList = listOf(
ShoesDTO(
shoesId = 1,
shoesName = "1",
shoesDescription = "123",
shoesUrl = "3",
category = "123"
)
)
val userList = listOf(
UserDTO(
userId = 1,

View File

@ -1,5 +0,0 @@
package org.example.data.model
//data class BucketDTO(
//
//)

View File

@ -1,6 +0,0 @@
package org.example.data.model
data class FavouriteDTO(
val userId: Int,
val shoesID: Int
)

View File

@ -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()
}
}

View File

@ -1,18 +1,12 @@
package org.example.domain
import org.example.data.FavouriteRepository
import org.example.data.ShoesRepository
import org.example.data.UserRepository
import org.example.domain.request.AuthorizeRequest
import org.example.domain.request.ChangePasswordRequest
import org.example.domain.request.RegistrationRequest
import org.example.domain.response.UserResponse
class UserUseCaseImpl(
private val userRepository: UserRepository,
private val favouriteRepository: FavouriteRepository,
private val shoesRepository: ShoesRepository
): UserUseCase {
class UserUseCaseImpl(private val userRepository: UserRepository): UserUseCase {
override fun authorize(authorizeRequest: AuthorizeRequest): UserResponse {
val findUser = userRepository.getAllUsers()
.firstOrNull {
@ -24,9 +18,7 @@ class UserUseCaseImpl(
require(findUser.password == authorizeRequest.password){
"Пароли не совпадают"
}
val favourite = favouriteRepository.getFavouritesByUserId(userID = findUser.userId)
val shoesFavourite = shoesRepository.getAllShoes().filter { it.shoesId in favourite}
return userDtoToUserResponse(findUser, shoesFavourite)
return UserDtoToUserResponse(findUser)
}
override fun registration(registrationRequest: RegistrationRequest): UserResponse {
@ -38,7 +30,7 @@ class UserUseCaseImpl(
"Такая почта уже существует"
}
val newUser = userRepository.addUser(registrationRequest)
return userDtoToUserResponse(newUser)
return UserDtoToUserResponse(newUser)
}
override fun changePassword(changePasswordRequest: ChangePasswordRequest) {

View File

@ -1,26 +1,13 @@
package org.example.domain
import org.example.data.model.ShoesDTO
import org.example.data.model.UserDTO
import org.example.domain.response.ShoesResponse
import org.example.domain.response.UserResponse
fun userDtoToUserResponse(userDTO: UserDTO, shoesList: List<ShoesDTO> = emptyList()) = UserResponse(
fun UserDtoToUserResponse(userDTO: UserDTO) = UserResponse(
lastName = userDTO.lastName,
firstName = userDTO.firstName,
email = userDTO.email,
phone = userDTO.phone,
userId = userDTO.userId,
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
)
}
)

View File

@ -1,3 +0,0 @@
package org.example.domain.request
data class AddFavouriteRequest(val userID:Int, val shoesID: Int)

View File

@ -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"
}
}

View File

@ -1,7 +1,5 @@
package org.example.domain.response
import org.example.data.model.ShoesDTO
data class UserResponse(
val userId: Int,
var firstName: String,
@ -9,5 +7,4 @@ data class UserResponse(
var email: String,
var phone: String? = null,
var address: String? = null,
var favouriteList: List<ShoesResponse> = emptyList()
)

View File

@ -89,16 +89,6 @@ class UserUI(private val userUseCase: UserUseCase) {
printOutput.appendLine()
printOutput.append("Ваш адрес ${userResponse.phone}")
}
if(!userResponse.favouriteList.isEmpty()){
printOutput.appendLine()
printOutput.append(
userResponse.favouriteList
.map { it.toString() }
.joinToString("\n")
)
}
return printOutput.toString()
}
}