diff --git a/demo/src/main/java/com/example/demo/supply/Product/ProductController.java b/demo/src/main/java/com/example/demo/supply/Product/ProductController.java
index 66f154f..d56d986 100644
--- a/demo/src/main/java/com/example/demo/supply/Product/ProductController.java
+++ b/demo/src/main/java/com/example/demo/supply/Product/ProductController.java
@@ -27,12 +27,14 @@ public class ProductController {
}
@PostMapping("/")
+ @Secured({UserRole.AsString.ADMIN})
public ProductDto createProduct(@RequestParam() String name,
@RequestParam() double cost) {
return new ProductDto(productService.addProduct(name, cost));
}
@PatchMapping("/{id}")
+ @Secured({UserRole.AsString.ADMIN})
public ProductDto updateProduct(@PathVariable Long id,
@RequestParam String name,
@RequestParam double cost) {
@@ -40,6 +42,7 @@ public class ProductController {
}
@DeleteMapping("/{id}")
+ @Secured({UserRole.AsString.ADMIN})
public ProductDto deleteProduct(@PathVariable Long id) {
return new ProductDto(productService.deleteProduct(id));
}
diff --git a/front/src/App.js b/front/src/App.js
index d2c9423..9110393 100644
--- a/front/src/App.js
+++ b/front/src/App.js
@@ -7,7 +7,8 @@ import Header from "./general/Header";
import SignUpPage from "./Pages/SignUpPage";
import LoginPage from "./Pages/LoginPage";
import PrivateRoutes from './utils/PrivateRoutes';
-
+import UsersPage from "./Pages/UsersPage";
+import GetSomeSuppliers from "./Pages/GetSomeSuppliers";
function App() {
@@ -22,9 +23,10 @@ function App() {
+
}>
- {/* } path="/Users"/> */}
+
diff --git a/front/src/DataService.js b/front/src/DataService.js
index 259f039..b06c71f 100644
--- a/front/src/DataService.js
+++ b/front/src/DataService.js
@@ -6,7 +6,6 @@ function getFullUrl(url, data) {
const fields = Object.getOwnPropertyNames(data);
//проходимся по каждому полю
for (const field of fields) {
-
if (field === undefined) continue
if (field === 'id') continue
if (field === 'date') continue
@@ -33,11 +32,6 @@ export default class DataService {
return res
}
- static async read(url, transformer) {
- const response = await axios.get(this.mainUrl + url);
- return transformer(response.data);
- }
-
static async readUsersPage(dataUrlPrefix, url, page) {
const response = await axios.get(dataUrlPrefix + url + `?page=${page}`,{
headers:{
@@ -52,6 +46,11 @@ export default class DataService {
return response.data;
}
+ static async read(url, transformer) {
+ const response = await axios.get(this.mainUrl + url);
+ return transformer(response.data);
+ }
+
static async create(url, data) {
const response = await axios.post(getFullUrl(this.mainUrl + url, data))
const res = response.data
@@ -65,6 +64,14 @@ export default class DataService {
return true;
}
+ static async getSomeSuppliers(url){
+ const response = await fetch(this.mainUrl + url, {
+ method: 'GET',
+ }).catch(e => console.log(e))
+ const res = response.json()
+ return res
+ }
+
static async update(url, data) {
await fetch(getFullUrl(this.mainUrl + url, data), {
method: 'PATCH',
diff --git a/front/src/Pages/GetSomeSuppliers.jsx b/front/src/Pages/GetSomeSuppliers.jsx
new file mode 100644
index 0000000..6444758
--- /dev/null
+++ b/front/src/Pages/GetSomeSuppliers.jsx
@@ -0,0 +1,97 @@
+import React, { useState, useEffect } from "react";
+import Modal from "../general/Modal";
+import Table from "../general/Table";
+import DataService from "../DataService";
+import Product from "../models/Product";
+import Supplier from "../models/Supplier";
+
+export default function GetSomeSuppliers(props) {
+ const url = 'order/someSuppliers/'
+ const productUrl = 'product/'
+
+ const headers = [
+ { name: 'name', label: 'Поставщик' },
+ { name: 'license', label: 'Лицензия' }
+ ];
+
+ const transformer = (data) => new Supplier(data)
+ const transformerProduct = (data) => new Product(data)
+
+ const [suppliers, setSuppliers] = useState([])
+ const [products, setProducts] = useState([])
+ const [product, setProduct] = useState(new Product())
+
+ const [modalHeader, setModalHeader] = useState('')
+ const [modalConfirm, setModalConfirm] = useState('')
+ const [modalVisible, setModalVisible] = useState(false)
+
+ useEffect(() => {
+ loadItems()
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
+ const loadItems = () => {
+ DataService.readAll(productUrl, transformerProduct).then(data =>{
+ console.log(data)
+ setProducts(data)
+ })
+ }
+
+ const chooseProduct = () => {
+ setModalHeader('Добавление')
+ setModalConfirm('Добавить')
+ setModalVisible(true)
+ }
+
+ const save = () => {
+ console.log(product)
+ DataService.getSomeSuppliers(`${url}${product.id}`)
+ .then(data => setSuppliers(data))
+ }
+
+ const handleChooseProduct = (event) => {
+ // console.log(event.target.id)
+ // console.log(event.target.value)
+ setProduct({ ...product, [event.target.id]: event.target.value })
+ }
+
+ const handleTableClick = (tableSelectedItems) => console.log("")
+ const handleTableDblClick = (tableSelectedItem) => console.log("")
+
+ const hideModal = () => {
+ setModalVisible(false)
+ }
+ const modalDone = () => save()
+
+ return (
+ <>
+
+
+
+
+
+
Продукт
+
+
+
+ >
+ );
+}
\ No newline at end of file
diff --git a/front/src/Pages/UsersPage.jsx b/front/src/Pages/UsersPage.jsx
new file mode 100644
index 0000000..e339736
--- /dev/null
+++ b/front/src/Pages/UsersPage.jsx
@@ -0,0 +1,63 @@
+import DataService from "../DataService";
+import { useState, useEffect } from "react";
+
+export default function UsersPage() {
+ const [users, setUsers] = useState([]);
+ const [pageNumbers, setPageNumbers] = useState([]);
+ const [pageNumber, setPageNumber] = useState();
+ const usersUrl = "/users";
+ const host = "http://localhost:8080/api/1.0";
+
+ useEffect(() => {
+ DataService.readUsersPage(host,usersUrl, 1).then((data)=>{
+ setUsers(data.first.content);
+ setPageNumbers(data.second);
+ setPageNumber(1);
+ });
+ }, []);
+ const pageButtonOnClick = function (page) {
+ DataService.readUsersPage(host,usersUrl, page).then((data)=>{
+ setUsers(data.first.content);
+ setPageNumber(page);
+ });
+ }
+ return (
+ <>
+
+
+
+
+ ID |
+ Логин |
+ Роль |
+
+
+
+ {users.map((user, index) => (
+
+ {user.id} |
+ {user.login} |
+ {user.role} |
+
+ ))}
+
+
+
+
+
+ Pages:
+
+
+
+ >
+ );
+}
\ No newline at end of file
diff --git a/front/src/general/Header.jsx b/front/src/general/Header.jsx
index e30e735..f086780 100644
--- a/front/src/general/Header.jsx
+++ b/front/src/general/Header.jsx
@@ -40,6 +40,12 @@ export default function Header() {
+
+
+ Доп
+
+
+
Вход