Compare commits
2 Commits
7e66b88679
...
ea2321d8af
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ea2321d8af | ||
![]() |
e387f25273 |
@ -1,18 +1,15 @@
|
|||||||
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)
|
||||||
val mainMenuUI = MainMenuUI(userUI)
|
userUI.authorize()
|
||||||
mainMenuUI.displayStartMenu()
|
userUI.changePassword()
|
||||||
|
userUI.authorize()
|
||||||
}
|
}
|
10
src/main/kotlin/data/FavouriteRepository.kt
Normal file
10
src/main/kotlin/data/FavouriteRepository.kt
Normal 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
|
||||||
|
}
|
@ -1,7 +1,10 @@
|
|||||||
package org.example.data
|
package org.example.data
|
||||||
|
|
||||||
|
import org.example.data.model.ShoesDTO
|
||||||
|
|
||||||
interface ShoesRepository {
|
interface ShoesRepository {
|
||||||
fun addShoes()
|
fun addShoes()
|
||||||
fun getAllShoes()
|
|
||||||
fun removeShoes()
|
fun removeShoes()
|
||||||
|
fun getAllShoes()
|
||||||
|
fun getShoesById()
|
||||||
}
|
}
|
@ -1,18 +1,7 @@
|
|||||||
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,
|
||||||
|
5
src/main/kotlin/data/model/BucketDTO.kt
Normal file
5
src/main/kotlin/data/model/BucketDTO.kt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package org.example.data.model
|
||||||
|
|
||||||
|
//data class BucketDTO(
|
||||||
|
//
|
||||||
|
//)
|
6
src/main/kotlin/data/model/FavouriteDTO.kt
Normal file
6
src/main/kotlin/data/model/FavouriteDTO.kt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package org.example.data.model
|
||||||
|
|
||||||
|
data class FavouriteDTO(
|
||||||
|
val userId: Int,
|
||||||
|
val shoesID: Int
|
||||||
|
)
|
27
src/main/kotlin/data/model/FavouriteRepositoryImpl.kt
Normal file
27
src/main/kotlin/data/model/FavouriteRepositoryImpl.kt
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,18 @@
|
|||||||
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(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 {
|
override fun authorize(authorizeRequest: AuthorizeRequest): UserResponse {
|
||||||
val findUser = userRepository.getAllUsers()
|
val findUser = userRepository.getAllUsers()
|
||||||
.firstOrNull {
|
.firstOrNull {
|
||||||
@ -18,7 +24,9 @@ class UserUseCaseImpl(private val userRepository: UserRepository): UserUseCase {
|
|||||||
require(findUser.password == authorizeRequest.password){
|
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 {
|
override fun registration(registrationRequest: RegistrationRequest): UserResponse {
|
||||||
@ -30,7 +38,7 @@ class UserUseCaseImpl(private val userRepository: UserRepository): UserUseCase {
|
|||||||
"Такая почта уже существует"
|
"Такая почта уже существует"
|
||||||
}
|
}
|
||||||
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,13 +1,26 @@
|
|||||||
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) = UserResponse(
|
fun userDtoToUserResponse(userDTO: UserDTO, shoesList: List<ShoesDTO> = emptyList()) = 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
|
||||||
|
)
|
||||||
|
}
|
3
src/main/kotlin/domain/request/AddFavouriteRequest.kt
Normal file
3
src/main/kotlin/domain/request/AddFavouriteRequest.kt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package org.example.domain.request
|
||||||
|
|
||||||
|
data class AddFavouriteRequest(val userID:Int, val shoesID: Int)
|
16
src/main/kotlin/domain/response/ShoesResponse.kt
Normal file
16
src/main/kotlin/domain/response/ShoesResponse.kt
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
|||||||
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,
|
||||||
@ -7,4 +9,5 @@ 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,6 +89,16 @@ 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