fixed all bugs

This commit is contained in:
zyzf 2023-12-15 11:20:18 +04:00
parent cc6178a845
commit 042350ca59
20 changed files with 54 additions and 80 deletions

View File

@ -3,7 +3,20 @@
<component name="deploymentTargetDropDown"> <component name="deploymentTargetDropDown">
<value> <value>
<entry key="app"> <entry key="app">
<State /> <State>
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="5l55mnq48hlndua6" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-12-15T06:33:52.521291494Z" />
</State>
</entry> </entry>
</value> </value>
</component> </component>

View File

@ -1,41 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewApiLevelMustBeValid" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
</profile>
</component>

View File

@ -8,7 +8,7 @@
<uses-permission android:name="com.google.android.gms.persmission.AD_ID" /> <uses-permission android:name="com.google.android.gms.persmission.AD_ID" />
<application <application
android:name=".CoffeeApplication" android:name=".CoffeeApplication"
android:allowBackup="true" android:allowBackup="false"
android:dataExtractionRules="@xml/data_extraction_rules" android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules" android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"

View File

@ -29,18 +29,18 @@ interface MyServerService {
): UserRemote ): UserRemote
@GET("user/tryLogin") @GET("user/tryLogin")
fun tryLogin( suspend fun tryLogin(
@Query("login") login: String, @Query("login") login: String,
@Query("password") password: String, @Query("password") password: String
): UserRemote? ): UserRemote
@POST("user/") @POST("user/")
fun createUser( suspend fun createUser(
@Body user: UserRemote, @Body user: UserRemote,
): UserRemote ): UserRemote
@PUT("user/{id}/") @PUT("user/{id}/")
fun updateUser( suspend fun updateUser(
@Path("id") id: Int, @Path("id") id: Int,
@Body user: UserRemote, @Body user: UserRemote,
): UserRemote ): UserRemote
@ -62,12 +62,12 @@ interface MyServerService {
): CoffeeRemote ): CoffeeRemote
@POST("coffee/") @POST("coffee/")
fun createCoffee( suspend fun createCoffee(
@Body coffee: CoffeeRemote, @Body coffee: CoffeeRemote,
): CoffeeRemote ): CoffeeRemote
@PUT("coffee/{id}/") @PUT("coffee/{id}/")
fun updateCoffee( suspend fun updateCoffee(
@Path("id") id: Int, @Path("id") id: Int,
@Body coffee: CoffeeRemote, @Body coffee: CoffeeRemote,
): CoffeeRemote ): CoffeeRemote
@ -78,7 +78,7 @@ interface MyServerService {
): CoffeeRemote ): CoffeeRemote
companion object { companion object {
private const val BASE_URL = "http://192.168.0.100:8080/api/" private const val BASE_URL = "http://192.168.42.48:8080/api/"
@Volatile @Volatile
private var INSTANCE: MyServerService? = null private var INSTANCE: MyServerService? = null

View File

@ -46,11 +46,11 @@ class RestCoffeeRepository(
override suspend fun getByUid(uid: Int): Coffee = override suspend fun getByUid(uid: Int): Coffee =
service.getCoffee(uid).toCoffee() service.getCoffee(uid).toCoffee()
override fun insert(coffee: Coffee): Long { override suspend fun insert(coffee: Coffee): Long {
return service.createCoffee(coffee.toCoffeeRemote()).toCoffee().uid.toLong() return service.createCoffee(coffee.toCoffeeRemote()).toCoffee().uid.toLong()
} }
override fun update(coffee: Coffee): Int { override suspend fun update(coffee: Coffee): Int {
return service.updateCoffee(coffee.uid, coffee.toCoffeeRemote()).toCoffee().uid return service.updateCoffee(coffee.uid, coffee.toCoffeeRemote()).toCoffee().uid
} }

View File

@ -10,7 +10,7 @@ data class UserRemote(
val fio: String = "", val fio: String = "",
val phone: String = "", val phone: String = "",
val password: String = "", val password: String = "",
val role: String = "user" val role: String = ""
) )
fun UserRemote.toUser(): User = User( fun UserRemote.toUser(): User = User(

View File

@ -7,6 +7,7 @@ import androidx.paging.PagingConfig
import androidx.paging.PagingData import androidx.paging.PagingData
import com.zyzf.coffeepreorder.api.MyServerService import com.zyzf.coffeepreorder.api.MyServerService
import com.zyzf.coffeepreorder.api.coffee.CoffeeRemoteMediator import com.zyzf.coffeepreorder.api.coffee.CoffeeRemoteMediator
import com.zyzf.coffeepreorder.api.model.UserRemote
import com.zyzf.coffeepreorder.api.model.toCoffee import com.zyzf.coffeepreorder.api.model.toCoffee
import com.zyzf.coffeepreorder.api.model.toCoffeeRemote import com.zyzf.coffeepreorder.api.model.toCoffeeRemote
import com.zyzf.coffeepreorder.api.model.toUser import com.zyzf.coffeepreorder.api.model.toUser
@ -49,18 +50,18 @@ class RestUserRepository(
).flow ).flow
} }
override suspend fun getByUid(uid: Int): User? = override suspend fun getByUid(uid: Int): User =
service.getUser(uid).toUser() service.getUser(uid).toUser()
override fun tryLogin(login: String, password: String): User? = override suspend fun tryLogin(login: String, password: String): User =
service.tryLogin(login, password)?.toUser() service.tryLogin(login, password).toUser()
override fun insert(user: User): Long { override suspend fun insert(user: User): Long {
return service.createUser(user.toUserRemote()).toUser().uid.toLong() return service.createUser(user.toUserRemote()).toUser().uid.toLong()
} }
override fun update(user: User): Int? { 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
} }

View File

@ -17,10 +17,10 @@ interface CartDao {
@Query("select coffee.uid, coffee.name, coffee.cost, coffee.ingredients from cart join coffee on coffee.uid = cart.coffee_id and cart.count > 0 collate nocase") @Query("select coffee.uid, coffee.name, coffee.cost, coffee.ingredients from cart join coffee on coffee.uid = cart.coffee_id and cart.count > 0 collate nocase")
fun getAllInCart(): PagingSource<Int, Coffee> fun getAllInCart(): PagingSource<Int, Coffee>
@Query("select sum(coffee.cost) from cart JOIN coffee on coffee.uid = cart.coffee_id and cart.count > 0") @Query("select sum(coffee.cost * cart.count) from cart JOIN coffee on coffee.uid = cart.coffee_id and cart.count > 0")
fun getSumInCart(): Double fun getSumInCart(): Double
@Query("select coffee.cost from cart JOIN coffee on coffee.uid = cart.coffee_id where coffee.uid = :coffeeId") @Query("select cart.count from cart JOIN coffee on coffee.uid = cart.coffee_id where coffee.uid = :coffeeId")
fun getCountForCoffee(coffeeId: Int): Double fun getCountForCoffee(coffeeId: Int): Double
@Insert @Insert

View File

@ -17,7 +17,7 @@ interface UserDao {
fun getAll(): PagingSource<Int, User> fun getAll(): PagingSource<Int, User>
@Query("select * from user where login = :login and password = :password") @Query("select * from user where login = :login and password = :password")
fun tryLogin(login: String, password: String): User? suspend fun tryLogin(login: String, password: String): User?
@Query("select * from user where uid = :uid") @Query("select * from user where uid = :uid")
suspend fun getByUid(uid: Int): User? suspend fun getByUid(uid: Int): User?

View File

@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.Flow
interface CoffeeRepository { interface CoffeeRepository {
fun getAllCoffees(): Flow<PagingData<Coffee>> fun getAllCoffees(): Flow<PagingData<Coffee>>
suspend fun getByUid(uid: Int): Coffee? suspend fun getByUid(uid: Int): Coffee?
fun insert(coffee: Coffee): Long suspend fun insert(coffee: Coffee): Long
fun update(coffee: Coffee): Int suspend fun update(coffee: Coffee): Int
suspend fun delete(coffee: Coffee) suspend fun delete(coffee: Coffee)
} }

View File

@ -21,9 +21,9 @@ class OfflineCoffeeRepository(private val coffeeDao: CoffeeDao) : CoffeeReposito
fun getAllCoffeesPagingSource(): PagingSource<Int, Coffee> = coffeeDao.getAllCoffees() fun getAllCoffeesPagingSource(): PagingSource<Int, Coffee> = coffeeDao.getAllCoffees()
suspend fun clearCoffees() = coffeeDao.deleteAll() suspend fun clearCoffees() = coffeeDao.deleteAll()
override suspend fun getByUid(uid: Int): Coffee? = coffeeDao.getByUid(uid) override suspend fun getByUid(uid: Int): Coffee? = coffeeDao.getByUid(uid)
override fun insert(coffee: Coffee): Long = coffeeDao.insert(coffee) override suspend fun insert(coffee: Coffee): Long = coffeeDao.insert(coffee)
suspend fun insertCoffees(coffees: List<Coffee>) = suspend fun insertCoffees(coffees: List<Coffee>) =
coffeeDao.insert(*coffees.toTypedArray()) coffeeDao.insert(*coffees.toTypedArray())
override fun update(coffee: Coffee): Int = coffeeDao.update(coffee) override suspend fun update(coffee: Coffee): Int = coffeeDao.update(coffee)
override suspend fun delete(coffee: Coffee) = coffeeDao.delete(coffee) override suspend fun delete(coffee: Coffee) = coffeeDao.delete(coffee)
} }

View File

@ -20,11 +20,11 @@ class OfflineUserRepository(private val userDao: UserDao) : UserRepository {
).flow ).flow
fun getAllUserPagingSource(): PagingSource<Int, User> = userDao.getAll() fun getAllUserPagingSource(): PagingSource<Int, User> = userDao.getAll()
override suspend fun getByUid(uid: Int): User? = userDao.getByUid(uid) override suspend fun getByUid(uid: Int): User? = userDao.getByUid(uid)
override fun tryLogin(login: String, password: String): User? = userDao.tryLogin(login, password) override suspend fun tryLogin(login: String, password: String): User? = userDao.tryLogin(login, password)
override fun insert(user: User): Long = userDao.insert(user) override suspend fun insert(user: User): Long = userDao.insert(user)
fun insertUsers(users: List<User>) = fun insertUsers(users: List<User>) =
userDao.insert(*users.toTypedArray()) userDao.insert(*users.toTypedArray())
override fun update(user: User): Int? = userDao.update(user) override suspend fun update(user: User): Int? = userDao.update(user)
override suspend fun delete(user: User) = userDao.delete(user) override suspend fun delete(user: User) = userDao.delete(user)
suspend fun clearUsers() = userDao.deleteAll() suspend fun clearUsers() = userDao.deleteAll()
} }

View File

@ -7,8 +7,8 @@ import kotlinx.coroutines.flow.Flow
interface UserRepository { interface UserRepository {
fun getAll(): Flow<PagingData<User>> fun getAll(): Flow<PagingData<User>>
suspend fun getByUid(uid: Int): User? suspend fun getByUid(uid: Int): User?
fun tryLogin(login: String, password: String): User? suspend fun tryLogin(login: String, password: String): User?
fun insert(user: User): Long suspend fun insert(user: User): Long
fun update(user: User) : Int? suspend fun update(user: User) : Int?
suspend fun delete(user: User) suspend fun delete(user: User)
} }

View File

@ -8,7 +8,7 @@ import com.zyzf.coffeepreorder.database.repository.UserRepository
class LoginViewModel( class LoginViewModel(
private val userRepository: UserRepository private val userRepository: UserRepository
) : ViewModel() { ) : ViewModel() {
fun tryLogin(login: String, password: String): User? { suspend fun tryLogin(login: String, password: String): User? {
return userRepository.tryLogin(login, password) return userRepository.tryLogin(login, password)
} }
} }

View File

@ -8,7 +8,7 @@ import com.zyzf.coffeepreorder.database.repository.UserRepository
class RegisterViewModel( class RegisterViewModel(
private val userRepository: UserRepository private val userRepository: UserRepository
) : ViewModel() { ) : ViewModel() {
fun register(user: User): User? { suspend fun register(user: User): User? {
userRepository.insert(user) userRepository.insert(user)
return userRepository.tryLogin(user.login, user.password) return userRepository.tryLogin(user.login, user.password)
} }

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<network-security-config> <network-security-config>
<domain-config cleartextTrafficPermitted="true"> <domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">192.168.0.100</domain> <domain includeSubdomains="true">192.168.42.48</domain>
</domain-config> </domain-config>
</network-security-config> </network-security-config>

View File

@ -7,6 +7,7 @@ import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
import java.util.Optional;
@RestController @RestController
@RequestMapping(WebConfiguration.REST_API + "/user") @RequestMapping(WebConfiguration.REST_API + "/user")
@ -29,7 +30,7 @@ public class UserController {
return userService.findAllUsers(pageNo, pageSize, sortBy, sortDir); return userService.findAllUsers(pageNo, pageSize, sortBy, sortDir);
} }
@GetMapping("/tryLogin") @GetMapping("/tryLogin")
public User tryLogin( public Optional<User> tryLogin(
@RequestParam(value = "login") String login, @RequestParam(value = "login") String login,
@RequestParam(value = "password") String password @RequestParam(value = "password") String password
){ ){

View File

@ -8,7 +8,7 @@ import org.springframework.data.repository.query.Param;
import java.util.Optional; import java.util.Optional;
public interface UserRepository extends JpaRepository<User, Long> { public interface UserRepository extends JpaRepository<User, Long> {
@Query(value = "select * from user_u where \"LOGIN\" = :login and \"PASSWORD\" = :password", nativeQuery = true) @Query(value = "select * from \"USER_U\" where \"LOGIN\" = :login and \"PASSWORD\" = :password", nativeQuery = true)
public Optional<User> tryLogin(@Param("login") String login, public Optional<User> tryLogin(@Param("login") String login,
@Param("password") String password); @Param("password") String password);

View File

@ -52,9 +52,9 @@ public class UserService {
return user.orElseThrow(() -> new UserNotFoundException(id)); return user.orElseThrow(() -> new UserNotFoundException(id));
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
public User tryLogin(String login, String password) { public Optional<User> tryLogin(String login, String password) {
final Optional<User> user = userRepository.tryLogin(login, password); final Optional<User> user = userRepository.tryLogin(login, password);
return user.orElseThrow(() -> new UserNotFoundException((long)0)); return user;
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
public List<UserDto> findAllUsers(int pageNo, int pageSize, String sortBy, String sortDir) { public List<UserDto> findAllUsers(int pageNo, int pageSize, String sortBy, String sortDir) {

View File

@ -8,4 +8,4 @@ spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.ddl-auto=update
spring.h2.console.enabled=true spring.h2.console.enabled=true
spring.h2.console.settings.trace=false spring.h2.console.settings.trace=false
spring.h2.console.settings.web-allow-others=false spring.h2.console.settings.web-allow-others=true