fixed warnings

This commit is contained in:
zyzf 2023-12-15 11:48:20 +04:00
parent acd37136b0
commit d3fde20a0a
32 changed files with 35 additions and 457 deletions

View File

@ -3,7 +3,6 @@ package com.zyzf.coffeepreorder
import android.app.Application import android.app.Application
import com.zyzf.coffeepreorder.database.AppContainer import com.zyzf.coffeepreorder.database.AppContainer
import com.zyzf.coffeepreorder.database.AppDataContainer import com.zyzf.coffeepreorder.database.AppDataContainer
import com.zyzf.coffeepreorder.database.model.Coffee
import com.zyzf.coffeepreorder.database.model.User import com.zyzf.coffeepreorder.database.model.User
class CoffeeApplication : Application() { class CoffeeApplication : Application() {

View File

@ -1,15 +1,12 @@
package com.zyzf.coffeepreorder package com.zyzf.coffeepreorder
import android.content.res.Configuration
import android.os.Bundle import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.zyzf.coffeepreorder.ui.navigation.MainNavbar import com.zyzf.coffeepreorder.ui.navigation.MainNavbar
import com.zyzf.coffeepreorder.ui.theme.CoffeePreorderTheme import com.zyzf.coffeepreorder.ui.theme.CoffeePreorderTheme

View File

@ -6,18 +6,11 @@ import androidx.paging.Pager
import androidx.paging.PagingConfig 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.model.UserRemote
import com.zyzf.coffeepreorder.api.model.toCoffee
import com.zyzf.coffeepreorder.api.model.toCoffeeRemote
import com.zyzf.coffeepreorder.api.model.toUser import com.zyzf.coffeepreorder.api.model.toUser
import com.zyzf.coffeepreorder.api.model.toUserRemote import com.zyzf.coffeepreorder.api.model.toUserRemote
import com.zyzf.coffeepreorder.database.AppContainer import com.zyzf.coffeepreorder.database.AppContainer
import com.zyzf.coffeepreorder.database.AppDatabase import com.zyzf.coffeepreorder.database.AppDatabase
import com.zyzf.coffeepreorder.database.model.Coffee
import com.zyzf.coffeepreorder.database.model.User import com.zyzf.coffeepreorder.database.model.User
import com.zyzf.coffeepreorder.database.repository.CoffeeRepository
import com.zyzf.coffeepreorder.database.repository.OfflineCoffeeRepository
import com.zyzf.coffeepreorder.database.repository.OfflineRemoteKeyRepository import com.zyzf.coffeepreorder.database.repository.OfflineRemoteKeyRepository
import com.zyzf.coffeepreorder.database.repository.OfflineUserRepository import com.zyzf.coffeepreorder.database.repository.OfflineUserRepository
import com.zyzf.coffeepreorder.database.repository.UserRepository import com.zyzf.coffeepreorder.database.repository.UserRepository

View File

@ -6,14 +6,11 @@ import androidx.paging.PagingState
import androidx.paging.RemoteMediator import androidx.paging.RemoteMediator
import androidx.room.withTransaction import androidx.room.withTransaction
import com.zyzf.coffeepreorder.api.MyServerService import com.zyzf.coffeepreorder.api.MyServerService
import com.zyzf.coffeepreorder.api.model.toCoffee
import com.zyzf.coffeepreorder.api.model.toUser import com.zyzf.coffeepreorder.api.model.toUser
import com.zyzf.coffeepreorder.database.AppDatabase import com.zyzf.coffeepreorder.database.AppDatabase
import com.zyzf.coffeepreorder.database.model.Coffee
import com.zyzf.coffeepreorder.database.model.RemoteKeyType import com.zyzf.coffeepreorder.database.model.RemoteKeyType
import com.zyzf.coffeepreorder.database.model.RemoteKeys import com.zyzf.coffeepreorder.database.model.RemoteKeys
import com.zyzf.coffeepreorder.database.model.User import com.zyzf.coffeepreorder.database.model.User
import com.zyzf.coffeepreorder.database.repository.OfflineCoffeeRepository
import com.zyzf.coffeepreorder.database.repository.OfflineRemoteKeyRepository import com.zyzf.coffeepreorder.database.repository.OfflineRemoteKeyRepository
import com.zyzf.coffeepreorder.database.repository.OfflineUserRepository import com.zyzf.coffeepreorder.database.repository.OfflineUserRepository
import retrofit2.HttpException import retrofit2.HttpException

View File

@ -6,10 +6,7 @@ import androidx.room.Delete
import androidx.room.Insert import androidx.room.Insert
import androidx.room.Query import androidx.room.Query
import androidx.room.Update import androidx.room.Update
import com.zyzf.coffeepreorder.api.user.RestUserRepository
import com.zyzf.coffeepreorder.database.model.Coffee
import com.zyzf.coffeepreorder.database.model.User import com.zyzf.coffeepreorder.database.model.User
import kotlinx.coroutines.flow.Flow
@Dao @Dao
interface UserDao { interface UserDao {

View File

@ -35,8 +35,7 @@ data class Cart(
other as Cart other as Cart
if (uid != other.uid) return false if (uid != other.uid) return false
if (coffeeId != other.coffeeId) return false if (coffeeId != other.coffeeId) return false
if (count != other.count) return false return count == other.count
return true
} }
override fun hashCode(): Int { override fun hashCode(): Int {

View File

@ -41,8 +41,7 @@ data class Coffee(
if (uid != other.uid) return false if (uid != other.uid) return false
if (name != other.name) return false if (name != other.name) return false
if (cost != other.cost) return false if (cost != other.cost) return false
if (ingredients != other.ingredients) return false return ingredients == other.ingredients
return true
} }
override fun hashCode(): Int { override fun hashCode(): Int {

View File

@ -51,8 +51,7 @@ data class User(
if (fio != other.fio) return false if (fio != other.fio) return false
if (phone != other.phone) return false if (phone != other.phone) return false
if (password != other.password) return false if (password != other.password) return false
if (role != other.role) return false return role == other.role
return true
} }
override fun hashCode(): Int { override fun hashCode(): Int {

View File

@ -6,7 +6,6 @@ import androidx.paging.PagingData
import androidx.paging.PagingSource import androidx.paging.PagingSource
import com.zyzf.coffeepreorder.database.AppContainer import com.zyzf.coffeepreorder.database.AppContainer
import com.zyzf.coffeepreorder.database.dao.UserDao import com.zyzf.coffeepreorder.database.dao.UserDao
import com.zyzf.coffeepreorder.database.model.Coffee
import com.zyzf.coffeepreorder.database.model.User import com.zyzf.coffeepreorder.database.model.User
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow

View File

@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
@ -96,7 +95,7 @@ fun Cart(
} }
) { innerPadding -> ) { innerPadding ->
Box (modifier = Modifier Box (modifier = Modifier
.padding(0.dp) .padding(innerPadding)
.pullRefresh(state)) { .pullRefresh(state)) {
PullRefreshIndicator(refreshing = refreshing, state = state, PullRefreshIndicator(refreshing = refreshing, state = state,
modifier = Modifier modifier = Modifier
@ -104,34 +103,27 @@ fun Cart(
.align(Alignment.TopCenter) .align(Alignment.TopCenter)
) )
CartList( CartList(
modifier = Modifier
.padding(innerPadding)
.pullRefresh(state)
.fillMaxSize(),
coffeeList = coffeeListUiState, coffeeList = coffeeListUiState,
onDeleteFromCartClick = {currentCoffee: Coffee -> onDeleteFromCartClick = {currentCoffee: Coffee ->
coffee.value = currentCoffee coffee.value = currentCoffee
openDialog.value = true openDialog.value = true
}, }
getCoffeeCount = {coffeeId: Int -> ) { coffeeId: Int ->
viewModel.getCountForCoffee(coffeeId) viewModel.getCountForCoffee(coffeeId)
} }
)
} }
} }
DeleteFromCartAlertDialog( DeleteFromCartAlertDialog(
openDialog = openDialog, openDialog = openDialog
onConfirmClick = { ) {
coroutineScope.launch { coroutineScope.launch {
viewModel.deleteCoffeeFromCart(coffee.value) viewModel.deleteCoffeeFromCart(coffee.value)
} }
} }
)
} }
@Composable @Composable
private fun CartList( private fun CartList(
modifier: Modifier = Modifier,
coffeeList: LazyPagingItems<Coffee>, coffeeList: LazyPagingItems<Coffee>,
onDeleteFromCartClick: (coffee: Coffee) -> Unit, onDeleteFromCartClick: (coffee: Coffee) -> Unit,
getCoffeeCount: (coffeeId: Int) -> Double getCoffeeCount: (coffeeId: Int) -> Double
@ -158,7 +150,6 @@ private fun CartList(
@Composable @Composable
private fun CartListItem ( private fun CartListItem (
coffee: Coffee, coffee: Coffee,
modifier: Modifier = Modifier,
onDeleteFromCartClick: (coffee: Coffee) -> Unit, onDeleteFromCartClick: (coffee: Coffee) -> Unit,
getCoffeeCount: (coffeeId: Int) -> Double getCoffeeCount: (coffeeId: Int) -> Double
) { ) {
@ -219,7 +210,6 @@ private fun CartListItem (
@Composable @Composable
private fun DeleteFromCartAlertDialog( private fun DeleteFromCartAlertDialog(
modifier: Modifier = Modifier,
openDialog: MutableState<Boolean>, openDialog: MutableState<Boolean>,
onConfirmClick: () -> Unit onConfirmClick: () -> Unit
) { ) {

View File

@ -15,7 +15,6 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
@ -131,27 +130,23 @@ fun CoffeeList(
} }
} }
) { innerPadding -> ) { innerPadding ->
Box (modifier = Modifier.padding(0.dp).pullRefresh(state)) { Box (modifier = Modifier.padding(innerPadding).pullRefresh(state)) {
PullRefreshIndicator(refreshing = refreshing, state = state, PullRefreshIndicator(refreshing = refreshing, state = state,
modifier = Modifier.zIndex(100f).align(Alignment.TopCenter) modifier = Modifier.zIndex(100f).align(Alignment.TopCenter)
) )
CoffeeList( CoffeeList(
modifier = Modifier
.padding(innerPadding)
.fillMaxSize(),
coffeeList = coffeeListUiState, coffeeList = coffeeListUiState,
onAddToCartClick = { coffeeUid: Int -> onAddToCartClick = { coffeeUid: Int ->
coroutineScope.launch { coroutineScope.launch {
viewModel.addCoffeeToCart(coffeeUid = coffeeUid) viewModel.addCoffeeToCart(coffeeUid = coffeeUid)
} }
}, }
onEditClick = { currentCoffee: Coffee -> ) { currentCoffee: Coffee ->
coroutineScope.launch { coroutineScope.launch {
coffee.value = currentCoffee coffee.value = currentCoffee
openDialog.value = true openDialog.value = true
} }
} }
)
} }
} }
AddEditModalBottomSheet( AddEditModalBottomSheet(
@ -290,7 +285,6 @@ private fun AddEditModalBottomSheet(
@Composable @Composable
private fun CoffeeList( private fun CoffeeList(
modifier: Modifier = Modifier,
coffeeList: LazyPagingItems<Coffee>, coffeeList: LazyPagingItems<Coffee>,
onAddToCartClick: (coffeeUid: Int) -> Unit, onAddToCartClick: (coffeeUid: Int) -> Unit,
onEditClick: (coffee: Coffee) -> Unit onEditClick: (coffee: Coffee) -> Unit
@ -304,7 +298,11 @@ private fun CoffeeList(
) {index -> ) {index ->
val coffee = coffeeList[index] val coffee = coffeeList[index]
coffee?.let { coffee?.let {
CoffeeListItem(coffee = coffee, onAddToCartClick = onAddToCartClick, onEditClick = onEditClick) CoffeeListItem(
coffee = coffee,
onAddToCartClick = onAddToCartClick,
onEditClick = onEditClick
)
} }
} }
} }
@ -313,7 +311,6 @@ private fun CoffeeList(
@Composable @Composable
private fun CoffeeListItem( private fun CoffeeListItem(
coffee: Coffee, coffee: Coffee,
modifier: Modifier = Modifier,
onAddToCartClick: (coffeeUid: Int) -> Unit, onAddToCartClick: (coffeeUid: Int) -> Unit,
onEditClick: (coffee: Coffee) -> Unit onEditClick: (coffee: Coffee) -> Unit
) { ) {
@ -395,9 +392,8 @@ fun CoffeeListPreview() {
coffeeList = MutableStateFlow( coffeeList = MutableStateFlow(
PagingData.from((1..20).map { i -> Coffee.getCoffee(i) }) PagingData.from((1..20).map { i -> Coffee.getCoffee(i) })
).collectAsLazyPagingItems(), ).collectAsLazyPagingItems(),
onAddToCartClick = {}, onAddToCartClick = {}
onEditClick = {} ) {}
)
} }
} }
} }
@ -415,9 +411,8 @@ fun CoffeeEmptyListPreview() {
coffeeList = MutableStateFlow( coffeeList = MutableStateFlow(
PagingData.empty<Coffee>() PagingData.empty<Coffee>()
).collectAsLazyPagingItems(), ).collectAsLazyPagingItems(),
onAddToCartClick = {}, onAddToCartClick = {}
onEditClick = {} ) {}
)
} }
} }
} }

View File

@ -44,17 +44,13 @@ import com.zyzf.coffeepreorder.R
import com.zyzf.coffeepreorder.database.AppDatabase import com.zyzf.coffeepreorder.database.AppDatabase
import com.zyzf.coffeepreorder.database.model.User import com.zyzf.coffeepreorder.database.model.User
import com.zyzf.coffeepreorder.ui.AppViewModelProvider import com.zyzf.coffeepreorder.ui.AppViewModelProvider
import com.zyzf.coffeepreorder.ui.coffee.CoffeeListViewModel
import com.zyzf.coffeepreorder.ui.navigation.Screen import com.zyzf.coffeepreorder.ui.navigation.Screen
import com.zyzf.coffeepreorder.ui.theme.CoffeePreorderTheme import com.zyzf.coffeepreorder.ui.theme.CoffeePreorderTheme
import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@OptIn(DelicateCoroutinesApi::class)
@Composable @Composable
fun Login( fun Login(
navController: NavController?, navController: NavController?,

View File

@ -1,7 +1,6 @@
package com.zyzf.coffeepreorder.ui.login package com.zyzf.coffeepreorder.ui.login
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import com.zyzf.coffeepreorder.api.user.RestUserRepository
import com.zyzf.coffeepreorder.database.model.User import com.zyzf.coffeepreorder.database.model.User
import com.zyzf.coffeepreorder.database.repository.UserRepository import com.zyzf.coffeepreorder.database.repository.UserRepository

View File

@ -195,7 +195,8 @@ fun Profile(navController: NavController?) {
onClick = { onClick = {
GlobalScope.launch (Dispatchers.Main) { GlobalScope.launch (Dispatchers.Main) {
if (userOldPsswd.value == user.password && userNewPsswd.value == userNewPsswdConf.value) { 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)) 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!!)!! user = AppDatabase.getInstance(context).userDao().getByUid(userUid!!)!!
CoffeeApplication.currentUser = user CoffeeApplication.currentUser = user
} }

View File

@ -40,25 +40,19 @@ import coil.compose.AsyncImage
import coil.request.ImageRequest import coil.request.ImageRequest
import com.zyzf.coffeepreorder.CoffeeApplication import com.zyzf.coffeepreorder.CoffeeApplication
import com.zyzf.coffeepreorder.R import com.zyzf.coffeepreorder.R
import com.zyzf.coffeepreorder.database.AppDatabase
import com.zyzf.coffeepreorder.database.model.User import com.zyzf.coffeepreorder.database.model.User
import com.zyzf.coffeepreorder.ui.AppViewModelProvider 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.navigation.Screen
import com.zyzf.coffeepreorder.ui.theme.CoffeePreorderTheme import com.zyzf.coffeepreorder.ui.theme.CoffeePreorderTheme
import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@OptIn(DelicateCoroutinesApi::class)
@Composable @Composable
fun Register( fun Register(
navController: NavController?, navController: NavController?,
viewModel: RegisterViewModel = viewModel(factory = AppViewModelProvider.Factory) viewModel: RegisterViewModel = viewModel(factory = AppViewModelProvider.Factory)
) { ) {
val context = LocalContext.current
val coroutineScope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
var login: String by remember { mutableStateOf("") } var login: String by remember { mutableStateOf("") }
var fio: String by remember { mutableStateOf("") } var fio: String by remember { mutableStateOf("") }

View File

@ -1,7 +1,6 @@
package com.zyzf.coffeepreorder.ui.register package com.zyzf.coffeepreorder.ui.register
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import com.zyzf.coffeepreorder.database.AppDatabase
import com.zyzf.coffeepreorder.database.model.User import com.zyzf.coffeepreorder.database.model.User
import com.zyzf.coffeepreorder.database.repository.UserRepository import com.zyzf.coffeepreorder.database.repository.UserRepository

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

View File

@ -1,25 +0,0 @@
<!--
~ Copyright (C) 2023 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="100dp"
android:tint="#A9A9AC"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#A9A9AC"
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4c-1.48,0 -2.85,0.43 -4.01,1.17l1.46,1.46C10.21,6.23 11.08,6 12,6c3.04,0 5.5,2.46 5.5,5.5v0.5H19c1.66,0 3,1.34 3,3 0,1.13 -0.64,2.11 -1.56,2.62l1.45,1.45C23.16,18.16 24,16.68 24,15c0,-2.64 -2.05,-4.78 -4.65,-4.96zM3,5.27l2.75,2.74C2.56,8.15 0,10.77 0,14c0,3.31 2.69,6 6,6h11.73l2,2L21,20.73 4.27,4 3,5.27zM7.73,10l8,8H6c-2.21,0 -4,-1.79 -4,-4s1.79,-4 4,-4h1.73z" />
</vector>

View File

@ -1,10 +1,2 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources></resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>

View File

@ -8,7 +8,6 @@
<string name="coffee_name">Название</string> <string name="coffee_name">Название</string>
<string name="coffee_cost">Стоимость</string> <string name="coffee_cost">Стоимость</string>
<string name="coffee_ingredients">Ингредиенты</string> <string name="coffee_ingredients">Ингредиенты</string>
<string name="coffee_view_title">Изменить кофе</string>
<string name="profile_title">Профиль</string> <string name="profile_title">Профиль</string>
<string name="profile_login_label">Логин</string> <string name="profile_login_label">Логин</string>
@ -19,17 +18,4 @@
<string name="profile_newpassw_label">Новый пароль</string> <string name="profile_newpassw_label">Новый пароль</string>
<string name="profile_confpassw_label">Подтверждение пароля</string> <string name="profile_confpassw_label">Подтверждение пароля</string>
<string name="student_firstname">Имя</string>
<string name="student_lastname">Фамилия</string>
<string name="student_group">Группа</string>
<string name="student_phone">Телефон</string>
<string name="student_email">e-mail</string>
<string name="student_main_title">Список студентов</string>
<string name="student_view_title">Профиль студента</string>
<string name="about_title">О нас</string>
<string name="about_text">
<p>Это текст <b>о нас</b>!</p>\n\n
<p>Здесь могла быть Ваша реклама!</p>\n\n
<p>Наш сайт <a href="https://ulstu.ru">ulstu.ru</a></p>
</string>
</resources> </resources>

View File

@ -6,7 +6,6 @@ plugins {
group = 'com.kalyshev' group = 'com.kalyshev'
version = '0.0.1-SNAPSHOT' version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories { repositories {
mavenCentral() mavenCentral()
@ -28,3 +27,5 @@ dependencies {
tasks.named('test') { tasks.named('test') {
useJUnitPlatform() useJUnitPlatform()
} }
java.targetCompatibility = JavaVersion.VERSION_17

View File

@ -2,7 +2,6 @@ package com.kalyshev.yan.coffee.controller;
import com.kalyshev.yan.WebConfiguration; import com.kalyshev.yan.WebConfiguration;
import com.kalyshev.yan.coffee.service.CoffeeService; import com.kalyshev.yan.coffee.service.CoffeeService;
import com.kalyshev.yan.user.model.User;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;

View File

@ -1,8 +1,6 @@
package com.kalyshev.yan.coffee.controller; package com.kalyshev.yan.coffee.controller;
import com.kalyshev.yan.coffee.model.Coffee; import com.kalyshev.yan.coffee.model.Coffee;
import lombok.Getter;
import lombok.Setter;
public class CoffeeDto { public class CoffeeDto {
private Long id; private Long id;

View File

@ -4,8 +4,6 @@ import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
import java.util.Objects; import java.util.Objects;

View File

@ -3,7 +3,6 @@ package com.kalyshev.yan.coffee.service;
import com.kalyshev.yan.coffee.controller.CoffeeDto; import com.kalyshev.yan.coffee.controller.CoffeeDto;
import com.kalyshev.yan.coffee.model.Coffee; import com.kalyshev.yan.coffee.model.Coffee;
import com.kalyshev.yan.coffee.repository.CoffeeRepository; import com.kalyshev.yan.coffee.repository.CoffeeRepository;
import com.kalyshev.yan.user.model.User;
import com.kalyshev.yan.user.repository.UserNotFoundException; import com.kalyshev.yan.user.repository.UserNotFoundException;
import com.kalyshev.yan.util.validation.ValidatorUtil; import com.kalyshev.yan.util.validation.ValidatorUtil;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;

View File

@ -1,8 +1,6 @@
package com.kalyshev.yan.user.controller; package com.kalyshev.yan.user.controller;
import com.kalyshev.yan.user.model.User; import com.kalyshev.yan.user.model.User;
import lombok.Getter;
import lombok.Setter;
public class UserDto { public class UserDto {
private Long id; private Long id;

View File

@ -4,8 +4,6 @@ import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
import java.util.Objects; import java.util.Objects;

View File

@ -53,8 +53,7 @@ public class UserService {
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
public Optional<User> tryLogin(String login, String password) { public Optional<User> tryLogin(String login, String password) {
final Optional<User> user = userRepository.tryLogin(login, password); return userRepository.tryLogin(login, password);
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) {
@ -69,11 +68,9 @@ public class UserService {
// get content for page object // get content for page object
List<User> listOfUsers = users.getContent(); List<User> listOfUsers = users.getContent();
List<UserDto> content = listOfUsers.stream() return listOfUsers.stream()
.map(UserDto::new) .map(UserDto::new)
.toList(); .toList();
return content;
} }
@Transactional @Transactional
public User updateUser(Long id, String login, String fio, String phone, String password, String role) { public User updateUser(Long id, String login, String fio, String phone, String password, String role) {

View File

@ -1,64 +0,0 @@
package com.kalyshev.yan;
import com.kalyshev.yan.cabinet.model.Cabinet;
import com.kalyshev.yan.cabinet.repository.CabinetNotFoundException;
import com.kalyshev.yan.cabinet.service.CabinetService;
import com.kalyshev.yan.computer.service.ComputerService;
import com.kalyshev.yan.monitor.service.MonitorService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest
public class JpaCabinetTests {
private static final Logger log = LoggerFactory.getLogger(JpaCabinetTests.class);
@Autowired
private ComputerService computerService;
@Autowired
private MonitorService monitorService;
@Autowired
private CabinetService cabinetService;
@Test
void testCabinetCreate() {
cabinetService.deleteAllCabinets();
final Cabinet cabinet = cabinetService.addCabinet("18");
log.info(cabinet.toString());
Assertions.assertNotNull(cabinet.getId());
}
@Test
void testCabinetRead() {
cabinetService.deleteAllCabinets();
final Cabinet cabinet = cabinetService.addCabinet("18");
log.info(cabinet.toString());
final Cabinet findCabinet = cabinetService.findCabinet(cabinet.getId());
log.info(findCabinet.toString());
Assertions.assertEquals(cabinet, findCabinet);
}
@Test
void testCabinetReadNotFound() {
cabinetService.deleteAllCabinets();
Assertions.assertThrows(CabinetNotFoundException.class, () -> cabinetService.findCabinet(-1L));
}
@Test
void testCabinetReadAll() {
cabinetService.deleteAllCabinets();
cabinetService.addCabinet("18");
cabinetService.addCabinet("19");
final List<Cabinet> cabinets = cabinetService.findAllCabinets();
log.info(cabinets.toString());
Assertions.assertEquals(cabinets.size(), 2);
}
@Test
void testComputerReadAllEmpty() {
cabinetService.deleteAllCabinets();
final List<Cabinet> cabinets = cabinetService.findAllCabinets();
log.info(cabinets.toString());
Assertions.assertEquals(cabinets.size(), 0);
}
}

View File

@ -1,85 +0,0 @@
package com.kalyshev.yan;
import com.kalyshev.yan.cabinet.model.Cabinet;
import com.kalyshev.yan.cabinet.service.CabinetService;
import com.kalyshev.yan.computer.model.Computer;
import com.kalyshev.yan.computer.service.ComputerService;
import com.kalyshev.yan.monitor.model.Monitor;
import com.kalyshev.yan.monitor.service.MonitorService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class JpaComputerCabinetTests {
private static final Logger log = LoggerFactory.getLogger(JpaCabinetTests.class);
@Autowired
private ComputerService computerService;
@Autowired
private MonitorService monitorService;
@Autowired
private CabinetService cabinetService;
@Test
void testCabinetAddOneToMany() {
cabinetService.deleteAllCabinets();
computerService.deleteAllComputers();
computerService.deleteAllMonitorsWithRelations();
final Cabinet cabinet = cabinetService.addCabinet("18");
final Monitor monitor = monitorService.addMonitor("Asus");
final Computer computer = computerService.addComputer("PC", "78457h", monitor.getId());
cabinet.addComputer(computer);
log.info(cabinet.toString());
log.info(computer.toString());
Assertions.assertEquals(cabinet.getComputers().get(0).getSerialNum(), computer.getSerialNum());
}
@Test
void testCabinetDeleteOneToMany() {
cabinetService.deleteAllCabinets();
computerService.deleteAllComputers();
computerService.deleteAllMonitorsWithRelations();
final Cabinet cabinet = cabinetService.addCabinet("18");
final Monitor monitor = monitorService.addMonitor("Asus");
final Computer computer = computerService.addComputer("PC", "78457h", monitor.getId());
cabinet.addComputer(computer);
log.info(cabinet.toString());
log.info(computer.toString());
Assertions.assertEquals(cabinet.getComputers().get(0).getSerialNum(), computer.getSerialNum());
cabinet.removeComputer(computer);
Assertions.assertEquals(cabinet.getComputers().size(), 0);
}
@Test
void testComputerAddManyToMany() {
cabinetService.deleteAllCabinets();
computerService.deleteAllComputers();
computerService.deleteAllMonitorsWithRelations();
final Cabinet cabinet = cabinetService.addCabinet("18");
final Monitor monitor = monitorService.addMonitor("Asus");
final Computer computer = computerService.addComputer("PC", "78457h", monitor.getId());
computer.setCabinet(cabinet);
log.info(cabinet.toString());
log.info(computer.toString());
Assertions.assertEquals(computer.getCabinet().getNumber(), cabinet.getNumber());
}
@Test
void testComputerDeleteManyToMany() {
cabinetService.deleteAllCabinets();
computerService.deleteAllComputers();
computerService.deleteAllMonitorsWithRelations();
final Cabinet cabinet = cabinetService.addCabinet("18");
final Monitor monitor = monitorService.addMonitor("Asus");
final Computer computer = computerService.addComputer("PC", "78457h", monitor.getId());
computer.setCabinet(cabinet);
log.info(cabinet.toString());
log.info(computer.toString());
Assertions.assertEquals(computer.getCabinet().getNumber(), cabinet.getNumber());
computer.setCabinet(null);
Assertions.assertNull(computer.getCabinet());
}
}

View File

@ -1,89 +0,0 @@
package com.kalyshev.yan;
import com.kalyshev.yan.cabinet.model.Cabinet;
import com.kalyshev.yan.cabinet.service.CabinetService;
import com.kalyshev.yan.computer.model.Computer;
import com.kalyshev.yan.computer.repository.ComputerNotFoundException;
import com.kalyshev.yan.computer.service.ComputerService;
import com.kalyshev.yan.monitor.model.Monitor;
import com.kalyshev.yan.monitor.service.MonitorService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest
public class JpaComputerTests {
private static final Logger log = LoggerFactory.getLogger(JpaComputerTests.class);
@Autowired
private ComputerService computerService;
@Autowired
private MonitorService monitorService;
@Autowired
private CabinetService cabinetService;
@Test
void testComputerPartialCreate() {
computerService.deleteAllComputers();
final Monitor monitor = monitorService.addMonitor("Asus");
final Computer computer = computerService.addComputer("Computer", "w7894572", monitor.getId());
log.info(computer.toString());
Assertions.assertNotNull(computer.getId());
Assertions.assertNull(computer.getCabinet());
}
@Test
void testComputerFullCreate() {
computerService.deleteAllComputers();
final Monitor monitor = monitorService.addMonitor("Asus");
final Cabinet cabinet = cabinetService.addCabinet("18a");
final Computer computer = computerService.addComputer("Computer", "w7894572", monitor.getId());
computer.setCabinet(cabinet);
log.info(computer.toString());
Assertions.assertNotNull(computer.getId());
Assertions.assertEquals(cabinet, computer.getCabinet());
}
@Test
void testComputerDelete() {
computerService.deleteAllComputers();
final Monitor monitor = monitorService.addMonitor("Asus");
final Computer computer = computerService.addComputer("Computer", "w7894572", null);
log.info(computer.toString());
computerService.deleteComputer(computer.getId());
Assertions.assertThrows(ComputerNotFoundException.class, () -> computerService.findComputer(computer.getId()));
}
@Test
void testComputerRead() {
computerService.deleteAllComputers();
final Computer computer = computerService.addComputer("Computer", "w7894572", null);
log.info(computer.toString());
final Computer findComputer = computerService.findComputer(computer.getId());
log.info(findComputer.toString());
Assertions.assertEquals(computer, findComputer);
}
@Test
void testComputerReadNotFound() {
computerService.deleteAllComputers();
Assertions.assertThrows(ComputerNotFoundException.class, () -> computerService.findComputer(-1L));
}
@Test
void testComputerReadAll() {
computerService.deleteAllComputers();
final Monitor monitor = monitorService.addMonitor("Asus");
computerService.addComputer("Computer", "w7894572", null);
computerService.addComputer("Another comp", "3453s", null);
final List<Computer> computers = computerService.findAllComputers();
log.info(computers.toString());
Assertions.assertEquals(computers.size(), 2);
}
@Test
void testComputerReadAllEmpty() {
computerService.deleteAllComputers();
final List<Computer> computers = computerService.findAllComputers();
log.info(computers.toString());
Assertions.assertEquals(computers.size(), 0);
}
}

View File

@ -1,78 +0,0 @@
package com.kalyshev.yan;
import com.kalyshev.yan.computer.model.Computer;
import com.kalyshev.yan.computer.service.ComputerService;
import com.kalyshev.yan.monitor.model.Monitor;
import com.kalyshev.yan.monitor.repository.MonitorNotFoundException;
import com.kalyshev.yan.monitor.service.MonitorService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest
public class JpaMonitorTests {
private static final Logger log = LoggerFactory.getLogger(JpaMonitorTests.class);
@Autowired
private MonitorService monitorService;
@Autowired
private ComputerService computerService;
@Test
void testMonitorCreate() {
computerService.deleteAllMonitorsWithRelations();
final Monitor monitor = monitorService.addMonitor("Asus");
log.info(monitor.toString());
Assertions.assertNotNull(monitor.getId());
}
@Test
void testMonitorRead() {
computerService.deleteAllMonitorsWithRelations();
final Monitor monitor = monitorService.addMonitor("Asus");
log.info(monitor.toString());
final Monitor findMonitor = monitorService.findMonitor(monitor.getId());
log.info(findMonitor.toString());
Assertions.assertEquals(monitor, findMonitor);
}
@Test
void testMonitorDelete() {
computerService.deleteAllMonitorsWithRelations();
final Monitor monitor = monitorService.addMonitor("Asus");
log.info(monitor.toString());
computerService.deleteMonitorWithRelation(monitor.getId());
Assertions.assertThrows(MonitorNotFoundException.class, () -> monitorService.findMonitor(monitor.getId()));
}
@Test
void testMonitorReadNotFound() {
computerService.deleteAllMonitorsWithRelations();
Assertions.assertThrows(MonitorNotFoundException.class, () -> monitorService.findMonitor(-1L));
}
@Test
void testMonitorReadAll() {
computerService.deleteAllMonitorsWithRelations();
monitorService.addMonitor("Asus");
monitorService.addMonitor("HP");
final List<Monitor> monitors = monitorService.findAllMonitors();
log.info(monitors.toString());
Assertions.assertEquals(monitors.size(), 2);
}
@Test
void testMonitorReadAllEmpty() {
computerService.deleteAllMonitorsWithRelations();
final List<Monitor> monitors = monitorService.findAllMonitors();
log.info(monitors.toString());
Assertions.assertEquals(monitors.size(), 0);
}
@Test
void testMonitorGetComputer() {
computerService.deleteAllMonitorsWithRelations();
computerService.deleteAllComputers();
Monitor monitor = monitorService.addMonitor("Asus");
Computer computer = computerService.addComputer("Model", "6sfv4", monitor.getId());
log.info(computer.toString());
Computer fetchedComputer = computerService.findComputerByMonitor(monitor);
Assertions.assertEquals(computer, fetchedComputer);
}
}