Вновь небольшое продвижение.
This commit is contained in:
parent
53911bccf8
commit
b3f016eca3
@ -22,7 +22,7 @@ function App() {
|
||||
{ path: 'levels', element: <AddLevel />, label: 'Обзор уровней', userGroup: "AUTH" },
|
||||
{ path: 'nations', element: <AddNation />, label: 'Обзор наций', userGroup: "AUTH" },
|
||||
{ path: 'tanks', element: <AddTank />, label: 'Обзор танков', userGroup: "AUTH"},
|
||||
{ path: 'clients', element: <AddClient />, label: 'Обзор клиентов', userGroup: "AUTH"},
|
||||
{ path: 'clients', element: <AddClient />, label: 'Обзор клиентов', userGroup: "ADMIN"},
|
||||
{ path: 'checkPage', element: <PageForChecking />, label: 'Фильтр по танкам', userGroup: "AUTH"}
|
||||
];
|
||||
|
||||
@ -42,13 +42,11 @@ function App() {
|
||||
<Route element={<SingupPage />} path="/singup" />
|
||||
<Route element={<PrivateRoutes userGroup="AUTH" />}>
|
||||
<Route element={<AddTank />} path="/tanks" />
|
||||
<Route element={<AddLevel />} path="/levels" />
|
||||
<Route element={<PageForChecking />} path="/checkPage" />
|
||||
<Route element={<AddNation />} path="/nations" exact />
|
||||
<Route element={<AddNation />} path="*" />
|
||||
</Route>
|
||||
<Route element={<PrivateRoutes userGroup="USER" />}>
|
||||
<Route element={<AddLevel />} path="/levels" />
|
||||
</Route>
|
||||
<Route element={<PrivateRoutes userGroup="ADMIN" />}>
|
||||
<Route element={<AddClient />} path="/clients" />
|
||||
</Route>
|
||||
|
@ -4,6 +4,9 @@ import '../styles/App.css';
|
||||
import ClientList from './items/GameClient/ClientList';
|
||||
import './AddClient.css';
|
||||
|
||||
const hostURL = "http://localhost:8080";
|
||||
const host = hostURL + "/api/1.0";
|
||||
|
||||
export default function AddClient() {
|
||||
const [clientItems, setClientItems] = useState([]);
|
||||
|
||||
@ -14,45 +17,41 @@ export default function AddClient() {
|
||||
|
||||
const [clientBalance, setClientBalance] = useState();
|
||||
|
||||
const [pageNumbers, setPageNumbers] = useState([]);
|
||||
|
||||
const [pageNumber, setPageNumber] = useState();
|
||||
|
||||
//загрузка всех имеющихся уровней при старте
|
||||
useEffect(() => {
|
||||
console.log('Обращение к БД');
|
||||
axios.get('http://localhost:8080/api/1.0/client/')
|
||||
.then((responce) => {
|
||||
console.log(responce.data);
|
||||
setClientItems(responce.data)
|
||||
})
|
||||
}, [])
|
||||
getUsers(1);
|
||||
}, []);
|
||||
|
||||
const pageButtonOnClick = function (page) {
|
||||
getUsers(page);
|
||||
}
|
||||
|
||||
const getTokenForHeader = function () {
|
||||
return "Bearer " + localStorage.getItem("token");
|
||||
}
|
||||
|
||||
//загрузка всех имеющихся клиентов при старте
|
||||
const getUsers = async function (page) {
|
||||
const requestParams = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const requestUrl = host + `/users?page=${page}`;
|
||||
const response = await fetch(requestUrl, requestParams);
|
||||
const data = await response.json();
|
||||
setClientItems(data.first.content);
|
||||
setPageNumber(data.first.number);
|
||||
setPageNumbers(data.second);
|
||||
}
|
||||
|
||||
//обновить список уровней
|
||||
function CheckArray(){
|
||||
console.log('Обращение к БД');
|
||||
axios.get('http://localhost:8080/api/1.0/client/')
|
||||
.then((responce) => {
|
||||
console.log(responce.data);
|
||||
setClientItems(responce.data)
|
||||
})
|
||||
}
|
||||
|
||||
//добавление нового уровня
|
||||
function addNewClient(){
|
||||
console.log(clientNickName);
|
||||
console.log(clientEmail);
|
||||
console.log(clientBalance);
|
||||
|
||||
if(clientNickName === ''){
|
||||
return;
|
||||
}
|
||||
else {
|
||||
axios.post('http://localhost:8080/api/1.0/client/?nickName=' + clientNickName + '&email=' + clientEmail + '&balance=' + clientBalance)
|
||||
.then((response) => {
|
||||
CheckArray();
|
||||
setClientNickName('');
|
||||
setClientEmail('');
|
||||
setClientBalance('');
|
||||
});
|
||||
}
|
||||
getUsers(1);
|
||||
}
|
||||
|
||||
//добавили условную отрисовку
|
||||
@ -87,11 +86,6 @@ export default function AddClient() {
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<button className='add-level-button'
|
||||
onClick={addNewClient}
|
||||
>
|
||||
Создать клиента
|
||||
</button>
|
||||
<button className='add-level-button'
|
||||
onClick={CheckArray}
|
||||
>
|
||||
|
@ -4,6 +4,9 @@ import '../styles/App.css';
|
||||
import NationList from './items/Nation/NationList';
|
||||
import './AddNation.css';
|
||||
|
||||
const hostURL = "http://localhost:8080";
|
||||
const host = hostURL + "/api/1.0/nation";
|
||||
|
||||
//компонент для просмотра, создания и удаления уровней
|
||||
const AddNation = () => {
|
||||
const [nationItems, setNationItems] = useState([]);
|
||||
@ -13,27 +16,35 @@ const AddNation = () => {
|
||||
|
||||
//загрузка всех имеющихся уровней при старте
|
||||
useEffect(() => {
|
||||
console.log('Обращение к БД');
|
||||
axios.get('http://localhost:8080/nation/')
|
||||
.then((responce) => {
|
||||
console.log(responce.data);
|
||||
setNationItems(responce.data)
|
||||
})
|
||||
getNations();
|
||||
}, [])
|
||||
|
||||
//обновить список уровней
|
||||
function CheckArray(){
|
||||
console.log('Обращение к БД');
|
||||
axios.get('http://localhost:8080/nation/')
|
||||
.then((responce) => {
|
||||
console.log(responce.data);
|
||||
setNationItems(responce.data)
|
||||
})
|
||||
getNations();
|
||||
}
|
||||
|
||||
const getTokenForHeader = function () {
|
||||
return "Bearer " + localStorage.getItem("token");
|
||||
}
|
||||
|
||||
const getNations = async function () {
|
||||
const requestParams = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const requestUrl = host + `/getNations`;
|
||||
const response = await fetch(requestUrl, requestParams);
|
||||
const data = await response.json();
|
||||
console.log(data);
|
||||
setNationItems(data);
|
||||
}
|
||||
|
||||
//добавление нового уровня
|
||||
function addNewNation(){
|
||||
if(nation.nation === ''){
|
||||
/*if(nation.nation === ''){
|
||||
return;
|
||||
}
|
||||
else {
|
||||
@ -42,7 +53,7 @@ const AddNation = () => {
|
||||
CheckArray();
|
||||
setNation({nation: ''});
|
||||
});
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
//добавили условную отрисовку
|
||||
|
@ -2,6 +2,7 @@ export default class UserSignupDto {
|
||||
constructor(args) {
|
||||
this.login = args.login;
|
||||
this.email = args.email;
|
||||
this.balance = args.balance;
|
||||
this.password = args.password;
|
||||
this.passwordConfirm = args.passwordConfirm;
|
||||
}
|
||||
|
@ -4,6 +4,9 @@ import './ClientItem.css';
|
||||
import ModalClient from './ModalClient';
|
||||
import ModalTankNation from '../Nation/ModalTankNation';
|
||||
|
||||
const hostURL = "http://localhost:8080";
|
||||
const host = hostURL + "/api/1.0";
|
||||
|
||||
const ClientItem = (data) => {
|
||||
|
||||
const [client, setClient] = useState(null);
|
||||
@ -14,19 +17,29 @@ const ClientItem = (data) => {
|
||||
//состояние для вызова окна показа списка танков нации
|
||||
const[modalNation, setModalNation] = useState(false);
|
||||
|
||||
function deleteClient(){
|
||||
axios.delete('http://localhost:8080/client/' + data.clientItem.id)
|
||||
.then((response) => {
|
||||
console.log("Удаление уровня с id " + data.clientItem.id)
|
||||
});
|
||||
const getTokenForHeader = function () {
|
||||
return "Bearer " + localStorage.getItem("token");
|
||||
}
|
||||
|
||||
const deleteClient = async function (id) {
|
||||
const requestParams = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const requestUrl = host + `/user/${id}`;
|
||||
await fetch(requestUrl, requestParams);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="client-card">
|
||||
<p className="client-attribute"> id: {data.clientItem.id} </p>
|
||||
<p className="client-attribute"> Никнейм: {data.clientItem.nickName} </p>
|
||||
<p className="client-attribute"> Никнейм: {data.clientItem.login} </p>
|
||||
<p className="client-attribute"> Баланс: {data.clientItem.balance} </p>
|
||||
<p className="client-attribute"> Почта: {data.clientItem.email} </p>
|
||||
<p className="client-attribute"> Роль: {data.clientItem.role} </p>
|
||||
<div className='client-button-group'>
|
||||
<button className="client-button" type="button"
|
||||
onClick={() => setModal(true)}
|
||||
@ -34,7 +47,7 @@ const ClientItem = (data) => {
|
||||
Редактировать
|
||||
</button>
|
||||
<button className="client-button" type="button"
|
||||
onClick={deleteClient}
|
||||
onClick={deleteClient(data.clientItem.id)}
|
||||
>
|
||||
Удалить
|
||||
</button>
|
||||
|
@ -6,12 +6,14 @@ import '../../AddClient.css';
|
||||
const ModalClient = ({data, visible, setVisible}) => {
|
||||
|
||||
//для обновления уровня
|
||||
const [clientNickName, setClientNickName] = useState(data.nickName);
|
||||
const [clientNickName, setClientNickName] = useState(data.login);
|
||||
|
||||
const [clientEmail, setClientEmail] = useState(data.email);
|
||||
|
||||
const [clientBalance, setClientBalance] = useState(data.balance);
|
||||
|
||||
const [clientPassword, setClientPassword] = useState(data.password);
|
||||
|
||||
const [clientTank, setClientTank] = useState(null);
|
||||
|
||||
const [tankItems, setTankItems] = useState([]);
|
||||
@ -35,8 +37,8 @@ const ModalClient = ({data, visible, setVisible}) => {
|
||||
|
||||
//добавление нового уровня
|
||||
function updateLevel(){
|
||||
axios.put('http://localhost:8080/client/' + data.id + '?nickName='
|
||||
+ clientNickName + '&email=' + clientEmail + '&balance=' + clientBalance + '&tankId=' + clientTank)
|
||||
axios.put('http://localhost:8080/client/' + data.id + '?login='
|
||||
+ clientNickName + '&email=' + clientEmail + '&password=' + clientPassword + + '&balance=' + clientBalance + '&tankId=' + clientTank)
|
||||
.then((response) => {
|
||||
console.log("Обновление клиента с id " + data.id)
|
||||
});
|
||||
@ -90,6 +92,14 @@ const ModalClient = ({data, visible, setVisible}) => {
|
||||
)}
|
||||
</select>
|
||||
</p>
|
||||
<p style={{marginTop: "10px"}}>
|
||||
Пароль:
|
||||
<input
|
||||
className="add-client-input"
|
||||
value={clientPassword}
|
||||
onChange={e => setClientPassword(e.target.value)}
|
||||
/>
|
||||
</p>
|
||||
<button
|
||||
style={{marginTop: "10px"}}
|
||||
className={cl.modalButton}
|
||||
|
@ -46,7 +46,7 @@ const LoginPage = function () {
|
||||
const result = await response.text();
|
||||
localStorage.setItem("role", result);
|
||||
window.dispatchEvent(new Event("storage"));
|
||||
navigate("/main");
|
||||
navigate("/index");
|
||||
}
|
||||
|
||||
const loginFormOnSubmit = function (event) {
|
||||
|
@ -10,12 +10,12 @@ const PrivateRoutes = (props) => {
|
||||
let token = localStorage.getItem("token");
|
||||
if (token) {
|
||||
getRole(token).then((role) => {
|
||||
if (localStorage.getItem("role") != role) {
|
||||
if (localStorage.getItem("role") !== role) {
|
||||
localStorage.removeItem("token");
|
||||
localStorage.removeItem("user");
|
||||
localStorage.removeItem("role");
|
||||
window.dispatchEvent(new Event("storage"));
|
||||
navigate("/main");
|
||||
navigate("/index");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ const SingupPage = function () {
|
||||
const emailInput = useRef();
|
||||
const passwordInput = useRef();
|
||||
const passwordConfirmInput = useRef();
|
||||
const balanceInput = useRef();
|
||||
|
||||
useEffect(() => {
|
||||
}, []);
|
||||
@ -32,6 +33,7 @@ const SingupPage = function () {
|
||||
const userSinginDto = {
|
||||
login: loginInput.current.value,
|
||||
email: emailInput.current.value,
|
||||
balance: balanceInput.current.value,
|
||||
password: passwordInput.current.value,
|
||||
passwordConfirm: passwordConfirmInput.current.value
|
||||
}
|
||||
@ -54,6 +56,12 @@ const SingupPage = function () {
|
||||
type="text" required
|
||||
ref={emailInput} />
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<p className="mb-1">Balance</p>
|
||||
<input className="form-control"
|
||||
type="text" required minlength="3" maxlength="64"
|
||||
ref={balanceInput} />
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<p className="mb-1">Password</p>
|
||||
<input className="form-control"
|
||||
|
@ -14,7 +14,7 @@ public class ClientDTO {
|
||||
private String password;
|
||||
private String email;
|
||||
private Integer balance;
|
||||
private List<TankDTO> tanks;
|
||||
private List<TankDTO> tanks = new ArrayList<>();
|
||||
private UserRole role;
|
||||
|
||||
public ClientDTO(){ }
|
||||
|
@ -19,8 +19,6 @@ import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/client")
|
||||
public class GameClientController {
|
||||
public static final String URL_LOGIN = "/jwt/login";
|
||||
public static final String URL_SING_UP = "/sing_up";
|
||||
@ -52,28 +50,11 @@ public class GameClientController {
|
||||
}
|
||||
|
||||
//аннотация PathVariable связывает значения id из URL и Long id
|
||||
@GetMapping(OpenAPI30Configuration.API_PREFIX + "/{id}")
|
||||
@GetMapping(OpenAPI30Configuration.API_PREFIX + "/")
|
||||
public ClientDTO getClient(@PathVariable Long id) {
|
||||
return new ClientDTO(gameClientService.findClient(id));
|
||||
}
|
||||
|
||||
//с помощью Java Stream преобразуем набор пришедших данных в объекты StudentDto
|
||||
@GetMapping(OpenAPI30Configuration.API_PREFIX + "/")
|
||||
@Secured({UserRole.AsString.ADMIN})
|
||||
public List<ClientDTO> getClients() {
|
||||
return gameClientService.findAllClients().stream()
|
||||
.map(ClientDTO::new)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@PostMapping(OpenAPI30Configuration.API_PREFIX + "/")
|
||||
public ClientDTO createClient(@RequestParam("login") String login,
|
||||
@RequestParam("password") String password,
|
||||
@RequestParam("email") String email,
|
||||
@RequestParam("balance") Integer balance) {
|
||||
return new ClientDTO(gameClientService.addClient(login, email, password, balance, password, UserRole.USER));
|
||||
}
|
||||
|
||||
@PutMapping(OpenAPI30Configuration.API_PREFIX + "/{id}")
|
||||
@Secured({UserRole.AsString.USER})
|
||||
public ClientDTO updateClient(@PathVariable Long id,
|
||||
@ -85,7 +66,7 @@ public class GameClientController {
|
||||
return new ClientDTO(gameClientService.updateClient(id, login, password, email, balance, tankService.findTank(tankId)));
|
||||
}
|
||||
|
||||
@DeleteMapping(OpenAPI30Configuration.API_PREFIX + "/{id}")
|
||||
@PostMapping(OpenAPI30Configuration.API_PREFIX + "/{id}")
|
||||
@Secured({UserRole.AsString.USER})
|
||||
public ClientDTO deleteClient(@PathVariable Long id) {
|
||||
return new ClientDTO(gameClientService.deleteClient(id));
|
||||
@ -93,7 +74,7 @@ public class GameClientController {
|
||||
|
||||
@GetMapping(OpenAPI30Configuration.API_PREFIX + "/users")
|
||||
@Secured({UserRole.AsString.ADMIN})
|
||||
public Pair<Page<ClientDTO>, List<Integer>> getUsers(@RequestParam(defaultValue = "1") int page,
|
||||
public Pair<Page<ClientDTO>, List<Integer>> getClients(@RequestParam(defaultValue = "1") int page,
|
||||
@RequestParam(defaultValue = "5") int size) {
|
||||
final Page<ClientDTO> users = gameClientService.findAllPages(page, size)
|
||||
.map(ClientDTO::new);
|
||||
|
@ -31,7 +31,7 @@ public class NationController {
|
||||
}
|
||||
|
||||
//с помощью Java Stream преобразуем набор пришедших данных в объекты StudentDto
|
||||
@GetMapping("/")
|
||||
@GetMapping("/getNations")
|
||||
public List<FullNationDTO> getNations() {
|
||||
return nationService.findAllNations().stream()
|
||||
.map(FullNationDTO::new)
|
||||
|
Loading…
x
Reference in New Issue
Block a user