Вроде как все CRUD для nation..
This commit is contained in:
parent
2f0e1edba8
commit
949716b6b2
@ -3,6 +3,9 @@ import axios from 'axios';
|
|||||||
import cl from './ModalNation.module.css';
|
import cl from './ModalNation.module.css';
|
||||||
import '../../AddNation.css';
|
import '../../AddNation.css';
|
||||||
|
|
||||||
|
const hostURL = "http://localhost:8080";
|
||||||
|
const host = hostURL + "/api/1.0/nation";
|
||||||
|
|
||||||
const ModalNation = ({data, visible, setVisible}) => {
|
const ModalNation = ({data, visible, setVisible}) => {
|
||||||
//для обновления уровня
|
//для обновления уровня
|
||||||
const [nation, setNation] = useState(data.nation);
|
const [nation, setNation] = useState(data.nation);
|
||||||
@ -17,15 +20,32 @@ const ModalNation = ({data, visible, setVisible}) => {
|
|||||||
rootClasses.push(cl.active);
|
rootClasses.push(cl.active);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getTokenForHeader = function () {
|
||||||
|
return "Bearer " + localStorage.getItem("token");
|
||||||
|
}
|
||||||
|
|
||||||
//добавление новой нации
|
//добавление новой нации
|
||||||
function updateLevel(){
|
/*function updateLevel(){
|
||||||
setNation()
|
setNation()
|
||||||
axios.put('http://localhost:8080/nation/' + data.id + '?nation=' + nation + '&tankId=' + nullId)
|
axios.put('http://localhost:8080/nation/' + data.id + '?nation=' + nation + '&tankId=' + nullId)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log("Обновление нации с id " + data.id)
|
console.log("Обновление нации с id " + data.id)
|
||||||
});
|
});
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
const updateLevel = async function () {
|
||||||
|
const requestParams = {
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": getTokenForHeader(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const requestUrl = host + `/${data.id}?nation=${nation}&tankId=${nullId}`;
|
||||||
|
const response = await fetch(requestUrl, requestParams);
|
||||||
|
console.log("Обновление успешно!")
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={rootClasses.join(' ')} onClick={() => setVisible(false)}>
|
<div className={rootClasses.join(' ')} onClick={() => setVisible(false)}>
|
||||||
@ -38,7 +58,7 @@ const ModalNation = ({data, visible, setVisible}) => {
|
|||||||
<button
|
<button
|
||||||
className={cl.modalButton}
|
className={cl.modalButton}
|
||||||
type="button"
|
type="button"
|
||||||
onClick={updateLevel}
|
onClick={event => updateLevel()}
|
||||||
>
|
>
|
||||||
Сохранить
|
Сохранить
|
||||||
</button>
|
</button>
|
||||||
|
@ -23,7 +23,7 @@ const NationItem = (data) => {
|
|||||||
|
|
||||||
const deleteFecth = async function (id) {
|
const deleteFecth = async function (id) {
|
||||||
const requestParams = {
|
const requestParams = {
|
||||||
method: "POST",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": getTokenForHeader(),
|
"Authorization": getTokenForHeader(),
|
||||||
|
@ -53,7 +53,7 @@ public class NationController {
|
|||||||
return new FullNationDTO(nationService.updateNation(id, nation, (tankId > 0) ? tankService.findTank(tankId) : null));
|
return new FullNationDTO(nationService.updateNation(id, nation, (tankId > 0) ? tankService.findTank(tankId) : null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public FullNationDTO deleteNation(@PathVariable Long id) {
|
public FullNationDTO deleteNation(@PathVariable Long id) {
|
||||||
return new FullNationDTO(nationService.deleteNation(id));
|
return new FullNationDTO(nationService.deleteNation(id));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user