[test-entity]: router fix
This commit is contained in:
parent
658a351d28
commit
9ca0430fda
6
front/package-lock.json
generated
6
front/package-lock.json
generated
@ -2811,7 +2811,7 @@
|
|||||||
"version": "15.7.13",
|
"version": "15.7.13",
|
||||||
"resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.13.tgz",
|
"resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.13.tgz",
|
||||||
"integrity": "sha512-hCZTSvwbzWGvhqxp/RqVqwU999pBf2vp7hzIjiYOsl8wqOmUxkQ6ddw1cV3l8811+kdUFus/q4d1Y3E3SyEifA==",
|
"integrity": "sha512-hCZTSvwbzWGvhqxp/RqVqwU999pBf2vp7hzIjiYOsl8wqOmUxkQ6ddw1cV3l8811+kdUFus/q4d1Y3E3SyEifA==",
|
||||||
"devOptional": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/@types/qs": {
|
"node_modules/@types/qs": {
|
||||||
"version": "6.9.16",
|
"version": "6.9.16",
|
||||||
@ -2829,7 +2829,7 @@
|
|||||||
"version": "18.3.8",
|
"version": "18.3.8",
|
||||||
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.8.tgz",
|
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.8.tgz",
|
||||||
"integrity": "sha512-syBUrW3/XpnW4WJ41Pft+I+aPoDVbrBVQGEnbD7NijDGlVC+8gV/XKRY+7vMDlfPpbwYt0l1vd/Sj8bJGMbs9Q==",
|
"integrity": "sha512-syBUrW3/XpnW4WJ41Pft+I+aPoDVbrBVQGEnbD7NijDGlVC+8gV/XKRY+7vMDlfPpbwYt0l1vd/Sj8bJGMbs9Q==",
|
||||||
"devOptional": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/prop-types": "*",
|
"@types/prop-types": "*",
|
||||||
"csstype": "^3.0.2"
|
"csstype": "^3.0.2"
|
||||||
@ -4262,7 +4262,7 @@
|
|||||||
"version": "3.1.3",
|
"version": "3.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz",
|
||||||
"integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==",
|
"integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==",
|
||||||
"devOptional": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "4.3.7",
|
"version": "4.3.7",
|
||||||
|
@ -98,7 +98,9 @@ export const updatePark = async (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (t.delete) {
|
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(
|
return api.put(
|
||||||
`${WIND_ENDPOINTS.parkTurbine}/${parkPesponse.data.id}/${t.id}`,
|
`${WIND_ENDPOINTS.parkTurbine}/${parkPesponse.data.id}/${t.id}`,
|
||||||
@ -108,3 +110,8 @@ export const updatePark = async (
|
|||||||
);
|
);
|
||||||
return getParkWithTurbines(id);
|
return getParkWithTurbines(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const deletePark = (id: number) => {
|
||||||
|
const url = `${WIND_ENDPOINTS.park}/${id}`;
|
||||||
|
return api.delete(url);
|
||||||
|
};
|
||||||
|
@ -4,7 +4,13 @@ import {
|
|||||||
ParkWithTurbines,
|
ParkWithTurbines,
|
||||||
updatePark,
|
updatePark,
|
||||||
} from '@api/wind';
|
} 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 { ParkTurbines } from '@components/ux';
|
||||||
import { Controller, useForm } from '@utils/form';
|
import { Controller, useForm } from '@utils/form';
|
||||||
import { ROUTES, useRoute } from '@utils/route';
|
import { ROUTES, useRoute } from '@utils/route';
|
||||||
@ -18,6 +24,7 @@ import { unpackPark } from './utils';
|
|||||||
export function ParkPage() {
|
export function ParkPage() {
|
||||||
const [park, setPark] = useState<ParkWithTurbines>(null);
|
const [park, setPark] = useState<ParkWithTurbines>(null);
|
||||||
const [pending, setPending] = useState<boolean>(false);
|
const [pending, setPending] = useState<boolean>(false);
|
||||||
|
const [error, setError] = useState<string>(null);
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
@ -45,12 +52,20 @@ export function ParkPage() {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setPending(true);
|
setPending(true);
|
||||||
if (isEdit) {
|
if (isEdit) {
|
||||||
const response = await updatePark(getValues(), id);
|
const { data, error } = await updatePark(getValues(), id);
|
||||||
setPark(response.data);
|
if (error) {
|
||||||
reset(unpackPark(response.data));
|
setError('Something went wrong');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setPark(data);
|
||||||
|
reset(unpackPark(data));
|
||||||
} else {
|
} else {
|
||||||
const response = await createPark(getValues());
|
const { data, error } = await createPark(getValues());
|
||||||
navigate(ROUTES.park.path.replace(':id', String(response.data.id)));
|
if (error) {
|
||||||
|
setError('Something went wrong');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
navigate(ROUTES.park.path.replace(':id', String(data.id)));
|
||||||
}
|
}
|
||||||
setPending(false);
|
setPending(false);
|
||||||
};
|
};
|
||||||
@ -100,6 +115,14 @@ export function ParkPage() {
|
|||||||
<ParkTurbines savedTurbines={park?.turbines ?? []} {...props} />
|
<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>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { getParks, Park } from '@api/wind';
|
import { deletePark, getParks, Park } from '@api/wind';
|
||||||
import { Button, Heading } from '@components/ui';
|
import { Button, Heading } from '@components/ui';
|
||||||
import { DataGrid } from '@components/ui/data-grid';
|
import { DataGrid } from '@components/ui/data-grid';
|
||||||
import { ROUTES, useRoute } from '@utils/route';
|
import { ROUTES, useRoute } from '@utils/route';
|
||||||
@ -27,7 +27,8 @@ export function ParksPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteButtonClick = async () => {
|
const handleDeleteButtonClick = async () => {
|
||||||
//
|
await deletePark(selected.id);
|
||||||
|
fetchParks();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -158,8 +158,8 @@ class WindParkTurbineRepository:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def delete(db: Session, park_turbine_id: int):
|
def delete(db: Session, park_id: int, turbine_id: int):
|
||||||
db_park_turbine = db.query(WindParkTurbine).filter(WindParkTurbine.turbine_id == park_turbine_id).first()
|
db_park_turbine = db.query(WindParkTurbine).filter(WindParkTurbine.wind_park_id == park_id, WindParkTurbine.turbine_id == turbine_id).first()
|
||||||
if db_park_turbine:
|
if db_park_turbine:
|
||||||
db.delete(db_park_turbine)
|
db.delete(db_park_turbine)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
@ -94,9 +94,9 @@ async def update_park_turbine(park_id: int, turbine_id: int, park_turbine: WindP
|
|||||||
return updated_park_turbine
|
return updated_park_turbine
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/park_turbine/{park_turbine_id}", status_code=204)
|
@router.delete("/park_turbine/{park_id}/{turbine_id}", status_code=204)
|
||||||
async def delete_park_turbine(park_turbine_id: int, db: Session = Depends(get_db)):
|
async def delete_park_turbine(park_id: int, turbine_id: int, db: Session = Depends(get_db)):
|
||||||
result = WindParkTurbineRepository.delete(db=db, park_turbine_id=park_turbine_id)
|
result = WindParkTurbineRepository.delete(db=db, park_id=park_id, turbine_id=turbine_id)
|
||||||
if not result:
|
if not result:
|
||||||
raise HTTPException(status_code=404, detail="Park Turbine not found")
|
raise HTTPException(status_code=404, detail="Park Turbine not found")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user