Добавление заметок к устройствам. Возможность добавить, удалить, изменить заметку. Синхронизируется с нынешней и старой картой

This commit is contained in:
parent 82a91c0e88
commit 090cbcd477
3 changed files with 92 additions and 25 deletions

View file

@ -1,5 +1,6 @@
from fastapi import APIRouter, HTTPException
from typing import List
from pydantic import BaseModel
from models.subnet import SubnetScanResult
from models.wifi import WifiScanResult
from services.subnet_service import SubnetService
@ -7,6 +8,9 @@ from services.wifi_service import WifiService
router = APIRouter()
class NoteRequest(BaseModel):
note: str
@router.get("/scan", response_model=SubnetScanResult)
def scan_subnet(subnet: str = "192.168.1.0/24", ports: List[int] = None):
"""Сканирует локальную подсеть и возвращает данные об устройствах"""
@ -25,4 +29,37 @@ def scan_wifi(timeout: int = 30):
result = wifi_service.scan_wifi(timeout=timeout)
return result
except Exception as e:
raise HTTPException(status_code=500, detail=f"Ошибка сканирования Wi-Fi: {str(e)}")
raise HTTPException(status_code=500, detail=f"Ошибка сканирования Wi-Fi: {str(e)}")
@router.post("/devices/{mac}/note")
def add_note(mac: str, request: NoteRequest):
"""Добавляет заметку для устройства по MAC-адресу"""
try:
subnet_service = SubnetService()
if not subnet_service.add_note(mac, request.note):
raise HTTPException(status_code=404, detail=f"Устройство с MAC {mac} не найдено")
return {"message": f"Заметка '{request.note}' добавлена для устройства {mac}"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"Ошибка добавления заметки: {str(e)}")
@router.put("/devices/{mac}/note")
def update_note(mac: str, request: NoteRequest):
"""Обновляет заметку для устройства по MAC-адресу"""
try:
subnet_service = SubnetService()
if not subnet_service.update_note(mac, request.note):
raise HTTPException(status_code=404, detail=f"Устройство с MAC {mac} не найдено")
return {"message": f"Заметка '{request.note}' обновлена для устройства {mac}"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"Ошибка обновления заметки: {str(e)}")
@router.delete("/devices/{mac}/note")
def delete_note(mac: str):
"""Удаляет заметку для устройства по MAC-адресу"""
try:
subnet_service = SubnetService()
if not subnet_service.delete_note(mac):
raise HTTPException(status_code=404, detail=f"Устройство с MAC {mac} не найдено")
return {"message": f"Заметка удалена для устройства {mac}"}
except Exception as e:
raise HTTPException(status_code=500, detail=f"Ошибка удаления заметки: {str(e)}")