[test-entity]: router fix

This commit is contained in:
maxim 2024-11-24 12:55:59 +04:00
parent 658a351d28
commit 9ca0430fda
6 changed files with 48 additions and 17 deletions

View File

@ -2811,7 +2811,7 @@
"version": "15.7.13",
"resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.13.tgz",
"integrity": "sha512-hCZTSvwbzWGvhqxp/RqVqwU999pBf2vp7hzIjiYOsl8wqOmUxkQ6ddw1cV3l8811+kdUFus/q4d1Y3E3SyEifA==",
"devOptional": true
"dev": true
},
"node_modules/@types/qs": {
"version": "6.9.16",
@ -2829,7 +2829,7 @@
"version": "18.3.8",
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.8.tgz",
"integrity": "sha512-syBUrW3/XpnW4WJ41Pft+I+aPoDVbrBVQGEnbD7NijDGlVC+8gV/XKRY+7vMDlfPpbwYt0l1vd/Sj8bJGMbs9Q==",
"devOptional": true,
"dev": true,
"dependencies": {
"@types/prop-types": "*",
"csstype": "^3.0.2"
@ -4262,7 +4262,7 @@
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz",
"integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==",
"devOptional": true
"dev": true
},
"node_modules/debug": {
"version": "4.3.7",

View File

@ -98,7 +98,9 @@ export const updatePark = async (
);
}
if (t.delete) {
return api.delete(`${WIND_ENDPOINTS.parkTurbine}/${t.id}`);
return api.delete(
`${WIND_ENDPOINTS.parkTurbine}/${parkPesponse.data.id}/${t.id}`,
);
}
return api.put(
`${WIND_ENDPOINTS.parkTurbine}/${parkPesponse.data.id}/${t.id}`,
@ -108,3 +110,8 @@ export const updatePark = async (
);
return getParkWithTurbines(id);
};
export const deletePark = (id: number) => {
const url = `${WIND_ENDPOINTS.park}/${id}`;
return api.delete(url);
};

View File

@ -4,7 +4,13 @@ import {
ParkWithTurbines,
updatePark,
} from '@api/wind';
import { Button, Heading, NumberField, TextInput } from '@components/ui';
import {
Button,
Dialog,
Heading,
NumberField,
TextInput,
} from '@components/ui';
import { ParkTurbines } from '@components/ux';
import { Controller, useForm } from '@utils/form';
import { ROUTES, useRoute } from '@utils/route';
@ -18,6 +24,7 @@ import { unpackPark } from './utils';
export function ParkPage() {
const [park, setPark] = useState<ParkWithTurbines>(null);
const [pending, setPending] = useState<boolean>(false);
const [error, setError] = useState<string>(null);
const params = useParams();
const navigate = useNavigate();
const route = useRoute();
@ -45,12 +52,20 @@ export function ParkPage() {
event.preventDefault();
setPending(true);
if (isEdit) {
const response = await updatePark(getValues(), id);
setPark(response.data);
reset(unpackPark(response.data));
const { data, error } = await updatePark(getValues(), id);
if (error) {
setError('Something went wrong');
return;
}
setPark(data);
reset(unpackPark(data));
} else {
const response = await createPark(getValues());
navigate(ROUTES.park.path.replace(':id', String(response.data.id)));
const { data, error } = await createPark(getValues());
if (error) {
setError('Something went wrong');
return;
}
navigate(ROUTES.park.path.replace(':id', String(data.id)));
}
setPending(false);
};
@ -100,6 +115,14 @@ export function ParkPage() {
<ParkTurbines savedTurbines={park?.turbines ?? []} {...props} />
)}
/>
<Dialog
open={Boolean(error)}
heading="Error"
message="Something went wrong"
onClose={() => setError(null)}
>
<Button onClick={() => setError(null)}>Ok</Button>
</Dialog>
</div>
);
}

View File

@ -1,4 +1,4 @@
import { getParks, Park } from '@api/wind';
import { deletePark, getParks, Park } from '@api/wind';
import { Button, Heading } from '@components/ui';
import { DataGrid } from '@components/ui/data-grid';
import { ROUTES, useRoute } from '@utils/route';
@ -27,7 +27,8 @@ export function ParksPage() {
};
const handleDeleteButtonClick = async () => {
//
await deletePark(selected.id);
fetchParks();
};
return (

View File

@ -158,8 +158,8 @@ class WindParkTurbineRepository:
return None
@staticmethod
def delete(db: Session, park_turbine_id: int):
db_park_turbine = db.query(WindParkTurbine).filter(WindParkTurbine.turbine_id == park_turbine_id).first()
def delete(db: Session, park_id: int, turbine_id: int):
db_park_turbine = db.query(WindParkTurbine).filter(WindParkTurbine.wind_park_id == park_id, WindParkTurbine.turbine_id == turbine_id).first()
if db_park_turbine:
db.delete(db_park_turbine)
db.commit()

View File

@ -94,9 +94,9 @@ async def update_park_turbine(park_id: int, turbine_id: int, park_turbine: WindP
return updated_park_turbine
@router.delete("/park_turbine/{park_turbine_id}", status_code=204)
async def delete_park_turbine(park_turbine_id: int, db: Session = Depends(get_db)):
result = WindParkTurbineRepository.delete(db=db, park_turbine_id=park_turbine_id)
@router.delete("/park_turbine/{park_id}/{turbine_id}", status_code=204)
async def delete_park_turbine(park_id: int, turbine_id: int, db: Session = Depends(get_db)):
result = WindParkTurbineRepository.delete(db=db, park_id=park_id, turbine_id=turbine_id)
if not result:
raise HTTPException(status_code=404, detail="Park Turbine not found")