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