fixes
This commit is contained in:
parent
ca3c675988
commit
e4b8fb9a5f
@ -4,18 +4,18 @@
|
||||
<value>
|
||||
<entry key="app">
|
||||
<State>
|
||||
<runningDeviceTargetSelectedWithDropDown>
|
||||
<targetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="RUNNING_DEVICE_TARGET" />
|
||||
<type value="QUICK_BOOT_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="SERIAL_NUMBER" />
|
||||
<value value="5l55mnq48hlndua6" />
|
||||
<type value="VIRTUAL_DEVICE_PATH" />
|
||||
<value value="$USER_HOME$/.android/avd/Pixel_7_API_33.avd" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</runningDeviceTargetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2023-12-15T06:33:52.521291494Z" />
|
||||
</targetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2023-12-20T08:37:35.519292927Z" />
|
||||
</State>
|
||||
</entry>
|
||||
</value>
|
||||
|
@ -23,7 +23,7 @@ interface MyServerService {
|
||||
@Query("pageSize") limit: Int,
|
||||
): List<UserRemote>
|
||||
|
||||
@GET("user/{id}/")
|
||||
@GET("user/{id}")
|
||||
suspend fun getUser(
|
||||
@Path("id") id: Int,
|
||||
): UserRemote
|
||||
@ -39,13 +39,13 @@ interface MyServerService {
|
||||
@Body user: UserRemote,
|
||||
): UserRemote
|
||||
|
||||
@PUT("user/{id}/")
|
||||
@PUT("user/{id}")
|
||||
suspend fun updateUser(
|
||||
@Path("id") id: Int,
|
||||
@Body user: UserRemote,
|
||||
): UserRemote
|
||||
|
||||
@DELETE("user/{id}/")
|
||||
@DELETE("user/{id}")
|
||||
suspend fun deleteUser(
|
||||
@Path("id") id: Int,
|
||||
): UserRemote
|
||||
@ -56,7 +56,7 @@ interface MyServerService {
|
||||
@Query("pageSize") limit: Int,
|
||||
): List<CoffeeRemote>
|
||||
|
||||
@GET("coffee/{id}/")
|
||||
@GET("coffee/{id}")
|
||||
suspend fun getCoffee(
|
||||
@Path("id") id: Int,
|
||||
): CoffeeRemote
|
||||
@ -66,19 +66,19 @@ interface MyServerService {
|
||||
@Body coffee: CoffeeRemote,
|
||||
): CoffeeRemote
|
||||
|
||||
@PUT("coffee/{id}/")
|
||||
@PUT("coffee/{id}")
|
||||
suspend fun updateCoffee(
|
||||
@Path("id") id: Int,
|
||||
@Body coffee: CoffeeRemote,
|
||||
): CoffeeRemote
|
||||
|
||||
@DELETE("coffee/{id}/")
|
||||
@DELETE("coffee/{id}")
|
||||
suspend fun deleteCoffee(
|
||||
@Path("id") id: Int,
|
||||
): CoffeeRemote
|
||||
|
||||
companion object {
|
||||
private const val BASE_URL = "http://192.168.42.48:8080/api/"
|
||||
private const val BASE_URL = "http://192.168.0.100:8080/api/"
|
||||
|
||||
@Volatile
|
||||
private var INSTANCE: MyServerService? = null
|
||||
|
@ -44,18 +44,18 @@ class RestUserRepository(
|
||||
}
|
||||
|
||||
override suspend fun getByUid(uid: Int): User =
|
||||
service.getUser(uid).toUser()
|
||||
service.getUser(uid).toUser()!!
|
||||
|
||||
override suspend fun tryLogin(login: String, password: String): User =
|
||||
override suspend fun tryLogin(login: String, password: String): User? =
|
||||
service.tryLogin(login, password).toUser()
|
||||
|
||||
|
||||
override suspend fun insert(user: User): Long {
|
||||
return service.createUser(user.toUserRemote()).toUser().uid.toLong()
|
||||
return service.createUser(user.toUserRemote()).toUser()?.uid?.toLong()!!
|
||||
}
|
||||
|
||||
override suspend fun update(user: User): Int {
|
||||
return service.updateUser(user.uid, user.toUserRemote()).toUser().uid
|
||||
return service.updateUser(user.uid, user.toUserRemote()).toUser()?.uid!!
|
||||
}
|
||||
|
||||
override suspend fun delete(user: User) {
|
||||
|
@ -8,6 +8,7 @@ import com.zyzf.coffeepreorder.CoffeeApplication
|
||||
import com.zyzf.coffeepreorder.ui.cart.CartViewModel
|
||||
import com.zyzf.coffeepreorder.ui.coffee.CoffeeListViewModel
|
||||
import com.zyzf.coffeepreorder.ui.login.LoginViewModel
|
||||
import com.zyzf.coffeepreorder.ui.profile.ProfileViewModel
|
||||
import com.zyzf.coffeepreorder.ui.register.RegisterViewModel
|
||||
|
||||
object AppViewModelProvider {
|
||||
@ -24,6 +25,9 @@ object AppViewModelProvider {
|
||||
initializer {
|
||||
RegisterViewModel(coffeeApplication().container.userRestRepository)
|
||||
}
|
||||
initializer {
|
||||
ProfileViewModel(coffeeApplication().container.userRestRepository)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@ fun CoffeeList(
|
||||
},
|
||||
onEditClick = { currentCoffee: Coffee, context: Context ->
|
||||
coroutineScope.launch {
|
||||
viewModel.editCoffee(currentCoffee, imageUri as Uri, context)
|
||||
viewModel.editCoffee(currentCoffee, imageUri, context)
|
||||
}
|
||||
},
|
||||
onDeleteClick = { currentCoffee: Coffee ->
|
||||
|
@ -52,8 +52,9 @@ class CoffeeListViewModel(
|
||||
|
||||
copyFileToSftp(f, "/mnt/nextcloud/data/Zyzf/files/Images")
|
||||
}
|
||||
suspend fun editCoffee(coffee: Coffee, imageUri: Uri, context: Context) {
|
||||
suspend fun editCoffee(coffee: Coffee, imageUri: Any?, context: Context) {
|
||||
val editedCoffee: Int = coffeeRepository.update(coffee)
|
||||
if (imageUri !is Uri) return
|
||||
val inputStream = context.contentResolver.openInputStream(imageUri)
|
||||
val bitmap = BitmapFactory.decodeStream(inputStream)
|
||||
|
||||
|
@ -8,6 +8,11 @@ class LoginViewModel(
|
||||
private val userRepository: UserRepository
|
||||
) : ViewModel() {
|
||||
suspend fun tryLogin(login: String, password: String): User? {
|
||||
return userRepository.tryLogin(login, password)
|
||||
val user: User? = userRepository.tryLogin(login, password)
|
||||
return if (user?.uid == 0) {
|
||||
null
|
||||
} else {
|
||||
user
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
@ -39,13 +40,17 @@ import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavController
|
||||
import com.zyzf.coffeepreorder.CoffeeApplication
|
||||
import com.zyzf.coffeepreorder.R
|
||||
import com.zyzf.coffeepreorder.database.AppDatabase
|
||||
import com.zyzf.coffeepreorder.database.model.User
|
||||
import com.zyzf.coffeepreorder.ui.AppViewModelProvider
|
||||
import com.zyzf.coffeepreorder.ui.login.LoginViewModel
|
||||
import com.zyzf.coffeepreorder.ui.navigation.Screen
|
||||
import com.zyzf.coffeepreorder.ui.theme.CoffeePreorderTheme
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
@ -54,10 +59,14 @@ import kotlinx.coroutines.withContext
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
@Composable
|
||||
fun Profile(navController: NavController?) {
|
||||
fun Profile(
|
||||
navController: NavController?,
|
||||
viewModel: ProfileViewModel = viewModel(factory = AppViewModelProvider.Factory)
|
||||
) {
|
||||
val openDialogEdit = remember { mutableStateOf(false) }
|
||||
val openDialogExit = remember { mutableStateOf(false) }
|
||||
val openDialogDelete = remember { mutableStateOf(false) }
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val context = LocalContext.current
|
||||
var user: User by remember { mutableStateOf(User("", "", "", "", "")) }
|
||||
var userLogin by remember { mutableStateOf("") }
|
||||
@ -193,13 +202,10 @@ fun Profile(navController: NavController?) {
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
GlobalScope.launch (Dispatchers.Main) {
|
||||
if (userOldPsswd.value == user.password && userNewPsswd.value == userNewPsswdConf.value) {
|
||||
val userUid: Int? = AppDatabase.getInstance(context).userDao().update(User(
|
||||
user.uid, userLogin, userFIO, userPhone, userNewPsswd.value, user.role))
|
||||
user = AppDatabase.getInstance(context).userDao().getByUid(userUid!!)!!
|
||||
CoffeeApplication.currentUser = user
|
||||
}
|
||||
coroutineScope.launch {
|
||||
val user: User = viewModel.changeUser(user.password, userOldPsswd.value, userNewPsswd.value, userNewPsswd.value,
|
||||
user.uid, userLogin, userFIO, userPhone, user.role)
|
||||
CoffeeApplication.currentUser = user
|
||||
}
|
||||
openDialogEdit.value = false
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
package com.zyzf.coffeepreorder.ui.profile
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.zyzf.coffeepreorder.CoffeeApplication
|
||||
import com.zyzf.coffeepreorder.database.AppDatabase
|
||||
import com.zyzf.coffeepreorder.database.model.User
|
||||
import com.zyzf.coffeepreorder.database.repository.UserRepository
|
||||
|
||||
class ProfileViewModel(
|
||||
private val userRepository: UserRepository
|
||||
) : ViewModel() {
|
||||
suspend fun changeUser(currentUserPassw: String,
|
||||
userOldPsswd: String,
|
||||
userNewPsswd: String,
|
||||
userNewPsswdConf: String,
|
||||
userUid: Int,
|
||||
userLogin: String,
|
||||
userFIO: String,
|
||||
userPhone: String,
|
||||
userRole: String): User {
|
||||
if (userOldPsswd == currentUserPassw && userNewPsswd == userNewPsswdConf) {
|
||||
val userUid: Int? = userRepository.update(User(
|
||||
userUid, userLogin, userFIO, userPhone, userNewPsswd, userRole))
|
||||
} else {
|
||||
val userUid: Int? = userRepository.update(User(
|
||||
userUid, userLogin, userFIO, userPhone, currentUserPassw, userRole))
|
||||
}
|
||||
return userRepository.getByUid(userUid!!)!!
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<network-security-config>
|
||||
<domain-config cleartextTrafficPermitted="true">
|
||||
<domain includeSubdomains="true">192.168.42.48</domain>
|
||||
<domain includeSubdomains="true">192.168.0.100</domain>
|
||||
</domain-config>
|
||||
</network-security-config>
|
@ -2,6 +2,7 @@ package com.kalyshev.yan.coffee.service;
|
||||
|
||||
import com.kalyshev.yan.coffee.controller.CoffeeDto;
|
||||
import com.kalyshev.yan.coffee.model.Coffee;
|
||||
import com.kalyshev.yan.coffee.repository.CoffeeNotFoundException;
|
||||
import com.kalyshev.yan.coffee.repository.CoffeeRepository;
|
||||
import com.kalyshev.yan.user.repository.UserNotFoundException;
|
||||
import com.kalyshev.yan.util.validation.ValidatorUtil;
|
||||
@ -40,7 +41,7 @@ public class CoffeeService {
|
||||
@Transactional(readOnly = true)
|
||||
public Coffee findCoffee(Long id) {
|
||||
final Optional<Coffee> coffee = coffeeRepository.findById(id);
|
||||
return coffee.orElseThrow(() -> new UserNotFoundException(id));
|
||||
return coffee.orElseThrow(() -> new CoffeeNotFoundException(id));
|
||||
}
|
||||
@Transactional(readOnly = true)
|
||||
public List<CoffeeDto> findAllCoffees(int pageNo, int pageSize, String sortBy, String sortDir) {
|
||||
|
@ -30,7 +30,7 @@ public class UserController {
|
||||
return userService.findAllUsers(pageNo, pageSize, sortBy, sortDir);
|
||||
}
|
||||
@GetMapping("/tryLogin")
|
||||
public Optional<User> tryLogin(
|
||||
public User tryLogin(
|
||||
@RequestParam(value = "login") String login,
|
||||
@RequestParam(value = "password") String password
|
||||
){
|
||||
|
@ -27,6 +27,14 @@ public class User {
|
||||
this.password = password;
|
||||
this.role = role;
|
||||
}
|
||||
public User(Long id, String login, String fio, String phone, String password, String role) {
|
||||
this.id = id;
|
||||
this.login = login;
|
||||
this.fio = fio;
|
||||
this.phone = phone;
|
||||
this.password = password;
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.kalyshev.yan.user.service;
|
||||
|
||||
import com.kalyshev.yan.coffee.repository.CoffeeNotFoundException;
|
||||
import com.kalyshev.yan.user.controller.UserDto;
|
||||
import com.kalyshev.yan.user.model.User;
|
||||
import com.kalyshev.yan.user.repository.UserNotFoundException;
|
||||
@ -52,8 +53,14 @@ public class UserService {
|
||||
return user.orElseThrow(() -> new UserNotFoundException(id));
|
||||
}
|
||||
@Transactional(readOnly = true)
|
||||
public Optional<User> tryLogin(String login, String password) {
|
||||
return userRepository.tryLogin(login, password);
|
||||
public User tryLogin(String login, String password) {
|
||||
Optional<User> user = userRepository.tryLogin(login, password);
|
||||
if (user.isPresent()) {
|
||||
return user.orElseThrow((() -> new UserNotFoundException((long)0))) ;
|
||||
} else {
|
||||
return new User((long)0,"", "", "", "", "");
|
||||
}
|
||||
|
||||
}
|
||||
@Transactional(readOnly = true)
|
||||
public List<UserDto> findAllUsers(int pageNo, int pageSize, String sortBy, String sortDir) {
|
||||
|
Loading…
Reference in New Issue
Block a user