some changes

This commit is contained in:
zyzf 2023-12-14 14:43:45 +04:00
parent ae769e167a
commit d2db976f34
7 changed files with 44 additions and 17 deletions

View File

@ -19,8 +19,8 @@ import retrofit2.http.Query
interface MyServerService {
@GET("user")
suspend fun getUsers(
@Query("_page") page: Int,
@Query("_limit") limit: Int,
@Query("pageNo") page: Int,
@Query("pageSize") limit: Int,
): List<UserRemote>
@GET("user/{id}")
@ -52,8 +52,8 @@ interface MyServerService {
@GET("coffee")
suspend fun getCoffees(
@Query("_page") page: Int,
@Query("_limit") limit: Int,
@Query("pageNo") page: Int,
@Query("pageSize") limit: Int,
): List<CoffeeRemote>
@GET("coffee/{id}")
@ -78,7 +78,7 @@ interface MyServerService {
): CoffeeRemote
companion object {
private const val BASE_URL = "http://10.120.175.105:8079/"
private const val BASE_URL = "http://192.168.42.94:8080/api/"
@Volatile
private var INSTANCE: MyServerService? = null

View File

@ -47,7 +47,7 @@ class RestCoffeeRepository(
service.getCoffee(uid).toCoffee()
override suspend fun insert(name: String, cost: Double, ingredients: String): Long {
return service.createCoffee(Coffee(name, cost, ingredients, null, 0).toCoffeeRemote()).toCoffee().uid.toLong()
return service.createCoffee(Coffee(name, cost, ingredients).toCoffeeRemote()).toCoffee().uid.toLong()
}
override suspend fun update(uid: Int, name: String, cost: Double, ingredients: String): Int? {

View File

@ -35,17 +35,17 @@ abstract class AppDatabase : RoomDatabase() {
userDao.insert(user1.login, user1.fio, user1.phone, user1.password, user1.role)
// Coffees
val coffeeDao = database.coffeeDao()
val coffee1 = Coffee("Coffee1", 200.0, "Ing1", null, 0)
val coffee2 = Coffee("Coffee2", 200.0, "Ing1", null, 0)
val coffee3 = Coffee("Coffee3", 300.0, "Ing1", null, 0)
val coffee4 = Coffee("Coffee4", 200.0, "Ing1", null, 0)
val coffee5 = Coffee("Coffee5", 200.0, "Ing1", null, 0)
val coffee6 = Coffee("Coffee6", 25.0, "Ing1", null, 0)
val coffee7 = Coffee("Coffee7", 400.0, "Ing1", null, 0)
val coffee8 = Coffee("Coffee8", 200.0, "Ing1", null, 0)
val coffee9 = Coffee("Coffee9", 200.0, "Ing1", null, 0)
val coffee10 = Coffee("Coffee10", 900.0, "Ing1", null, 0)
val coffee11 = Coffee("Coffee11", 200.0, "Ing1", null, 0)
val coffee1 = Coffee("Coffee1", 200.0, "Ing1")
val coffee2 = Coffee("Coffee2", 200.0, "Ing1")
val coffee3 = Coffee("Coffee3", 300.0, "Ing1")
val coffee4 = Coffee("Coffee4", 200.0, "Ing1")
val coffee5 = Coffee("Coffee5", 200.0, "Ing1")
val coffee6 = Coffee("Coffee6", 25.0, "Ing1")
val coffee7 = Coffee("Coffee7", 400.0, "Ing1")
val coffee8 = Coffee("Coffee8", 200.0, "Ing1")
val coffee9 = Coffee("Coffee9", 200.0, "Ing1")
val coffee10 = Coffee("Coffee10", 900.0, "Ing1")
val coffee11 = Coffee("Coffee11", 200.0, "Ing1")
coffeeDao.insert(coffee1.name, coffee1.cost, coffee1.ingredients)
coffeeDao.insert(coffee2.name, coffee2.cost, coffee2.ingredients)
coffeeDao.insert(coffee3.name, coffee3.cost, coffee3.ingredients)

View File

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

View File

@ -1,6 +1,7 @@
package com.kalyshev.yan.user.controller;
import com.kalyshev.yan.WebConfiguration;
import com.kalyshev.yan.user.model.User;
import com.kalyshev.yan.user.service.UserService;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
@ -25,6 +26,13 @@ public class UserController {
){
return userService.findAllUsers(pageNo, pageSize, sortBy, sortDir);
}
@GetMapping("/tryLogin")
public User tryLogin(
@RequestParam(value = "login") String login,
@RequestParam(value = "password") String password
){
return userService.tryLogin(login, password);
}
@PostMapping("/")
public UserDto createUser(@RequestBody @Valid UserDto userDto) {
return new UserDto(userService.addUser(userDto.getLogin(), userDto.getFio(), userDto.getPhone(), userDto.getPassword(), userDto.getRole()));

View File

@ -2,6 +2,14 @@ package com.kalyshev.yan.user.repository;
import com.kalyshev.yan.user.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.Optional;
public interface UserRepository extends JpaRepository<User, Long> {
@Query(value = "select * from user_u where \"LOGIN\" = :login and \"PASSWORD\" = :password", nativeQuery = true)
public Optional<User> tryLogin(@Param("login") String login,
@Param("password") String password);
}

View File

@ -53,6 +53,11 @@ public class UserService {
return user.orElseThrow(() -> new UserNotFoundException(id));
}
@Transactional(readOnly = true)
public User tryLogin(String login, String password) {
final Optional<User> user = userRepository.tryLogin(login, password);
return user.orElseThrow(() -> new UserNotFoundException((long)0));
}
@Transactional(readOnly = true)
public UserResponse findAllUsers(int pageNo, int pageSize, String sortBy, String sortDir) {
Sort sort = sortDir.equalsIgnoreCase(Sort.Direction.ASC.name()) ? Sort.by(sortBy).ascending()
: Sort.by(sortBy).descending();