diff --git a/api/app/controllers/patients_router.py b/api/app/controllers/patients_router.py
index e547458..5345adc 100644
--- a/api/app/controllers/patients_router.py
+++ b/api/app/controllers/patients_router.py
@@ -37,3 +37,12 @@ async def update_patient(
):
patients_service = PatientsService(db)
return await patients_service.update_patient(patient_id, patient)
+
+@router.delete("/patients/{patient_id}/", response_model=bool)
+async def delete_patient(
+ patient_id: int,
+ db: AsyncSession = Depends(get_db),
+ user=Depends(get_current_user)
+):
+ patient_service = PatientsService(db)
+ return await patient_service.delete_patient(patient_id)
diff --git a/api/app/infrastructure/auth_service.py b/api/app/infrastructure/auth_service.py
index bd48193..3aee7bd 100644
--- a/api/app/infrastructure/auth_service.py
+++ b/api/app/infrastructure/auth_service.py
@@ -2,6 +2,7 @@ import datetime
from typing import Optional
import jwt
+from fastapi import HTTPException
from sqlalchemy.ext.asyncio import AsyncSession
from app.application.users_repository import UsersRepository
@@ -21,7 +22,7 @@ class AuthService:
"user_id": user.id
}
- return None
+ raise HTTPException(status_code=403, detail="Invalid login or password")
@staticmethod
def create_access_token(data: dict) -> str:
diff --git a/api/app/infrastructure/patients_service.py b/api/app/infrastructure/patients_service.py
index 6b2d137..9ea8964 100644
--- a/api/app/infrastructure/patients_service.py
+++ b/api/app/infrastructure/patients_service.py
@@ -1,5 +1,6 @@
from typing import Optional
+from fastapi import HTTPException
from sqlalchemy.ext.asyncio import AsyncSession
from app.application.patients_repository import PatientsRepository
@@ -81,4 +82,12 @@ class PatientsService:
correction=patient_model.correction,
)
- return None
+ raise HTTPException(status_code=404, detail="Patient not found")
+
+ async def delete_patient(self, patient_id: int) -> Optional[bool]:
+ result = await self.patient_repository.delete(patient_id) is not None
+
+ if not result:
+ raise HTTPException(status_code=404, detail="Patient not found")
+
+ return result
diff --git a/web-app/src/api/patients/AddPatient.jsx b/web-app/src/api/patients/AddPatient.jsx
index ab6dd7a..c97b5fa 100644
--- a/web-app/src/api/patients/AddPatient.jsx
+++ b/web-app/src/api/patients/AddPatient.jsx
@@ -11,7 +11,7 @@ const AddPatient = async (token, patient) => {
});
return response.data;
} catch (error) {
- throw new Error(error.response.data.message);
+ throw new Error(error.message);
}
};
diff --git a/web-app/src/api/patients/DeletePatient.jsx b/web-app/src/api/patients/DeletePatient.jsx
new file mode 100644
index 0000000..a359557
--- /dev/null
+++ b/web-app/src/api/patients/DeletePatient.jsx
@@ -0,0 +1,19 @@
+import axios from "axios";
+import CONFIG from "../../core/Config.jsx";
+
+
+const DeletePatient = async (token, patient_id) => {
+ try {
+ const response = await axios.delete(`${CONFIG.BASE_URL}/patients/${patient_id}/`, {
+ headers: {
+ Authorization: `Bearer ${token}`,
+ },
+ });
+ return response.data;
+ } catch (error) {
+ throw new Error(error.message);
+ }
+}
+
+
+export default DeletePatient;
\ No newline at end of file
diff --git a/web-app/src/api/patients/GetAllPatients.jsx b/web-app/src/api/patients/GetAllPatients.jsx
index 48d8b09..f6b7954 100644
--- a/web-app/src/api/patients/GetAllPatients.jsx
+++ b/web-app/src/api/patients/GetAllPatients.jsx
@@ -1,6 +1,7 @@
import axios from "axios";
import CONFIG from "../../core/Config.jsx";
+
const getAllPatients = async (token) => {
if (!token) {
diff --git a/web-app/src/components/PatientListCard.jsx b/web-app/src/components/PatientListCard.jsx
index 21db7c3..ff188b7 100644
--- a/web-app/src/components/PatientListCard.jsx
+++ b/web-app/src/components/PatientListCard.jsx
@@ -1,17 +1,43 @@
-import { Card } from "antd";
+import {Card, Modal} from "antd";
import PropTypes from "prop-types";
+import {DeleteOutlined, EditOutlined} from "@ant-design/icons";
-const PatientListCard = ({ patient }) => {
+const PatientListCard = ({patient, handleEditPatient, handleDeletePatient}) => {
const birthday = new Date(patient.birthday)
+ const deletePatientConfirm = () => {
+ Modal.confirm({
+ title: "Удаление пациента",
+ content: `Вы уверены, что хотите удалить пациента ${patient.last_name} ${patient.first_name}?`,
+ okText: "Да, удалить",
+ cancelText: "Отмена",
+ onOk: () => handleDeletePatient(patient.id),
+ });
+ };
+
return (
📅 Дата рождения: {birthday.toLocaleString('ru-RU', {month: 'long', day: 'numeric', year: 'numeric'})} 📅 Дата рождения: {birthday.toLocaleString('ru-RU', {
+ month: 'long',
+ day: 'numeric',
+ year: 'numeric'
+ })} 📞 Телефон: {patient.phone} ✉️ Email: {patient.email}