Compare commits

...

2 Commits

Author SHA1 Message Date
KP9lKk
ea2321d8af Merge remote-tracking branch 'origin/master'
# Conflicts:
#	src/main/kotlin/Main.kt
#	src/main/kotlin/data/ShoesRepository.kt
#	src/main/kotlin/data/ShoesRepositoryImpl.kt
#	src/main/kotlin/data/localDataSource.kt
2025-02-06 12:37:14 +03:00
KP9lKk
e387f25273 add shoes 2025-02-06 12:35:06 +03:00
13 changed files with 114 additions and 24 deletions

View File

@ -1,18 +1,15 @@
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)
val mainMenuUI = MainMenuUI(userUI)
mainMenuUI.displayStartMenu()
userUI.authorize()
userUI.changePassword()
userUI.authorize()
}

View File

@ -0,0 +1,10 @@
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,7 +1,10 @@
package org.example.data
import org.example.data.model.ShoesDTO
interface ShoesRepository {
fun addShoes()
fun getAllShoes()
fun removeShoes()
fun getAllShoes()
fun getShoesById()
}

View File

@ -1,18 +1,7 @@
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

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

View File

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

View File

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

View File

@ -1,13 +1,26 @@
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) = UserResponse(
fun userDtoToUserResponse(userDTO: UserDTO, shoesList: List<ShoesDTO> = emptyList()) = 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

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

View File

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

View File

@ -89,6 +89,16 @@ 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()
}
}